'build myTabGroup
Private Sub BuildTabGroup(ByVal IdCategory As String, ByVal strTextOne As String, ByVal strTextTwo As String, ByVal strTextThree As String)
'build tabcontrol
Me.flowlayoutpanelContent.Controls.Clear()
myTabControl = New TabControl()
myTabControl.ItemSize = New Size(300, 40)
myTabControl.Size = New Size(534, 729)
flowlayoutpanelContent.Controls.Add(myTabControl)
'build tabpage
'mytabone
If strTextOne.ToString <> "" Then
myTabPage = New TabPage()
myTabPage.Text = strTextOne
myTabControl.TabPages.Add(myTabPage)
End If
'mytabtwo
If strTextTwo.ToString <> "" Then
myTabPage = New TabPage()
myTabPage.Text = strTextTwo
myTabControl.TabPages.Add(myTabPage)
End If
'mytabthree
If strTextThree.ToString <> "" Then
myTabPage = New TabPage()
myTabPage.Text = strTextThree
myTabControl.TabPages.Add(myTabPage)
End If
End Sub
'sub even show button product product
Private Sub ClickHandlerPageProduct(ByVal getGroupId As String)
'Button To add TextBoxes
Dim sqlProduct As String
Dim productButton As Button
Dim i As Integer
Try
'query product build control button from id group
sb = New StringBuilder
sb.Append("SELECT id,code,name_thai,name_eng,sell_price,images FROM product")
sb.Append(" WHERE group_id=@group_id") ' AND glass=@glass
sb.Append(" ORDER BY code ASC")
sqlProduct = sb.ToString
cmd = New SqlCommand
With cmd
.Parameters.Clear()
.Parameters.Add("@group_id", SqlDbType.Int).Value = getGroupId.ToString
' .Parameters.Add("@glass", SqlDbType.SmallInt).Value = getGlass.ToString
.Connection = conn
.CommandText = sqlProduct
dr = .ExecuteReader
If dr.HasRows Then
dt = New DataTable
dt.Load(dr)
'myTabControl.TabPages(0).Controls.Clear()
For i = 0 To dt.Rows.Count - 1
productButton = New Button
productButton.ForeColor = Color.Red
productButton.TextAlign = ContentAlignment.BottomCenter
productButton.BackgroundImageLayout = ImageLayout.Stretch
productButton.Cursor = Cursors.Hand
productButton.Width = 100
productButton.Height = 100
'set id product
productButton.TabIndex = dt.Rows(i).Item("id").ToString
productButton.Name = dt.Rows(i).Item("code").ToString
productButton.Text = dt.Rows(i).Item("name_thai").ToString
productButton.AccessibleName = dt.Rows(i).Item("name_eng").ToString
productButton.Tag = dt.Rows(i).Item("sell_price").ToString
'check image null default
'If IsDBNull(dt.Rows(i).Item("images")) Then
' productButton.BackgroundImage = defaultImage
'Else
' productButton.BackgroundImage = BytesToImages(dt.Rows(i).Item("images"))
'End If
'myTabControl.TabPages(0).Controls.Add(productButton)
AddHandler productButton.Click, AddressOf ClickAddToGridView
Next
End If
End With
dr.Close()
Catch ex As Exception
Console.WriteLine("ERROR Sub ClickHandlerPageProduct")
Exit Sub
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AddTab(Image.FromFile("D:\SWDownload\Wallpaper\01024418.jpg"), "ไอ้ก้อนหินเฮ็งซวย") 'การใช้งาน
End Sub
'ส่วนของการเพิ่ม TabPage
Private Sub AddTab(pathPic As String, Optional strTabString As String = "")
Dim tab As TabPage = New TabPage(strTabString)
Dim pic As PictureBox = New PictureBox
pic.Image = pathPic
pic.Dock = System.Windows.Forms.DockStyle.Fill 'ทำให้เต็มจอ
tab.Controls.Add(pic) 'เพิ่ม picture box ใน TabPage
Me.TabControl1.Controls.Add(tab) 'เพิ่ม TabPage ใน TabControl
End Sub
หลักการ add control แบบบ้านๆคือให้ดู ใน Private Sub InitializeComponent() คือ add control ไปก่อนแล้วไปดูใน Private Sub InitializeComponent() ว่ามัน add control ยังไงได้ผล 1000000000000000000000000000000 %