Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 62,015 times

Contents

Related Categories

Toolbar Control - Running Code

Running Code

Now that the toolbar has been created, we need to write some code that will run when a button is clicked. Not suprisingly, the ButtonClick event occurs whenever a button is clicked. We are then passed a reference to the button that has been clicked, which we can use to work out what to do.

The code below does exactly this. All you need to do is add a 'Case' for each of the buttons, and then run the code that you want. If you already have a menu item that does the same thing, you could simply call that procedure.

Private Sub Toolbar1_ButtonClick(ByVal Button As ComctlLib.Button)
    Select Case Button.Key 'get the button's key
    Case "Open"
        'perform Open action
    Case "Save"
        'perform Save action
    Case "New"
        'perform New action
    End Select
End Sub

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Re: [2] Toolbar Control

    Posted by vblife2003 on 19 Jan 2007

    Hi,


    I am trying to create keyboard shortcuts for toolbar buttons in VB.NET. Eg. For a button titled Manual I am setting the Text property to '&Manual'. In run mode when I press Alt...

  • Re: [2] Toolbar Control

    Posted by 3nter on 10 Jul 2006

    How would i resize the button if i had the text align to the right.


    for some reason when i try to change the width it switches right back to the width of whichever button that wou...

  • Problem with diabling images in the tool bar

    Posted by skomali on 05 Apr 2005

    Hi!
    I am using a imagelist with a toolbar and when I am trying to disable an image in the tool bar the image is getting completely faded (no image is being displayed but simply a complete gray sectio...

  • TBPaint

    Posted by donkey on 03 Oct 2003

    FYI, if you want to do your own Toolbar graphics I have a freeware toolbar paint program that allows you to create imagelists quickly and easily. You can import icons, individual images from other ima...

  • toolbar code

    Posted by ocanse on 05 Sep 2003

    HI all

    this is my code en c# ,
    I have six button but they no working .

    private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
    {

    }

    who can he...