按钮加上image和label
- 格式:doc
- 大小:42.50 KB
- 文档页数:3
按钮加上image和label
public class buttons
{
/* Create a new hbox with an image and a label packed into it* and return the box. */
static Widget xpm_label_box(string xpm_filename, string label_text )
{
/* Create box for image and label */
HBox box =new HBox(false, 0);
box.BorderWidth=2;
/* Now on to the image stuff */
Gtk.Image image =new
Gtk.Image(xpm_filename);
/* Create a label for the button */
Label label =new Label (label_text);
/* Pack the image and label into the box
box.PackStart(image, false, false, 3);
box.PackStart(label, false, false, 3);
image.Show();
label.Show();
return box;
}
/* Our usual callback function */
static void callback(object obj, EventArgs args) {
Console.WriteLine("Hello again - cool button
was pressed");
}
/* another callback */
static void delete_event (object obj, DeleteEventArgs args) {
Application.Quit();
}
public static void Main(string[] args)
{
Application.Init();
/* Create a new window */
Window window =new Window ("Pixmap'd Buttons!");
/* It's a good idea to do this for all windows. */ window.DeleteEvent+= delete_event;
/* Sets the border width of the window. */
window.BorderWidth=10;
/* Create a new button */
Button button =new Button();
/* Connect the "clicked" signal of the button to
our callback */
button.Clicked+= callback;
/* This calls our box creating function */
Widget box = xpm_label_box ("info.xpm", "cool
button");
/* Pack and show all our widgets */
box.Show();
button.Add(box);
button.Show();
window.Add(button);
window.ShowAll();
/* Rest in gtk_main and wait for the fun to begin! */ Application.Run();
}
}
多线程例子:
using System;
using System.Threading;
namespace ThreadGuideSamples
{
public class FirstUnsyncThreads {
private int i =0;
public static void Main (string[] args)
{
FirstUnsyncThreads myThreads =new FirstUnsyncThreads ();
}
public FirstUnsyncThreads ()
{
// Creating our two threads. The ThreadStart delegate is points to
// the method being run in a new thread.
Thread firstRunner =new Thread (new ThreadStart (this.firstRun));
Thread secondRunner =new Thread (new ThreadStart (this.secondRun));
// Starting our two threads. Thread.Sleep(10) gives the first Thread
// 10 miliseconds more time.
firstRunner.Start();
Thread.Sleep(10);
secondRunner.Start();
}
// This method is being excecuted on the first thread.
public void firstRun ()
{
while(this.i<10)
{
Console.WriteLine("First runner incrementing i from "+this.i+" to "+++this.i);
// This avoids that the first runner does all the work before
// the second one has even started. (Happens on high performance
// machines sometimes.)
Thread.Sleep(100);
}
}
// This method is being excecuted on the second thread.
public void secondRun ()
{
while(this.i<10)
{
Console.WriteLine("Second runner incrementing i from "+this.i+" to "+++this.i); Thread.Sleep(100);
}
}
}
}。