Instead of a classic button, you can create a type of menu on a toolbar so that, when the user clicks the button, a menu would come up. To get it:
The button that is equipped with a menu is available through a class named ToolStripDropDownButton. This class inherits from a class named ToolStripDropDownItem. The ToolStripDropDownButton class has seven constructors. To programmatically create a drop down button, you can declare a variable of type ToolStripDropDownButton using its default constructor, allocate memory for it using the new operator, and add it to the Items collection of the ToolStrip variable. Here is an example: Imports System.Drawing Imports System.Windows.Forms Public Class Exercise Inherits System.Windows.Forms.Form Dim tbrStandard As ToolStrip Dim ddRecentlyUsed As ToolStripDropDownButton Public Sub New() tbrStandard = New ToolStrip ddRecentlyUsed = New ToolStripDropDownButton tbrStandard.Items.Add(ddRecentlyUsed) Controls.Add(tbrStandard) End Sub <STAThread()> Public Shared Function Main() As Integer Application.Run(New Exercise) Return 0 End Function End Class The primary characteristic of a drop down button is that it is equipped with a menu. To visually create the menu, after adding the button, it displays a text box labeled Type Here. Alternatively, click the drop down button on the toolbar. In the Properties window, click DropDownItems, then click its browse button to open the Items Collection Editor. You programmatically create the menu items of a drop down button like those of regular menu items. After creating them, add them to the DropDownItems collection of the drop down button. Here is an example: Imports System.Drawing Imports System.Windows.Forms Public Class Exercise Inherits System.Windows.Forms.Form Dim tbrStandard As ToolStrip Dim ddRecentlyUsed As ToolStripDropDownButton Dim ddiFirst As ToolStripMenuItem Dim ddiSecond As ToolStripMenuItem Dim ddiThird As ToolStripMenuItem Dim ddiFourth As ToolStripMenuItem Public Sub New() tbrStandard = New ToolStrip ddRecentlyUsed = New ToolStripDropDownButton ddRecentlyUsed.Image = Image.FromFile("C:\Exercise\recent.ico") ddRecentlyUsed.DisplayStyle = ToolStripItemDisplayStyle.Image tbrStandard.Items.Add(ddRecentlyUsed) ddiFirst = New ToolStripMenuItem("First") ddiSecond = New ToolStripMenuItem("Second") ddiThird = New ToolStripMenuItem("Third") ddiFourth = New ToolStripMenuItem("Fourth") ddRecentlyUsed.DropDownItems.Add(ddiFirst) ddRecentlyUsed.DropDownItems.Add(ddiSecond) ddRecentlyUsed.DropDownItems.Add(ddiThird) ddRecentlyUsed.DropDownItems.Add(ddiFourth) Controls.Add(tbrStandard) End Sub <STAThread()> Public Shared Function Main() As Integer Application.Run(New Exercise) Return 0 End Function End Class This would produce:
The menu items of a drop down button behave like the menu items we saw in Lessons 10-12. Based on this, you can configure the items of the button the same way we reviewed for menu items.
A separator is a vertical bar that is used to create sections or groups of items on a toolbar. There is no strict rule as to where to put a separator. Only your experience and needs will guide you. To create a separator:
When the user clicks a drop down button, its menu automatically displays. As an alternative, you can create a button split by a bar, showing a normal button on the left and a menu on the right. To support this, the .NET Framework provides the ToolStripSplitButton class. This class is represented by a control named split button. To visually add a split button to a toolbar, do one of the following:
To programmatically create a split button, declare a variable of type ToolStripSplitButton and add it to the Items property of the toolbar. Here is an example: Imports System.Drawing Imports System.Windows.Forms Public Class Exercise Inherits System.Windows.Forms.Form Dim tbrStandard As ToolStrip Dim btnTypesOfApplications As ToolStripSplitButton Public Sub New() tbrStandard = New ToolStrip btnTypesOfApplications = New ToolStripSplitButton tbrStandard.Items.Add(btnTypesOfApplications) Controls.Add(tbrStandard) End Sub <STAThread()> Public Shared Function Main() As Integer Application.Run(New Exercise) Return 0 End Function End Class
There are two ways a user can use a split button, by clicking the button itself on the left or the arrow on the right. When the arrow button is clicked, a menu displays. The menu items that display are of type ToolStripItem. This means that you create them using the same descriptions we saw for menus. Imports System.Drawing
Imports System.Windows.Forms
Public Class Exercise
Inherits System.Windows.Forms.Form
Dim tbrStandard As ToolStrip
Dim btnTypesOfApplications As ToolStripSplitButton
Public Sub New()
tbrStandard = New ToolStrip
btnTypesOfApplications = New ToolStripSplitButton
btnTypesOfApplications.Image = Image.FromFile("K:\Art Gallery 1.0\alarm2.ico")
btnTypesOfApplications.DisplayStyle = ToolStripItemDisplayStyle.Image
btnTypesOfApplications.DropDownItems.Add(New ToolStripMenuItem("Work Processing"))
btnTypesOfApplications.DropDownItems.Add(New ToolStripMenuItem("Spreadsheet"))
btnTypesOfApplications.DropDownItems.Add(New ToolStripMenuItem("Databases"))
btnTypesOfApplications.DropDownItems.Add(New ToolStripMenuItem("Presentation"))
tbrStandard.Items.Add(btnTypesOfApplications)
Controls.Add(tbrStandard)
End Sub
<STAThread()>
Public Shared Function Main() As Integer
Application.Run(New Exercise)
Return 0
End Function
End Class
You can create a section on a toolbar to display text. To support this, the .NET Framework provides the ToolStripLabel class, which is derived from the ToolStripItem class. To visually create a label:
As its name indicates, a label is meant to display text. After adding it to a toolbar, assign a string to its Text property. Instead of simple text, you can make a label behave like a link. To support this, the ToolStripLabel class is equipped with a Boolean property named IsLink. If you set this property to true, the label would follow the standard description of a web link (without the link itself; you must find a way to make it active the desired link).
You can add a text box to a toolbar so the user can type something in it or read text from it. To make this possible, you can use a class named ToolStripTextBox. To add a text box to a toolbar:
To programmatically add a textbox to a toolbar, declare a variable of type ToolStripTextBox. The ToolStripTextBox class is equipped with 3 constructors. The default constructor is used to create a normal and simple text box. After declaring and initializing the variable, add it to the Items property of the toolstrip. Here is an example: Imports System.Drawing Imports System.Windows.Forms Public Class Exercise Inherits System.Windows.Forms.Form Dim tbrStandard As ToolStrip Dim txtFullName As ToolStripTextBox Public Sub New() tbrStandard = New ToolStrip txtFullName = New ToolStripTextBox tbrStandard.Items.Add(txtFullName) Controls.Add(tbrStandard) End Sub <STAThread()> Public Shared Function Main() As Integer Application.Run(New Exercise) Return 0 End Function End Class This would produce:
Most of the time, you create an empty text box in which a user can enter text. At any time, if you want to display text in the text box, assign a string to the Text property of the button. This can be done as follows: Imports System.Drawing
Imports System.Windows.Forms
Public Class Exercise
Inherits System.Windows.Forms.Form
Dim tbrStandard As ToolStrip
Dim txtFullName As ToolStripTextBox
Public Sub New()
tbrStandard = New ToolStrip
txtFullName = New ToolStripTextBox
txtFullName.Text = "John Doe"
tbrStandard.Items.Add(txtFullName)
Controls.Add(tbrStandard)
End Sub
<STAThread()>
Public Shared Function Main() As Integer
Application.Run(New Exercise)
Return 0
End Function
End Class
The text box of a toolbar uses the normal features of a Microsoft Windows text box.
You can add a combo box to a toolbar to provide a list from which the user can select an item. The combo box is handled by the ToolStripComboBox class. To visually add a combo box to a toolbar, perform one of the following actions:
To programmatically create a combo box, declare a variable of type ToolStripComboBox. The ToolStripComboBox class has 3 constructors. Use the default constructor to create a combo box. Initialize the variable and add it to the Items property of the toolbar. Here is an example: Imports System.Drawing Imports System.Windows.Forms Public Class Exercise Inherits System.Windows.Forms.Form Dim tbrStandard As ToolStrip Dim cbxCategories As ToolStripComboBox Public Sub New() tbrStandard = New ToolStrip cbxCategories = New ToolStripComboBox tbrStandard.Items.Add(cbxCategories) Controls.Add(tbrStandard) End Sub <STAThread()> Public Shared Function Main() As Integer Application.Run(New Exercise) Return 0 End Function End Class This would produce:
One of the properties of the combo box of a toolbar is named ComboBox. This property is of type ComboBox. This property can be assigned a predefined object that has all the desired and necessary characteristics of a Microsoft Windows combo box.
A progress bar is used to show the evolution of something by drawing continuous rectangles, usually blue. To support them on a toolbar, the .NET Framework provides the ToolStripProgressBar class. This class inherits from the ToolStripControlHost class. To visuall add a progress bar on a toolbar:
To programmatically create a progress bar to be hosted by a toolbar, declare a variable of type ToolStripProgressBar. The ToolStripProgressBar class has two constructors. You can use the default constructor to declare the variable, initialize it using the new operator, and add it to the Items property of a ToolStrip variable. Here is an example: Imports System.Drawing Imports System.Windows.Forms Public Class Exercise Inherits System.Windows.Forms.Form Dim tbrStandard As ToolStrip Dim pgrEvolution As ToolStripProgressBar Public Sub New() tbrStandard = New ToolStrip pgrEvolution = New ToolStripProgressBar tbrStandard.Items.Add(pgrEvolution) Controls.Add(tbrStandard) End Sub <STAThread()> Public Shared Function Main() As Integer Application.Run(New Exercise) Return 0 End Function End Class This would produce:
After creating a progress bar, you must find a way to make it display its rectangle (and why). |
|
|||||||||||||||||||||||||||||||||||||||
|