[Gtk-sharp-list] Glade# signal/handler pass object

Alejandro Sánchez alejasanch@yahoo.es
Tue, 25 Nov 2003 23:17:35 +0100


--=-2udG5uEbifaSe+jsJeoo
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Mon, 2003-11-24 at 21:10, Leo Spalteholz wrote:
> On November 24, 2003 10:35 am, Luciano Callero wrote:
> > Try this:
> >
> > void OnButtonClicked(object obj, EventArgs args) {
> > 	// get widget, in this case your button
> > 	Widget wg = (Widget)(obj);
> >   }
> 
> He wants to get the other widget, not the originating button.  In C/GTK+ 
> you get the Button from which the event originated and you can also 
> include a pointer to any other widget of your choice (as I understand it).

Correct

>   
> I don't think this is possible in C#.  You can't get anything out of the 
> EventArgs.
> 

I have a partial solution to my problem with a custom EventArgs,
EventHandler and Event. See attachment and
http://www.csharphelp.com/archives2/archive470.html article

How to link GLib.Signal("clicked") with ButtonClickedEvent?

Thanks

> leo
> 
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
-- 

--=-2udG5uEbifaSe+jsJeoo
Content-Description: 
Content-Disposition: attachment; filename=MyApp.cs
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

namespace MyApp { 
	
	using System;
	using Gtk;
	using GtkSharp;
		
	public class MyApp {
		
		public static void Main (string[] args) {
		
			new MyApp(args);
		}
		
		public MyApp (string[] args) {

			Application.Init ();

	    	Window window = new Window ("My App"); 
			  

			HBox hbox = new HBox(false,3);
			MyButton mybutton = new MyButton("MyButton");
			MyButton mywidget = new MyButton("My other widget");
			mybutton.MyWidget = mywidget;
			
			hbox.PackStart (mybutton, false, false, 0);
			hbox.PackStart (mywidget, false, false, 0);
			window.Add (hbox);
			
			mybutton.Show();
			mywidget.Show();
			hbox.Show();
			window.Show();
			
			mybutton.ButtonClickedEvent += new ButtonClickedEventHandler(OnButtonClicked);
			mybutton.ActivateEvent();
			
			Application.Run ();
					
		}
                
    	class ButtonClickedEventArgs : EventArgs	{
		
			Widget mywidget;

			public Widget MyWidget {
			
				get {
					return mywidget;
				}
		
			}

			public ButtonClickedEventArgs(Widget MyWidget) {
		
				mywidget = MyWidget;
			}
		}
	
		delegate void ButtonClickedEventHandler(object o, ButtonClickedEventArgs args);
	
		class MyButton : Button {
	
			public MyButton(string label) :  base(label){}
			
			Widget mywidget;

			public Widget MyWidget {
		
				get{ 
					return mywidget;
				}
				
				set {
					mywidget = value;
				}
		
			}
		
			public event ButtonClickedEventHandler ButtonClickedEvent;
		
			public void ActivateEvent() {
		
				ButtonClickedEvent( this, new ButtonClickedEventArgs( mywidget ) );
			}
		
			/*[GLib.Signal("clicked")]
			public event ButtonClickedEventHandler ButtonClickedEvent {
				add {
					if (EventList["clicked"] == null)
						Signals["clicked"] = new GtkSharp.voidObjectSignal(this, Handle, "clicked", value, System.Type.GetType("System.EventArgs"));
					else
						((GtkSharp.SignalCallback) Signals ["clicked"]).AddDelegate (value);
					EventList.AddHandler("clicked", value);
				}
				remove {
					EventList.RemoveHandler("clicked", value);
					GtkSharp.SignalCallback cb = Signals ["clicked"] as GtkSharp.SignalCallback;
					if (cb == null)
						return;

					cb.RemoveDelegate (value);

					if (EventList["clicked"] == null) {
						Signals.Remove("clicked");
						cb.Dispose ();
					}
				}
			}*/
		}
		
		void OnButtonClicked (object o, ButtonClickedEventArgs args ) {
	
			Button button = (Button)o;
			button.Destroy();
			args.MyWidget.Destroy();
			
		}
	}
           
};

--=-2udG5uEbifaSe+jsJeoo--