ToolBarButton "Name" property?
This seems really silly but I can't find the "Name" property of my ToolBarButtons in code.
I have set up a toolbar object at design time on my windows form, giving each button a name so that I might identify it later in code.
However when iterating through my toolbar.buttons collection in code, I can find no name property? Am I just being silly? How do I get to it? :eek2:
Re: ToolBarButton "Name" property?
It's not silly because it doesn't have one. The name property of controls is inherited from the Control class, but the ToolBarButton class does not inherit Control. The name property you see in the Properties window is not an actual property of the object but rather the name of the member variable that will be used to refer to the object. If you want to do something like check which button was clicked in an event handler you can use the actual variables like this:
VB Code:
If sender Is Me.ToolBarButton1 Then
ElseIf sender Is ToolBarButton2 Then
End If
If it's something else you want then you may have to use the Tag property perhaps.
Re: ToolBarButton "Name" property?
Thanks.
Can that be done in a SELECT statement?
I have the following code but it gets a runtime error:
VB Code:
Select Case sender
Case Is = Me.tbbIssues
Me.tbbCustomers.Pushed = Not Me.tbbIssues.Pushed
RefreshData()
Case Is = Me.tbbCustomers
Me.tbbIssues.Pushed = Not Me.tbbCustomers.Pushed
RefreshData()
Case Is = Me.tbbRefresh
RefreshData()
Case Is = Me.tbbOpen
EditIssue()
Case Is = Me.tbbNew
NewIssue()
End Select
Re: ToolBarButton "Name" property?
The expression in a Select Case statement must evaluate to one of the native VB.NET types, i.e. String, Integer, Boolean, Char, Double, etc. For that reason you have to use If statements in this case.
Re: ToolBarButton "Name" property?
Oh...thanks. It's a bit sh*t, isn't it?
Re: ToolBarButton "Name" property?
Things have improved in .NET 2.0. The ToolStrip and MenuStrip classes are huge steps forward over the ToolBar and MainMenu classes.