Handle

comcrack

Regular
Joined
Jun 14, 2003
Messages
52
Location
Canada
Hy,


Can anyone can tel me how to add a handle. I tryed the help of MSDN but I didn't understand.:confused:


And if you know how to put this handle there it will be real appreciated. --> Menu1.MenuItems.Add("hy",TheHandle)


Thank You

ComCrack
 
.. what?

What do you mean by a handle? Do you mean adding an item to a menu given its handle?
 
I mean to add a handle to mybase like MyBase.Closing. to make a sub :

Visual Basic:
public sub MenuItem_click(byval Id as integer) handles mybase.menuclick

'...

end sub 

'...

private sub any_sub()
     Menu1.MenuItems.Add("hy", mybase.menuclick(id))
end sub
 
Do you mean a handler?

You can do:
Visual Basic:
AddHandler MyMenu.Click, AddressOf HandlerSub
You can assign as many events to the same sub as you want, as long as they are all the same kind of event.
 
You have to put the name of your handling sub there, and make sure the arguments it accepts correspond to the ones that the event you are using passes in.
 
????
there is my two sub. the second is the sub witch I want to call when I click on the menu item declared in my first sub. I also need to send the id (NbMainFrame) when the menuitem is clicked.

Visual Basic:
Private Sub MenuItem66_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem66.Click
        Dim newmainframe As New MainFrame(NbMainFrame + 1, NbMainFrame + 1, Me)
        NbMainFrame += 1
        MainframeTemp(NbMainFrame) = newmainframe
        MainframeOpen(NbMainFrame) = True
        newmainframe.Show()
        Dim sendertemp As Object
        sendertemp = NbMainFrame
????? AddHandler MyMenu.Click, AddressOf HandlerSub ????
        Menu1.MenuItems.Add("Hy",???? What do I have to write Here???? (id))
        Menu1.MenuItems.Item(NbMainFrame + 3).Visible = True
    End Sub



    Private Sub MenuItem_Click(ByVal id As Integer) ??? What do I have to write Here????
        MainframeTemp(id).Activate()
    End Sub
 
Visual Basic:
Private Sub MenuItem66_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem66.Click
        Dim newmainframe As New MainFrame(NbMainFrame + 1, NbMainFrame + 1, Me)
        NbMainFrame += 1
        MainframeTemp(NbMainFrame) = newmainframe
        MainframeOpen(NbMainFrame) = True
        newmainframe.Show()
        Dim sendertemp As Object
        sendertemp = NbMainFrame
        AddHandler MyMenu.Click, AddressOf MenuItem_Click
        Menu1.MenuItems.Add("Hy",MenuItem_Click)
        Menu1.MenuItems.Item(NbMainFrame + 3).Visible = True
    End Sub

    Private Sub MenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)         
          MainframeTemp(id).Activate()
    End Sub
You cant pick your own arguments for event handlers, but you can identify the menu that was clicked with the sender argument that is passed in.
Whats the MainframeTemp object, if I know that I can help you come up with the substitute for the id number.
:)
 
Maybe you could make your ID variable public to the whole class so you dont have to pass it between the sub.
Instead of declraing 1000000(!!) array members you could use an array list, where you can add objects to it without having to worry about the array capacity.
 
if do that :
Visual Basic:
Menu1.MenuItems.Add(NbMainFrame + 3, Menu1.MenuItems.Item(4))
When any of these menuitem is clicked, how can I know witch is clicked?
 
You want to know what menu was clicked and raised the event in your MenuItem_Click handler? If yes, then:
(in your MenuItem_Click handler)
Visual Basic:
If sender Is somemenuitem Then
         MsgBox("some menu item was clicked")
End If
Substitute it with your object names and with what you want to do there.
 
Back
Top