Option Explicit
Private Declare Function InitCommonControls Lib "Comctl32.dll" () As Long
' การสร้าง TabToolBar
Public WithEvents TabToolBar As XtremeCommandBars.TabToolBar
' หรือ แบบไม่ต้องเอามาเต็มยศฐาบรรดาศักดิ์ ... 55555+
'Public WithEvents TabToolBar As TabToolBar
' การสร้าง StatusBar
Dim WithEvents StatusBar As XtremeCommandBars.StatusBar
' ###############################################
' เหตุการณ์ในการคลิ๊กเลือก ToolBar หรือ MenuBar เพื่อสั่งให้ไปทำงานอย่างอื่น
' ###############################################
Private Sub CommandBars_Execute(ByVal Control As XtremeCommandBars.ICommandBarControl)
On Error Resume Next
Select Case Control.Id
' กลุ่มนี้ คือ TabToolBar ค่าคงที่ถูกกำหนดไว้ในไฟล์ modDefinitions.bas
Case ID_USER_TOOLS_1:
MsgBox "คุณเลือกรายการ ToolBar ตัวที่ 1"
Case ID_USER_TOOLS_2:
MsgBox "คุณเลือกรายการ ToolBar ตัวที่ 2"
Case ID_USER_TOOLS_3:
MsgBox "คุณเลือกรายการ ToolBar ตัวที่ 3"
Case ID_USER_TOOLS_4:
MsgBox "คุณเลือกรายการ ToolBar ตัวที่ 4"
Case ID_USER_TOOLS_5:
MsgBox "คุณเลือกรายการ ToolBar ตัวที่ 5"
End
' กรณีของ MenuBar ก็เช่นเดียวกัน เรานำค่าคงที่จาก Resource.bas มาใช้งานได้เลย
Case ID_FILE_MENU1:
MsgBox "คุณเลือกรายการ MenuBar ตัวที่ 1"
Case ID_FILE_MENU2:
MsgBox "คุณเลือกรายการ MenuBar ตัวที่ 2"
Case ID_PROGRAM_MENU3:
MsgBox "คุณเลือกรายการ MenuBar ตัวที่ 3"
End Select
End Sub
Private Sub MDIForm_Activate()
frmMain.Caption = "ตัวอย่างการทำ ToolBar ด้วย Xtreame SuitePro ActiveX - www.g2gnet.com"
StatusBar(0).Text = "ผู้พัฒนาโปรแกรม : นายสุรพล ยอดสง่า [email protected] [www.g2gnet.com]"
End Sub
Private Sub MDIForm_Initialize()
InitCommonControls
End Sub
Private Sub MDIForm_Load()
' หากเปิดโปรแกรมนี้ซ้ำกัน จะไม่ให้ตัวใหม่ขึ้นมาทำงาน
If App.PrevInstance Then End
' การตั้งค่าคุณสมบัติ เพื่อใช้ประโยชน์ในส่วนของพารามิเตอร์ภายในของ App
' เช่น App.Title, App.Path โดยใช้งานผ่าน CommandBars Control
CommandBarsGlobalSettings.App = App
' CommandBarsGlobalSettings มี Properties ให้ใช้งานได้หลากหลายมากครับ เช่น ทำโปรแกรมหลายภาษา
' ตัวอย่าง ... CommandBarsGlobalSettings.ResourceFile = "XTPResourceArSa.dll"
' ตัวแปร Control ในการสร้างกลุ่มของ ToolBar
Dim Control As CommandBarControl
Me.Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
' โหลดตัว Designer เข้าสู่ CommandBars ... ก็การสร้างเมนูนั่นแหละครับ
CommandBars.LoadDesignerBars
' ไม่ต้องการให้เมนูเคลื่อนที่ได้ (Stretched)
CommandBars.ActiveMenuBar.EnableDocking xtpFlagStretched
CommandBars.Options.KeyboardCuesShow = xtpKeyboardCuesShowWindowsDefault
CommandBars.EnableCustomization False
' แสดง Theme ... เลือกเอามาใช้เลยครับ
'SkinFramework.LoadSkin App.Path + "\Styles\Office2007.cjstyles", "NORMALBLUE.ini"
'SkinFramework.LoadSkin App.Path + "\Styles\Vista.cjstyles", "NORMALBLUE.INI"
'SkinFramework.LoadSkin App.Path + "\Styles\Vista.cjstyles", "NORMALBLACK.INI"
'SkinFramework.LoadSkin App.Path + "\Styles\Vista.cjstyles", "NORMALSILVER.INI"
SkinFramework.LoadSkin App.Path + "\Styles\Office2007.cjstyles", "NORMALBLUE.ini"
SkinFramework.ApplyWindow (Me.hWnd)
SkinFramework.ApplyOptions = SkinFramework.ApplyOptions Or xtpSkinApplyMetrics
CommandBars.PaintManager.RefreshMetrics
CommandBars.RecalcLayout
' เพิ่มรายการ ToolBar
Set TabToolBar = CommandBars.AddTabToolBar("UserTools")
' ไม่อนุญาตให้เพิ่ม/ลบ (Add or Remove Buttons) ที่มันจะอยู่ทางด้านขวามือสุดของ ToolBar
TabToolBar.ShowExpandButton = False
' กำหนดความกว้างขั้นต่ำสุดของ ToolBar แต่ละตัว (หน่วยวัด Pixels)
TabToolBar.MinimumWidth = 400
' เริ่มต้นการเพิ่มปุ่ม Control เข้ามายัง ToolBar
With TabToolBar
Dim iCount As Integer
' สร้างรายการ ToolBar ขึ้นมา โดยใช้ชื่อกลุ่ม "User Tools" มีทั้งหมด 5 ตัว
' ค่าคงที่ ID_USER_TOOLS แต่ละตัว เราไปกำหนดล่วงหน้าเอาเองที่ modDefinitions.bas
For iCount = ID_USER_TOOLS_1 To ID_USER_TOOLS_5
Select Case iCount
Case 801: Set Control = .Control.Add(xtpControlButton, iCount, "รายการตัวที่ 1")
Case 802: Set Control = .Control.Add(xtpControlButton, iCount, "รายการตัวที่ 2")
Case 803: Set Control = .Control.Add(xtpControlButton, iCount, "รายการตัวที่ 3")
Case 804: Set Control = .Control.Add(xtpControlButton, iCount, "รายการตัวที่ 4")
Case 805: Set Control = .Control.Add(xtpControlButton, iCount, "รายการตัวที่ 5")
End Select
Next
End With
' ประกาศตัวแปร Array ตามจำนวน ToolBar ที่ต้องการสร้างขึ้นมา เพื่อแสดงรูป Icon
' ในตัวอย่างมี 5 ตัว โดยเริ่มต้นจาก 0 ถึง 4
Dim icoIconArray(0 To 4) As Long
icoIconArray(0) = ID_USER_TOOLS_1
icoIconArray(1) = ID_USER_TOOLS_2
icoIconArray(2) = ID_USER_TOOLS_3
icoIconArray(3) = ID_USER_TOOLS_4
icoIconArray(4) = ID_USER_TOOLS_5
' โหลดภาพ PNG เข้ามาให้กับ ImageManager
ImageManager.Icons.LoadBitmap App.Path & "\Icon\images.png", icoIconArray, xtpImageNormal
' ส่งให้กับ CommandBars อีกที เพื่อให้ ToolBar แสดงภาพ Icon ได้
CommandBars.Icons = ImageManager.Icons
' ตั้งค่าขนาด Icon ตามที่เราออกแบบเอาไว้ แต่ละตัวจะมีขนาด 32x32 Pixel
TabToolBar.SetIconSize 32, 32
TabToolBar.ShowTextBelowIcons = True
' ไม่ให้เกิดการเคลื่อนที่ของ ToolBar ได้
TabToolBar.EnableDocking xtpFlagStretched
TabToolBar.Closeable = False
TabToolBar.Customizable = False
' ======================= ToolTips ==========================
Dim ToolTipContext As ToolTipContext
Set ToolTipContext = CommandBars.ToolTipContext
ToolTipContext.Style = xtpToolTipOffice2007
ToolTipContext.ShowTitleAndDescription True, xtpToolTipIconNone
' ตั้งค่าตำแหน่งของ ToolTip
'ToolTipContext.SetMargin 2, 2, 2, 2
ToolTipContext.MaxTipWidth = 180
ToolTipContext.ShowShadow = True
' ======================= ToolTips ==========================
' การสร้าง StatusBar ที่อยู่ด้านล่างของฟอร์ม
Set StatusBar = CommandBars.StatusBar
StatusBar.Visible = True
StatusBar.AddPane 0
' ค่าคงที่ๆกำหนดไว้ใน modDefinitions.bas และเป็นค่าสงวนที่เปลี่ยนแปลงไม่ได้
StatusBar.AddPane ID_INDICATOR_CAPS
StatusBar.AddPane ID_INDICATOR_NUM
StatusBar.AddPane ID_INDICATOR_SCRL
StatusBar.IdleText = "ผู้พัฒนาโปรแกรม : นายสุรพล ยอดสง่า [email protected] [www.g2gnet.com]"
End Sub
|