473,403 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Toolboar

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
5 933
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
* "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
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: ncsthbell | last post by:
Hello, Wanted to ask the best approach to handle this situation: My users want to be able to go into an access application, press a button and it run a report and the report automatically run and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.