[Gtk-sharp-list] Gtk# bug with multiple EventHandlers

Lee Mallabone gnome@fonicmonkey.net
Sun, 15 Dec 2002 15:51:20 -0000

This is a multi-part message in MIME format.

Content-Type: text/plain;
Content-Transfer-Encoding: 7bit


I'm trying to change the event handler on a button with Gtk#.
As far as I can make out from the docs & code, I should be able to use
the -= and += operators to remove and add signal/event handlers

However, removing an event handler seems to have no effect - the original
handler is still fired when the event occurs. Adding a second event hander
also seems to have no effect - the first handler is still called but the
second is not!

I've attached the simplest test case I could write that demonstrates this
behaviour on my machine. It can be compiled with:
mcs -o eventtext.exe eventtest.cs -r gtk-sharp.dll

I'm running mono/mcs 0.17 and Gtk# 0.6 on Mandrake Linux.

Can someone confirm this as a bug, or am I using the handlers incorrectly?


Lee Mallabone.

Content-Type: application/octet-stream;
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;

using System;=0A=
using Gtk;=0A=
public class eventtest : Window=0A=
 private Button testButton;=0A=
 public eventtest(): base ("event test")=0A=
  	// Make a button for the test event handlers=0A=
  	testButton =3D new Button("Test button");=0A=
	testButton.Clicked +=3D new EventHandler(TestHandler1);=0A=
	// Make a button to change event handlers on the other button=0A=
	Button eventSwitcher =3D new Button("Change event handler");=0A=
	eventSwitcher.Clicked +=3D new EventHandler(EventSwitcher);=0A=
	// Add the buttons to the window=0A=
	HBox box =3D new HBox(true, 5);=0A=
 ////////// Event handlers /////////=0A=
 private void TestHandler1(object sender, EventArgs args)=0A=
  	Console.WriteLine("event handled with handler 1!");=0A=
 private void TestHandler2(object sender, EventArgs args)=0A=
  	Console.WriteLine("event handled with handler 2!");=0A=
 private void EventSwitcher(object sender, EventArgs args)=0A=
 {	=0A=
	testButton.Clicked -=3D new EventHandler(TestHandler1);=0A=
	testButton.Clicked +=3D new EventHandler(TestHandler2);=0A=
 // Initialisation=0A=
 public static int Main(string[] args)=0A=
 	Window eventTest =3D new eventtest();=0A=
  	new eventtest().ShowAll();=0A=
	return 0;=0A=