.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add command To button

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
makepeace1
539 Views, 2 Replies

Add command To button

This is my button

 

  Dim pan1button1 As New RibbonButton()
            pan1button1.Text = "STORE"
            pan1button1.ShowText = True
            pan1button1.ShowImage = True
            pan1button1.Image = Images.getBitmap(My.Resources.Store)
            pan1button1.LargeImage = Images.getBitmap(My.Resources.Store_L)
            pan1button1.Orientation = System.Windows.Controls.Orientation.Vertical
            pan1button1.Size = RibbonItemSize.Large
            pan1button1.CommandHandler = New RibbonCommandHandler

 I have had a look online but i can seem to find how i assign the macro to the button

 

The macro i want to use it

 

"^C^C_StoreTree "

 

Thanks in advance

2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: makepeace1

 

Basically, you specify the CommandHandler and CommandParameter properties of a ribbon item (button, in your case):

 

pan1button1.CommandHandler= New MyRibbonCommandHandler()

pan1button1.CommandParameter="^C^C_StoreTree "

 

Then you implement ICommand interface

 

Public class MyRibbonCommandHandler

    Implement System.Windows.Input.ICommand

 

   Public Function CanExecute(...)

     ....

   End Function

 

   Public Event ....

 

   Public Sub Execute(parameter As Object) Implement....

     Dim doc As Document=Application.DocumentManager.MdiActiveDocument

     Dim riboonItem As RiboonCommandItem=TryCast(parameter, RibbonCommandItem)

     If ribbonItem IsNot Nothing Then

       doc.SendStringToExecute(ribbonItem.CommandParameter, True, False, True)

     End If

   End Sub

 

End class

 

Note the code here is just right off my head and entered through Visual Studio, not compiled, thus could have sytex error. Just meant to give you an idea how to do it.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3
makepeace1
in reply to: norman.yuan

Thanks

 

I have just managed to get it sorted just before i got your message

 

I am using The button's ID to run the macro
(i have since added the ID to it )

 

and then is what i had further down

 

        Public Class RibbonCommandHandler
            Implements System.Windows.Input.ICommand


            Public Function CanExecute(ByVal parameter As Object) As Boolean Implements System.Windows.Input.ICommand.CanExecute
                Return True
            End Function

            Public Event CanExecuteChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements System.Windows.Input.ICommand.CanExecuteChanged


            Public Sub Execute(ByVal parameter As Object) Implements System.Windows.Input.ICommand.Execute
                Dim doc As Document = Application.DocumentManager.MdiActiveDocument

                If TypeOf parameter Is RibbonButton Then
                    Dim button As RibbonButton = TryCast(parameter, RibbonButton)
                    doc.SendStringToExecute(button.Id & " ", True, False, False)
                End If
            End Sub


        End Class

 I have just changed this line so that it looks form the button ID and then executes it

 

doc.SendStringToExecute(button.Id & " ", True, False, False)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost