English 中文(简体)
In Gtk, how do I make a Button with just a stock icon?
原标题:
  • 时间:2009-11-14 17:20:58
  •  标签:
  • c#
  • gtk
  • gtk#

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.

最佳回答

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);
问题回答

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.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签