By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,797 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

Toolboar

P: n/a
How do I code a button in the toolbar in Visual
Basic .NET. I added a button but do not know how to code
that button to bring up another form.
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
I believe you need to make a Case select statement

"Ivan" <Iv*****@aol.com> wrote in message
news:0f****************************@phx.gbl...
How do I code a button in the toolbar in Visual
Basic .NET. I added a button but do not know how to code
that button to bring up another form.

Nov 20 '05 #2

P: n/a
* "Ivan" <Iv*****@aol.com> scripsit:
How do I code a button in the toolbar in Visual
Basic .NET. I added a button but do not know how to code
that button to bring up another form.


\\\
Private Sub ToolBar1_ButtonClick( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs _
) Handles ToolBar1.ButtonClick
Select Case True
Case e.Button Is Me.ToolBarButton1
Nov 20 '05 #3

P: n/a
That did work, thank you. Out of curiosity what is that e.Button
statement? What does the e represent?

Thanks again!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #4

P: n/a

I wanted to ask you a follow-up question and I am not sure if the
previous post went through. What does the e.Button actually
reprepsent/mean? The statement did work, though. Thank you very much.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #5

P: n/a
Hello Ivan -

e.Button represents the button on the toolbar that was clicked. You get
one click event for the entire toolbar, not one click event for each button
on the toolbar. The Button property of the ToolBarButtonClickEventArgs in
the click event gives that extra bit of information you need to figure out
which of the toolbar buttons was pressed.

Here's a solution that uses a delegate and avoids the Select statement.
With the Select statement, you run the risk of leaving out one of the
cases. On the other hand, but buttons are added in code, and not in the
designer. The code can be copied directly into a Form class. Then use the
Form_Load event to call the MakeButtons method.

-Robin
VB Team
Delegate Sub ExecuteSub()

Structure ButtonStruct
Sub New(ByVal n As String, ByVal t As String, ByVal e As ExecuteSub)
Name = n
Tip = t
Execute = e
End Sub
Dim Name As String
Dim Tip As String
Dim Execute As ExecuteSub
End Structure

Dim Buttons() As ButtonStruct = { _
New ButtonStruct("Open ", "Open a file", AddressOf DoOpen), _
New ButtonStruct("Save ", "Save", AddressOf DoSave), _
New ButtonStruct("Print ", "Print", AddressOf DoPrint), _
}

Private Sub MakeButtons()
ToolBar1.Appearance = ToolBarAppearance.Normal
ToolBar1.ButtonSize = New Size(ToolBar1.Width / (UBound(Buttons) +
1), ToolBar1.ButtonSize.Height)
Dim bs As ButtonStruct
For Each bs In Buttons
Dim b As New ToolBarButton(bs.Name)
b.ToolTipText = bs.Tip
ToolBar1.Buttons.Add(b)
Next
End Sub

Public Sub DoSave()
' Add code here
End Sub

Public Sub DoPrint()
' Add code here
End Sub

Private Sub DoOpen()
' Add code here
End Sub

Private Sub ToolBar1_ButtonClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.ToolBarButtonClickEventArgs) Handles
ToolBar1.ButtonClick
Buttons(ToolBar1.Buttons.IndexOf(e.Button)).Execut e()
End Sub

--------------------
From: Ivan Weiss <iv*****@optonline.net>
References: <bm************@ID-208219.news.uni-berlin.de>
X-Newsreader: AspNNTP 1.50 (ActionJackson.com)
Subject: Re: Toolboar
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Message-ID: <us**************@TK2MSFTNGP12.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
Date: Fri, 17 Oct 2003 06:29:12 -0700
NNTP-Posting-Host: actionjackson133.dsl.frii.net 216.17.147.133
Lines: 1
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:147659
X-Tomcat-NG: microsoft.public.dotnet.languages.vb
I wanted to ask you a follow-up question and I am not sure if the
previous post went through. What does the e.Button actually
reprepsent/mean? The statement did work, though. Thank you very much.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.