Calling an event ?

G

genc ymeri

Hi,
I'm trying to call an menuItem_onClick() method from toolbar_Buttonclick
event but it doesn't compile :
I'm doing something like this :


private void tlbMain_ButtonClick(object sender,
System.Windows.Forms.ToolBarButtonClickEventArgs e)

{

mainFormMenu.MenuItems[aIntVariable].Click();

//(725): The event 'System.Windows.Forms.MenuItem.Click' can only appear on
the left hand side of += or -=

//how can I call the above method from toolbar_ButtonClick ?


}



Thank You.
 
O

Oleg Ogurok

You don't call or raise an Event directly. Just call your method
menuItem_onClick() inside tlbMain_ButtonClick. Or better write a separate
method that does what menuItem_onClick() does and then call it both in
menuItem_onClick() and tlbMain_ButtonClick().

Read MSDN docs about events, delegates and protected On<EventName> methods.

-Oleg.
 
G

genc ymeri

The problem is that I don't know the event name or even I don't know what is
the name of menuitem in mainFormMenu.MenuItems[AnIndex].

I did this in other languages so I suppose C# should have one way of doing
it.

Any idea ?


Oleg Ogurok said:
You don't call or raise an Event directly. Just call your method
menuItem_onClick() inside tlbMain_ButtonClick. Or better write a separate
method that does what menuItem_onClick() does and then call it both in
menuItem_onClick() and tlbMain_ButtonClick().

Read MSDN docs about events, delegates and protected On<EventName> methods.

-Oleg.


genc ymeri said:
Hi,
I'm trying to call an menuItem_onClick() method from toolbar_Buttonclick
event but it doesn't compile :
I'm doing something like this :


private void tlbMain_ButtonClick(object sender,
System.Windows.Forms.ToolBarButtonClickEventArgs e)

{

mainFormMenu.MenuItems[aIntVariable].Click();

//(725): The event 'System.Windows.Forms.MenuItem.Click' can only
appear
on
the left hand side of += or -=

//how can I call the above method from toolbar_ButtonClick ?


}



Thank You.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top