![]() |
Source Code |
![]() |
![]() |
2 | Common Controls Library |   |
Toolbars and Rebars: Quick Start 1 - Add a Rebar and a Toolbar to Your App |
How to get started with the vbAccelerator CoolMenu, Toolbar and Rebar Control. |   |
  |
With cToolbar1 .ImageSource = CTBStandardImageSources .ImageStandardBitmapType = CTBStandardSmallColor .CreateToolbar 16, , True End With The list of available in-built images are coded as an enumeration in the toolbar control. Check the ECTBStandardImageIndexConstants enumeration for a list of the available items. The AddButton method allows you to add or insert a toolbar button and takes the following arguments:
        .AddButton "New", CTBStdFileNew, , , "New", CTBDropDown,"New"         .AddButton "Open", CTBStdFileOpen, , , "Open", ,"Open"         .AddButton "Save", CTBStdFIleSave, , , "Save", ,"Save"         .AddButton "", -1, , , , CTBSeparator         .AddButton "Cut", CTBStdCut, , , "Cut", ,"Cut"         .AddButton "Copy", CTBStdCopy, , , "Copy", ,"Copy"         .AddButton "Paste", CTBStdPaste, , , "Paste", ,"Paste"         .AddButton "", -1, , , , CTBSeparator         .AddButton "CheckBox", CTBStdProperties, , , "Properties", CTBCheck,"Properties"         .AddButton "", -1, , , , CTBSeparator         .AddButton "Print", CTBStdPrint, , , "Print", ,"Print"         .AddButton "", -1, , , , CTBSeparator         .AddButton "Help", CTBStdHelp, , , "Help", ,"Help"         .AddButton "Find", CTBStdFind, , , "Find", ,"Find"     End With Here the rebar does not have a background bitmap. The rebar is created with the CreateRebar method, which takes the hWnd of the rebar's parent as an argument, and then the toolbar is added to it with the AddBandByhWnd method, which takes the following arguments:
        .CreateRebar Me.hWnd         .AddBandByHwnd cToolbar1.hWnd, , , , "Toolbar1"     End With Firstly, you should tell the Rebar to resize whenever the form changes size using the RebarSize method:     ' Make sure the rebar is the correct width:     cReBar1.RebarSize     ' Do your form resizing here:     ' Note that the Rebar's height can be obtained from the RebarHeight     ' property. This is in pixels, so multiply by Screen.TwipsPerPixelY.     ' ... End Sub The rebar can also change height when your form hasn't resized, for example, when a band is moved by the user. When this occurs, the Rebar raises a HeightChanged event. Respond to this and do all the Form_Resize code you would normally perform. Although the control should theoretically respond correctly during unload, the unload order is sometimes unpredictable in VB. By calling this method you ensure all controls are in the correct place and that the Rebar will terminate.     ' For safety, ensure that the Rebar doesn't have any     ' child windows before terminating. This shouldn't be     ' necessary:     cReBar1.RemoveAllRebarBands End Sub When a button is clicked, the toolbar will raise a ButtonClick event, passing the index of the button as a parameter. You can get the key of the button by querying the toolbar's ButtonKey property. If the drop-down portion of a button is clicked, the toolbar will raise a DropDownPress event, also passing the index of the button. To show a drop-down menu, call the toolbar's GetDropDownPosition method to determine the x and y position to show the menu, and use VB's PopupMenu event to show a menu there. And that's it! Now you are ready to continue to stage 2: Quick Start 2: Adding a CoolMenu to your Application.
|
  |
![]() |
|
About Contribute Send Feedback Privacy
|