Results 1 to 7 of 7

Thread: Toolbar

  1. #1
    Join Date
    Jan 2004
    Location
    amsterdam
    Posts
    31

    Unanswered: Toolbar

    I'd like to have a few buttons on the toolbar which resets the Working Dir to different aliases. Is it possible to have your own code under parameter 3 of AddButton? Is it possible to use your own Bitmap?
    In the next example you only get the Working Dir Menu at once, which in itself is an improvement, but not really what I want.

    method pushButton(var eventInfo Event)
    var
    tb Toolbar
    endvar

    if tb.create("Work Dir") then
    tb.addButton(ToolbarMiscCluster, ToolbarButtonPush,
    MenuFileWorkingDir, BitMapRemoveFromCat, "WD")

    endif
    endnethod

  2. #2
    Join Date
    Feb 2006
    Location
    Hertfordshire, UK
    Posts
    24
    To be honest I cannot remember fully, but am sure I've done this before.

    If you assume in the example below your bitmap file is C:\tbar_icon.bmp then I believe you can use the following code:

    var
    tb Toolbar
    endVar

    if tb.create("Work dir") then
    tb.addButton(ToolbarMiscCluster, ToolbarButtonPush, MenuFileWorkingDir,
    readFromFile("C:\tbar_icon.bmp"), "WD")
    endIf

  3. #3
    Join Date
    Jan 2004
    Location
    amsterdam
    Posts
    31

    toolbar

    Thank you for the reply. HOwever, it does not work, I get a Parameter Mismatch.

    ReadFromFile is a logical, the routine needs a graphic.

  4. #4
    Join Date
    Feb 2006
    Location
    Hertfordshire, UK
    Posts
    24
    Ok, it was almost good, try the following as an example

    Code:
    var
      tbHandle   Toolbar
      grHandle   Graphic
    endVar
    
    grHandle.readFromFile("C:\tbar_icon.bmp")
    
    if tbHandle.create("Work dir") then
      tbHandle.addButton(ToolbarMiscCluster, ToolbarButtonPush,
                                     MenuFileWorkingDir, grHandle, "WD")
    endIf
    What this will do is load the bmp into a graphic variable and then use the graphic variable in your addbutton statement to declare the image you want in your toolbar.

  5. #5
    Join Date
    Jan 2004
    Location
    amsterdam
    Posts
    31

    programming the toolbar

    Yes!

    that works, thanks, are you in for the first part of my question, putting your own code into this?

  6. #6
    Join Date
    Feb 2006
    Location
    Hertfordshire, UK
    Posts
    24
    No i haven't put my own code against this button but you can easily do this.

    The toolbar button event triggers a menuAction event using an id number, if in the menuAction event for the form you trap when this id is sent in you can call your custom method to execute.

    The following is an example:

    In the forms open method the following code exists:

    Code:
    method open(var eventInfo Event)
    
      if eventInfo.isPreFilter() then
        ;// This code executes for each object on the form
    		
      else
        ;// This code executes only for the form
    
        tb.create("Test")
        tb.addButton(ToolbarMiscCluster, ToolbarButtonPush,
                UserMenu + 1, BitmapAddTable, "Custom")
        tb.show()
    		
      endIf
    
    endMethod
    Within the form I have a custom method called showMyMessage which contains the following code:

    Code:
    method showMyMessage()
    
      msgInfo("showMyMessage",
        "This is a custom method called from a toolbar button")
    
    endMethod
    Within the menuAction method I trap the code and execute my own method/code as follows:

    Code:
    method menuAction(var eventInfo MenuEvent)
      var
        siEvent    SmallInt
      endVar
    
      siEvent = eventInfo.id()  ; Get the Event ID into a variable
    
      if eventInfo.isPreFilter() then
        ;// This code executes for each object on the form
    
      else
        ;// This code executes only for the form
    
        ; Menu/Toolbar Event Custom Processing
        switch
            case siEvent = UserMenu + 1 :
              showMyMessage()
    
            otherWise :
              doDefault
    
          endSwitch
    		
      endIf
    
    endMethod
    If you want to add more custom methods to a toolbar then the trick is where you stated MenuWorkingDir you replace this with a constant value, for custom events this should always be UserMenu + <your number> and then trap for this value in the menuAction method of the form.

    Hope this helps

    Regards,
    Jonathan

  7. #7
    Join Date
    Jan 2004
    Location
    amsterdam
    Posts
    31

    programming the toolbar

    Yes! this works wonderfully. You did a great job.
    Now I can avoid all those annoying mouse clicks .
    Willem

Posting Permissions

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