Results 1 to 2 of 2

Thread: Create ToolBar Buttons

  1. #1

    Thread Starter
    Addicted Member Tengkorak's Avatar
    Join Date
    Nov 2006
    Posts
    240

    Create ToolBar Buttons

    I want to create a toolbar button, which controls toolbar is on MDIForm and I make a function in the Module.
    My code like this:

    VB.NET Code:
    1. Sub AddToolbarButtons()
    2.         'MDI Main form
    3.         Dim fMain As MDIMain
    4.  
    5.         'create toolbar buttons
    6.         With fMain.TBar
    7.             .Buttons.Clear()
    8.             .Buttons.Add(setButton("Add", 1))
    9.             .Buttons.Add(setButton("Modify", 2))
    10.             .Buttons.Add(setButton("Delete", 3))
    11.             .Buttons.Add(setButton("Preview", 4))
    12.             .Buttons.Add(setButton("Refresh", 5))
    13.             .Buttons.Add(setButton("Close", 6))
    14.         End With
    15.  
    16. Function setButton(ByVal txt, ByVal imgIdx) As ToolBarButton
    17.         Dim btn As New ToolBarButton
    18.         btn.Text = txt
    19.         btn.ImageIndex = imgIdx
    20.         Return btn
    21.     End Function

    and I get an error message like this:
    Code:
    An unhandled exception of type 'System.NullReferenceException' occurred in POSClient.exe
    
    Additional information: Object reference not set to an instance of an object.
    at
    VB.NET Code:
    1. 'create toolbar buttons
    2.         With fMain.TBar

    what's the solution ?

    thank you

  2. #2
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Create ToolBar Buttons

    Sounds like fMain.TBar isn't set to an instance of an object, do you set it to a new object anywhere? Cause I don't see you doing that in your code. You dim fMain as MDIMain but you don't set it to a new instance let alone set it's TBar to a new instance.

    Are you trying to add those tool bar buttons to an existing form? If so, you should probably pass it the reference to the existing form rather than trying to make a 2nd one.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

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