[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.

------=_NextPart_000_007B_01C2A451.CFF3C1C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello,

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
respectively.

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?

Regards,

--
Lee Mallabone.


------=_NextPart_000_007B_01C2A451.CFF3C1C0
Content-Type: application/octet-stream;
	name="eventtest.cs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="eventtest.cs"

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

------=_NextPart_000_007B_01C2A451.CFF3C1C0--