ทำความรู้จักกับ HTML5 กับ TAG พื้นฐาน
HTML5 - ตอนที่ 1 - Introduction
HTML5 - ตอนที่ 2 - CSS3 กับการจัดรูปแบบหน้าเว็บ
HTML - ตอนที่ 3 - HTML tag กำหนดรูปแบบของบทความ
จ.ด.ท = จด ดู ทำ แล้วจะ จำ ได้ ท่าน

header {
color:blue;
background-color:yellow;
}
header {
visibility:hidden;
width:0px;
height:0px;
}
Private Sub Form1_InputLanguageChanged _
(ByVal sender As Object, ByVal e As _
System.Windows.Forms.InputLanguageChangedEventArgs) _
Handles Me.InputLanguageChanged
Label1.Text = InputLanguage.CurrentInputLanguage.Culture.DisplayName.ToString
End Sub
ที่ Procedure : Load
Private Sub Form1_Load _
(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Label1.Text = InputLanguage.CurrentInputLanguage.Culture.DisplayName.ToString
End Sub
วิธีที่ 2
อาศัยเรียกใช้จาก user32
ให้ทำการ Import คลาสเข้ามาใช้งาน
Imports System.Runtime.InteropServicesจากนั้นสร้าง Function ชื่อ GetKeyBoardLayoutName
ที่ Procedure : InputLanguageChange_ Private Shared Function GetKeyboardLayoutName _ (ByVal sb As System.Text.StringBuilder) As Integer 'ไม่ต้องใส่อะไร End Function
Private Sub Form1_InputLanguageChanged _
(ByVal sender As Object, ByVal e As _
System.Windows.Forms.InputLanguageChangedEventArgs) _
Handles Me.InputLanguageChanged
Dim sb As New System.Text.StringBuilder(" "c, 256)
Dim len As Integer
len = GetKeyboardLayoutName(sb)
Label1.Text = sb.ToString
End Sub
ที่ Procedure : Load
Private Sub Form1_Load _
(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim sb As New System.Text.StringBuilder(" "c, 256)
Dim len As Integer
len = GetKeyboardLayoutName(sb)
Label1.Text = sb.ToString
End Sub
สำหรับวิธีที่ 2 การแสดงผลจะเป็นรหัส เช่น
' ไทย -- 0000041E
' English -- 00000409
หวังว่าคงเป็นประโยชน์....
สวัสดี คนไทยไม่ทิ้งกัน
Imports System.Data
Imports System.Data.SqlClient
Public Class frmInquiry
' ตัวแปรที่ใช้ใน Property [AssCode]
Dim rAssCode As String = " "
Private Sub frmInquiry_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
queryData()
'สลับสีของแถว
DataGridView1.RowsDefaultCellStyle.BackColor = Color.White
DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Azure
With DataGridView1
.DefaultCellStyle.NullValue = ""
.Columns(0).HeaderText = "รหัสสินทรัพย์"
.Columns(0).Width = 100
.Columns(1).HeaderText = "รายการ"
.Columns(1).Width = 200
.Columns(2).HeaderText = "หน่วยนับ"
.Columns(2).Width = 80
End With
End Sub
Private Sub txtSearch_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles txtSearch.TextChanged
queryData()
End Sub
Private Sub DataGridView1_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentDoubleClick
Dim row As Integer = DataGridView1.CurrentCellAddress.Y
AssCode = DataGridView1.Rows(row).Cells(0).Value 'Cell(0) คือ คอลัมแรกของกริดนับจากซ้ายมือ
Me.Close()
End Sub
Sub queryData()
'ให้ทำการแก้ไข Connection String ตามที่เราใช้งานอยู่
Dim connString As String = "Data Source=.;Initial Catalog=ชื่อฐานข้อมูล;Persist Security Info=True;User ID=sa;Password=รหัสผ่าน"
Dim myConn As SqlConnection = New SqlConnection
myConn.ConnectionString = connString
'ให้แก้ไขคำสั่ง SQL ตามที่ต้องการ
Dim da As SqlDataAdapter = New SqlDataAdapter _
("SELECT TOP 50 ASSCODE, NAME, UMCODE FROM ABASSET WHERE ASSCODE+NAME LIKE '%" & txtSearch.Text.Trim & "%' ORDER BY ASSCODE", myConn)
Dim ds As DataSet = New DataSet
da.Fill(ds, "ABASSET")
myConn.Close()
DataGridView1.DataSource = ds.Tables(0)
End Sub
'' หากมีการส่งคืนหลายค่า ก็สร้าง Property เพิ่ม
Public Property [AssCode]() As String
Get
Return Me.rAssCode
End Get
Set(ByVal value As String)
Me.rAssCode = value
End Set
End Property
End Class
ต่อมาเราจะมาทำฟอร์มหลัก สำหรับเรียกฟอร์มค้นหาPublic Class Form1
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim fm As New frmInquiry()
fm.ShowDialog()
If fm.AssCode.ToString <> "" Then
txtAssCode.Text = fm.AssCode.ToString 'อ้างถึง property ชื่อ [AssCode] ของฟอร์ม frmInquiry
End If
fm.Dispose()
txtAssCode.Focus()
End Sub
End Class
ทำการเรียกฟอร์มขึ้นมาทำงาน โดยกดปุ่ม F5 เพื่อรันโปรเจกต์Imports System.IO
Imports System.Net
Imports System.Web
Imports System.Collections.Generic
Imports System.ComponentModel
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim ll As New LatLon()
ll = GetLatLon(txtAddress.Text)
txtLatLon.Text = ll.Latitude.ToString() & ", " & ll.Longitude.ToString()
Catch ex As Exception
MessageBox.Show(ex.Message, "An error has occurred")
End Try
End Sub
Public Function GetLatLon(ByVal addr As String) As LatLon
Dim url As String = "http://maps.google.com/maps/geo?output=csv&" & _
"key=[YOUR KEYGOES HERE]&q=" & addr
Dim request As System.Net.WebRequest = WebRequest.Create(url)
Dim response As HttpWebResponse = request.GetResponse()
If response.StatusCode = HttpStatusCode.OK Then
Dim ms As New System.IO.MemoryStream()
Dim responseStream As System.IO.Stream = response.GetResponseStream()
Dim buffer(2048) As Byte
Dim count As Integer = responseStream.Read(buffer, 0, buffer.Length)
While count > 0
ms.Write(buffer, 0, count)
count = responseStream.Read(buffer, 0, buffer.Length)
End While
responseStream.Close()
ms.Close()
Dim responseBytes() As Byte = ms.ToArray()
Dim encoding As New System.Text.ASCIIEncoding()
Dim coords As String = encoding.GetString(responseBytes)
Dim parts() As String = coords.Split(",")
Return New LatLon(Convert.ToDouble(parts(2)), Convert.ToDouble(parts(3)))
End If
Return Nothing
End Function
End Class
3. ไปที่เมนู Project เลือกรายการ Add Class...Public Class LatLon
Public Property Latitude As Double
Public Property Longitude As Double
Public Sub New()
End Sub
Public Sub New(ByVal lat As Double, ByVal lon As Double)
Me.Latitude = lat
Me.Longitude = lon
End Sub
End Class
หลังจากนั้นให้กดปุ่ม F5 เพื่อทำการทดสอบโปรแกรม จะปรากฏหน้าต่างให้เราป้อนที่อยู่ที่ต้องการ ดังภาพ

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim fm2 As Form2 = New Form2
fm2.ValueToPassBetweenForms1 = Me.TextBox1.Text
fm2.ShowDialog()
End Sub
End Class
3. ให้สร้างฟอร์มขึ้นมาอีกหนึ่งฟอร์มเป็นฟอร์มสำหรับรับค่า แล้วกำหนด คอนโทรลดังภาพ
Public Class Form2
Inherits Form
Public Sub New()
MyBase.New()
InitializeComponent()
AddHandler Load, AddressOf Me.Form2PassValue_Load
End Sub
Private Sub Form2PassValue_Load(ByVal sender As Object, _
ByVal e As EventArgs)
Me.Label1.Text = Me._valueToPassBetweenForms1
End Sub
Private _valueToPassBetweenForms1 As String
Public Property ValueToPassBetweenForms1() As String
Get
Return Me._valueToPassBetweenForms1
End Get
Set(ByVal value As String)
Me._valueToPassBetweenForms1 = value
End Set
End Property
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Me.Dispose()
End Sub
End Class
Imports System.Text
Public Class Form1
Private Sub btnSearch_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnSearch.Click
Try
Dim latitude As String = ""
Dim longitude As String = ""
Dim AddrToSearch As New StringBuilder()
AddrToSearch.Append("http://maps.google.com/maps?output=embed&hl=th&q=")
' if there is latitude
If txtLatitude.Text <> "" Then
latitude = txtLatitude.Text
AddrToSearch.Append(latitude & "%2C")
End If
' if there is longitude
If txtLongitude.Text <> "" Then
longitude = txtLongitude.Text
AddrToSearch.Append(longitude)
End If
' pass the AddrToSearch value to web browser control
WebBrowser1.Navigate(AddrToSearch.ToString())
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), _
"Problem encountered while retrieving google map")
End Try
End Sub
End Class
Imports System.Data Imports System.Data.SqlClient Imports System.IO
Public Class Form1
Dim bm As Bitmap
Dim fs As FileStream
Dim fsImage As Byte()
...
With OpenFileDialog1
.CheckFileExists = True
.ShowReadOnly = False
.Filter = "All Files|*.*|Picture Files|*.bmp;*.gif;*.jpg;*.png"
.FilterIndex = 2
If .ShowDialog = DialogResult.OK Then
fs = New FileStream(.FileName.ToString(), FileMode.Open)
fsImage = New Byte(fs.Length) {}
fs.Read(fsImage, 0, fs.Length)
fs.Close()
bm = Image.FromFile(.FileName.ToString())
PictureBox1.Image = bm
Label1.Text = System.IO.Path.GetFileName(.FileName)
End If
End With
If System.IO.File.Exists(Me.OpenFileDialog1.FileName) = False Then
MessageBox.Show("File Not Found", "Error")
Exit Sub
Else
Dim strConn As String = "Data Source=.;Initial Catalog=myData;" & _
"Integrated Security=SSPI;"
'strConn ให้เปลี่ยนค่าตามเครื่อง Server ของ SQL Server ที่ติดต่อ
Dim Conn As New SqlConnection(strConn)
Dim SqlString As String
SqlString = "INSERT INTO tblImage(ImageName,Image) " & _
" VALUES(@ImgName, @Img)"
Dim cmd As SqlCommand = New SqlCommand(SqlString, Conn)
Dim ImgName As SqlParameter = New SqlParameter("@ImgName", _
System.Data.SqlDbType.VarChar, 100)
ImgName.Value = Label1.Text.ToString()
cmd.Parameters.Add(ImgName)
Dim Img As SqlParameter = New SqlParameter("@Img", _
System.Data.SqlDbType.Image)
Img.Value = fsImage
cmd.Parameters.Add(Img)
Try
Conn.Open()
cmd.ExecuteNonQuery()
Conn.Close()
MessageBox.Show("Save Image Complete", "Success")
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Error")
Exit Sub
End Try
End If
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Public Class Form2
'strConn ให้เปลี่ยนค่าตามเครื่อง Server ของ SQL Server ที่ติดต่อ
Private strConn As String = "Data Source=.;Initial Catalog=myData;" & _
"Integrated Security=SSPI;"
Private SqlString As String
Private Conn As SqlConnection
Private cmd As SqlCommand
Private da As SqlDataAdapter
Private ds As DataSet
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
SqlString = "SELECT roworder,imagename FROM tblImage"
Conn = New SqlConnection(strConn)
Conn.Open()
cmd = New SqlCommand(SqlString, Conn)
da = New SqlDataAdapter(cmd)
ds = New DataSet()
da.Fill(ds, "tblImage")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "tblImage"
DataGridView1.ReadOnly = True
DataGridView1.Columns(0).HeaderText = "Run No."
DataGridView1.Columns(1).HeaderText = "Picture Name"
'format GridView
DataGridView1.GridColor = Color.Red
DataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None
DataGridView1.BackgroundColor = Color.LightGray
DataGridView1.DefaultCellStyle.SelectionBackColor = Color.Red
DataGridView1.DefaultCellStyle.SelectionForeColor = Color.Yellow
DataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.[True]
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
DataGridView1.AllowUserToResizeColumns = False
DataGridView1.RowsDefaultCellStyle.BackColor = Color.Bisque
DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige
'
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Error")
Finally
If Conn.State = ConnectionState.Open Then
Conn.Close()
End If
End Try
End Sub
Private Sub DataGridView1_SelectionChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles DataGridView1.SelectionChanged
Try
SqlString = "select image from tblImage where roworder = @roworder"
Conn = New SqlConnection(strConn)
cmd = New SqlCommand(SqlString, Conn)
Dim rdr As SqlDataReader = Nothing
Dim imgData As Byte() = Nothing
Dim row As Integer = DataGridView1.CurrentCellAddress.Y
Dim roworder As String = DataGridView1.Rows(row).Cells(0).Value
cmd.Parameters.AddWithValue("@roworder", roworder)
Conn.Open()
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If rdr.Read() Then
imgData = New Byte(rdr.GetBytes(0, 0, Nothing, 0, Integer.MaxValue) - 1) {}
rdr.GetBytes(0, 0, imgData, 0, imgData.Length)
Dim ms As New MemoryStream(imgData)
PictureBox1.Image = Image.FromStream(ms)
Else
MessageBox.Show("No records found in the database.", "Warning")
End If
Catch ex As Exception
PictureBox1.Image = Nothing
Finally
If Conn.State = ConnectionState.Open Then
Conn.Close()
End If
End Try
End Sub
End Class