[Gtk-sharp-list] Problem setting image on Button

James Fitzsimons james.fitzsimons at gmail.com
Sat Apr 8 07:18:31 EDT 2006


Hi all,

Not sure whether this is just my lack of Gtk# knowledge or if it's a bug
so I thought I'd post here. 

I am hacking on a new feature for f-spot and am trying to change the
image on a Button widget in that widgets click event handler.
Unfortunately I can't seem to get this to work for any images other than
Gtk Stock images.

Here is a very simple example I mocked up to test this.

using System;
using Gtk;

public class MyWindow : Window
{	
	Gtk.Button button;
	
	public MyWindow () : base ("MyWindow")
	{
		this.SetDefaultSize (400, 300);
		this.DeleteEvent += new DeleteEventHandler (OnMyWindowDelete);
		
		Gtk.Image img = new Gtk.Image ("f-spot-crop.png");
		button = new Button (img); //L1
		button.Clicked  += ClickEventHandler;
		this.Add (button);
		this.ShowAll ();
	}
	
	private void ClickEventHandler (object obj, EventArgs args)
	{
		Gtk.Image img = new Gtk.Image ("f-spot-desaturate.png");
		button.Image = img;
		Console.WriteLine("Clicked");
	}
	
	void OnMyWindowDelete (object sender, DeleteEventArgs a)
	{
		Application.Quit ();
		a.RetVal = true;
	}
}

This displays the crop image correctly, but never changes it. I the line
commented L1 is changed to look like this:

button = new Button (Stock.New); //L1

And the click event handler is changed to look like this:

private void ClickEventHandler (object obj, EventArgs args)
{
	Gtk.Image img = new Gtk.Image();
	img.Stock = Stock.About;
	button.Image = img;
	Console.WriteLine("Clicked");
}

Then the image changes on the first click of the button.

Any advise on why this isn't working with custom images would be greatly
appreciated!

Regards,
James Fitzsimons
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20060408/f973e7b3/attachment.bin


More information about the Gtk-sharp-list mailing list