Results 1 to 6 of 6

Thread: ToolBarButton "Name" property?

  1. #1

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    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?
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. If sender Is Me.ToolBarButton1 Then
    2.  
    3. ElseIf sender Is ToolBarButton2 Then
    4.  
    5. End If
    If it's something else you want then you may have to use the Tag property perhaps.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    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:
    1. Select Case sender
    2.     Case Is = Me.tbbIssues
    3.         Me.tbbCustomers.Pushed = Not Me.tbbIssues.Pushed
    4.         RefreshData()
    5.     Case Is = Me.tbbCustomers
    6.         Me.tbbIssues.Pushed = Not Me.tbbCustomers.Pushed
    7.         RefreshData()
    8.     Case Is = Me.tbbRefresh
    9.         RefreshData()
    10.     Case Is = Me.tbbOpen
    11.         EditIssue()
    12.     Case Is = Me.tbbNew
    13.         NewIssue()
    14. End Select
    Last edited by simonm; Dec 7th, 2005 at 05:54 AM.
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: ToolBarButton "Name" property?

    Oh...thanks. It's a bit sh*t, isn't it?
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width