thongkorn โพสต์ 2019-3-20 19:44:10

[VB.NET] การใช้งาน GroupBar ของฟรีใน Syncfusion Community

http://www.g2gnet.com/webboard/images/vbnet/groupbarsyncfusion.png


ย้ำอีกทีน่ะครับว่า Syncfusion Community เป็นของฟรีที่เต็มไปด้วย Control หรือ Component ที่น่าใช้งานอยู่มากมายหลายตัว และหนึ่งในนั้นก็คือ GroupBar ซึ่งนำมาใช้ประโยชน์ด้วยการจัดหมวดหมู่กลุ่ม Control อีกทีหนึ่งได้ค่อนข้างดีทีเดียว ... (Download Syncfusion Community Edition)

http://www.g2gnet.com/webboard/images/vbnet/syncfusionref.png
การเรียกใช้งาน Syncfusion โดยเลือก Reference ตัวหลัก 2 ตัวนี้ ...


http://www.g2gnet.com/webboard/images/vbnet/groupbardesign.png
หน้าจอการออกแบบ (Design Time)


มาดูโค้ดกันเถอะ ...
' / -------------------------------------------------------------------------------
' / Developer : Mr.Surapon Yodsanga (Thongkorn Tubtimkrob)
' / eMail : thongkorn@hotmail.com
' / URL: http://www.g2gnet.com (Khon Kaen - Thailand)
' / Facebook: https://www.facebook.com/g2gnet (For Thailand)
' / Facebook: https://www.facebook.com/commonindy (Worldwide)
' / More Info: http://www.g2gnet.com/webboard
' /
' / Purpose: Using GroupBar of Syncfusion Community.
' / Microsoft Visual Basic .NET (2010)
' /
' / This is open source code under @CopyLeft by Thongkorn Tubtimkrob.
' / You can modify and/or distribute without to inform the developer.
' / -------------------------------------------------------------------------------

Public Class frmGroupBar

    Private Sub frmGroupBar_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
      Me.CenterToScreen()
      '/ MessageBox.Show(AppPath);
      Dim MyPath As String = Application.StartupPath.ToLower
      MyPath = MyPath.Replace("\bin\debug", "\").Replace("\bin\release", "\").Replace("\bin\x86\debug", "\")
      '// If not found folder then put the \ (BackSlash) at the end.
      If Microsoft.VisualBasic.Right(MyPath, 1) <> Chr(92) Then MyPath = MyPath & Chr(92)
      Dim strPathImage As String = MyPath & "images\"
      '//
      Me.GroupBar1.ForeColor = Color.Black
      Me.GroupBar1.Font = New Font("Tahoma", 10, FontStyle.Bold)
      '// Acquire the DataTable instance.
      Dim table As DataTable = GetTable()
      Dim row As DataRow
      Dim img As String
      '/ Load data @RunTime
      Dim Rec As Integer = 0
      Dim myButtons = { _
            btnBurger1, btnBurger2, btnBurger3, btnBurger4, btnBurger5, btnBurger6, btnBurger7, _
            btnSmall1, btnSmall2, btnSmall3, btnMedium1, btnMedium2, btnMedium3, btnLarge1, btnLarge2, btnLarge3 _
            }
      For Each btn In myButtons
            row = table.Rows(Rec)
            With btn
                '// ใช้คุณสมบัติ Tag เก็บค่า Primary Key
                .Tag = row("PK")
                '// ใช้คุณสมบัติ Text เก็บค่า Description
                .Text = row("Description")
                img = strPathImage & row("Picture")
                .BackgroundImage = New System.Drawing.Bitmap(img)
            End With
            '// Force events handler.
            AddHandler btn.Click, AddressOf ClickButton
            Rec += 1
      Next
    End Sub

    '// Click Button event, get the text of button
    Public Sub ClickButton(ByVal sender As Object, ByVal e As System.EventArgs)
      Dim btn As Button = sender
      '// หากนำไปใช้งานจริง ข้อมูลของตัวสินค้าจะถูกเรียกมาจากตารางข้อมูล
      '// Acquire the DataTable instance.
      Dim table As DataTable = GetTable()
      'Search DataTable by string DataType
      Dim oRow() As DataRow = table.Select("PK = " & btn.Tag)
      MessageBox.Show("You choose: " & btn.Text & vbCrLf & "Price: " & CDbl(oRow(0)("PriceCash")) & " Baht.")
    End Sub

    '// จำลองเป็นตารางข้อมูล (Table)
    Function GetTable() As DataTable
      ' Generate a new DataTable.
      ' ... Add columns.
      Dim table As DataTable = New DataTable
      table.Columns.Add("PK", GetType(Integer))
      table.Columns.Add("Description", GetType(String))
      table.Columns.Add("PriceCash", GetType(Double))
      table.Columns.Add("Quantity", GetType(Integer))
      table.Columns.Add("Picture", GetType(String))
      ' ... Add rows.
      table.Rows.Add(1, "Classic Checken", "50.00", "1", "BurgerChicken.png")
      table.Rows.Add(2, "Mexicana", "100.00", "1", "BurgerMexicana.png")
      table.Rows.Add(3, "Lemon Shrimp", "150.00", "1", "BurgerLemonShrimp.png")
      table.Rows.Add(4, "Bacon", "200.00", "1", "BurgerBacon.png")
      table.Rows.Add(5, "Spicy Shrimp", "250.00", "1", "BurgerSpicyShrimp.png")
      table.Rows.Add(6, "Tex Supreme", "300.00", "1", "BurgerTexSupreme.png")
      table.Rows.Add(7, "Fish", "350.00", "1", "BurgerFish.png")
      '//
      table.Rows.Add(101, "Pepsi Small", "10.00", "1", "PepsiCan.png")
      table.Rows.Add(102, "Coke Small", "15.00", "1", "CocaColaCan.png")
      table.Rows.Add(103, "7Up Small", "20.00", "1", "7UpCan.png")
      table.Rows.Add(104, "Pepsi Medium", "25.00", "1", "PepsiCan.png")
      table.Rows.Add(105, "Coke Medium", "30.00", "1", "CocaColaCan.png")
      table.Rows.Add(106, "7Up Medium", "45.00", "1", "7UpCan.png")
      table.Rows.Add(107, "Pepsi Large", "50.00", "1", "PepsiCan.png")
      table.Rows.Add(108, "Coke Large", "55.00", "1", "CocaColaCan.png")
      table.Rows.Add(109, "7Up Large", "60.00", "1", "7UpCan.png")
      Return table
    End Function

End Class

ดาวน์โหลดโค้ดต้นฉบับเต็ม VB.NET (2010) ได้ที่นี่ ...



wut262 โพสต์ 2019-3-21 20:52:12

ขอบคุณครับ
หน้า: [1]
ดูในรูปแบบกติ: [VB.NET] การใช้งาน GroupBar ของฟรีใน Syncfusion Community