tags:

views:

456

answers:

2

I want to create a button with the stock "Remove" icon on it, but without the text "Remove". If I use Button button = new Button(Stock.Remove);, I get the opposite: just the text, and no icon. I will have many of these buttons, and the text makes it look cluttered. How do I get just the icon?

Note: these are regular buttons, not toolbar buttons.

Edit: This is how it currently looks:

cluttered

I want to replace these buttons with small, unobtrusive, icon-only buttons.

+2  A: 

First create a stock Gtk.Image, and then create your Gtk.Button, passing the image as its argument.

Image image = new Image(Stock.Remove, IconSize.Button);
Button button = new Button(image);
DoR
Thanks, this works with one tweak: You have to do "new Image(Stock.Remove, IconSize.Button)". If you just pass it Stock.Remove, it seems to use the wrong overload and can't find the image.
Matthew
lol, I was fixing that at the same time your were writing your comment :P
DoR
+1  A: 

See the list of GTK+ stock images. Then just use one of those identifiers in your call to create the button, there is absolutely no need to manually create an Image yourself:

Button remove = Button.NewFromStock(Stock.Remove);

I consider this way cleaner than having to "know" and deal with the proper image size hint.

UPDATE: At the time of writing, the Mono link doesn't actually work. Here is the list of stock items and the gtk_button_new_from_stock() function description, from the core GTK+ C documentation. The GTK# wrapping done in Mono seems to follow the original pretty closely.

unwind
Is it the link that is wrong, or has their site crashed? I get Server Error 500 from that GTK+ stock images link of yours...
Svish
Swish: I think it's the latter, their site seems to have problems. Perhaps I should have said so in the post, but that seemed too transient. :)
unwind