Tuesday, December 11, 2007

How to create Toolbar

How to create Toolbar

Step 1

To create a toolbar in Visual Basic, user will need to create a MDI application and then create your menu as we describe above.

Step 2

Once we have got all that, we can create our toolbar, by using Toolbar control and picture box. Drag a component called Toolbar and place it just below your main menu. Then it will automatically scale to fit the menu. As shown in the diagram above.

Step 3

To create each Toolbar button, you need to use ImageList control

Step 4

You have to create an ImageList and then bind it your toolbar

Step 5

In your Window Form toolbar, create an ImageList Control.

Step 6

First we will create an Images for ImageList control.

Step 7

Click on Add to insert new images to this control. We will use some sample images for our demo here.

An example of our output here had shown above.

Step 8

Then we will proceed to setup our toolbar in VB.net. Switch to our Toolbar and then under its imageList set the properties to ImageList1 control that we have created earlier.

Step 9

Okay, then we will set it’s Button properties. Under your toolbar properties select Button and then click on … to open a window.

Step 10

Click on Add to add a toolbar. Under the ImageIndex, set it to an Imagelist that you have created. In this example we will create 2 of this toolbar.

If you would like to set your Tooltip you can do so here.

This is an example of your Toolbar.

Step 11

Then just press F5 and run it. Off course there will be no function to run as you did not put it in.

How to create Custom User Control

How to create Custom User Control

Step 1

You can create custom user control to allow rapid application development. To create a custom control, go to Visual Studio.Net.

Step 2

Go to File and select New then choose Project and select Window Application.

Step 3

Once your project has been created, go to File and select Add New Item.

We will create Custom User control that looks something like this.

Step 4

So just click on UserControl1.vb [Design] tab and then proceed to create a textbox and a button here.

Step 5

Then you can Build it.

Your control which is call UserControl1 will appear in your Toolbox. To use it, click on your Form1 and then drag the user control over your form.

It will look something like this.

Step 6

If you have another form called Form2, by dragging the user component over would allow you to create your control rapidly without having to redesign it.

How to read an XML file to DataSet

How to read an XML file to DataSet

Step 1

To read an XML file to a DataSet, first of all you need to declare a dataset first and then use the method called ReadXML to read your XML file to your dataset


Step 2

Create a datagrid and a button on your form. Then use the following code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim ds As New DataSet("Product")

ds.ReadXml("c:\product2.xml")

With DataGrid1

.DataSource = ds

End With

End Sub

Step 3

This will create a Dataset and then use it’s method of ReadXML to get data from your file. Then associate your dataset to datagrid.

An example of the screen output from the code above is shown below:

How to create MDI Child

How to create MDI Child

Step 1

To create an MDI child, go to the File and select New click event and then declare the following codes.


It is actually the same as creating and show a normal form except the form MdiParemt properties is set to it’s parent.

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click

Dim f2 As New Form2()

f2.MdiParent = Me

f2.Show()

End Sub

An example of the MDI application that we have created are shown below