[Gtk-sharp-list] EventHandler

underdog10 at netcourrier.com underdog10 at netcourrier.com
Thu Jul 14 19:08:22 EDT 2005


Hi,

On the example below i set a right click event on a widget.
All the menuitem have the same Event Callback (in my case OnSwichActiveConnectionClicked  ), because it's only change a label.
I would like to know which menu have been click, so i could change the label to the one click.
I have try playing EventArgs abut without success.
Has any one of you made something similar?

Thanks,
francois

private void PopupPopupConnexion (EventButton ev)
{
	#if ( DEBUG )
	Console.WriteLine ("In PopupPopupConnexion2!");
	#endif
	if (menu == null)
    {
		menu = new Menu ();
		AccelGroup group = new AccelGroup ();
		
		int i = 0;
		for(i = 0; i < config.xboxs.Length; i++){
			if (config.xboxs[i].defaut) { // Default Xbox with icon
				ImageMenuItem item = new Gtk.ImageMenuItem (config.xboxs[i].name, group);
				item.Image = new Gtk.Image (Stock.Apply, IconSize.Menu);
				item.Activated += new EventHandler (OnSwichActiveConnectionClicked);
				menu.Append (item);
			}
			else {
				// Other Xbox with simple menu as Text
				MenuItem item2 = new MenuItem (config.xboxs[i].name);
				item2.Activated += new EventHandler (OnSwichActiveConnectionClicked);
				menu.Append (item2);                                   	
			}
		}			
	}
	menu.ShowAll ();
	menu.Popup (null, null, null, IntPtr.Zero,
					(ev != null) ? ev.Button : 0, (ev != null) ? ev.Time : 0);
}
        
public void OnSwichActiveConnectionClicked (object o, EventArgs args)
{
	#if ( DEBUG )
	Console.WriteLine ("In OnSwichActiveConnectionClicked!"+ args.ToString());
	#endif
	// Switch Label Text to the default xbox connection
	int i = 0;
	for(i = 0; i < config.xboxs.Length; i++){
		if (config.xboxs[i].name.Equals(o.ToString())) {
			// Other Xbox with simple menu as Text
			statuslabelconnexion.Text = config.xboxs[i].name;           	
		}
	}	
}

-------------------------------------------------------------
NetCourrier, votre bureau virtuel sur Internet : Mail, Agenda, Clubs, Toolbar...
Web/Wap : www.netcourrier.com
Téléphone/Fax : 08 92 69 00 21 (0,34 € TTC/min)
Minitel: 3615 NETCOURRIER (0,16 € TTC/min)



More information about the Gtk-sharp-list mailing list