Gtk.Dialog Class
Creates popup windows.

See Also: Dialog Members

Syntax

public class Dialog : Window

Remarks

Gtk.Dialog boxes are a convenient way to prompt the user for a small amount of input, eg. to display a message, ask a question, or anything else that does not require extensive effort by the user.

Gtk# treats a dialog as a window split vertically. The top section is a Gtk.VBox, and is where widgets such as a Gtk.Label or an Gtk.Entry should be packed. The bottom area is known as the Dialog.ActionArea. This is generally used for packing buttons into the dialog which may perform functions such as cancel, ok, or apply. The two areas are separated by a Gtk.HSeparator.

The two primary areas of a dialog can be accessed as the Dialog.Vbox property and the Dialog.ActionArea property. To set the dialog to be modal, use the Window.Modal property.

If you want to block waiting for a dialog to return before returning control flow to your code, you can call Dialog.Run. This function enters a recursive main loop and waits for the user to respond to the dialog, returning the Gtk.ResponseType corresponding to the Gtk.Button the user clicked.

For a simple dialog, you would probably use Gtk.MessageDialog to save yourself some effort. However, you would need to create the Gtk.Dialog contents manually if you had more than a simple message in the Gtk.Dialog.

C# Example

using System;
using Gtk;

namespace GtkDialogSample
{
    public class GtkDialogSample
    {
        Dialog dialog;
        Window win;
		
        static void Main()
        {
            new GtkDialogSample ();
        }
	
        GtkDialogSample ()
        {
            Application.Init ();
            win = new Window ("Test");
            win.SetDefaultSize (250, 250);
            win.DeleteEvent += delegate {
			Application.Quit ();
		  }
            
            Button btn = new Button ("Show About");
            btn.Clicked += on_btn_clicked;
            win.Add (btn);
            
            win.ShowAll ();
            Application.Run ();
        }
		
        void on_btn_clicked (object obj, EventArgs args)
        {
            dialog = new Dialog
                ("Sample", win, Gtk.DialogFlags.DestroyWithParent);
            dialog.Modal = true;
            dialog.AddButton ("Close", ResponseType.Close);
            dialog.Response += on_dialog_response;
            dialog.Run ();
            dialog.Destroy ();
        }
		
        void on_dialog_response (object obj, ResponseArgs args)
        {
            Console.WriteLine (args.ResponseId);
        }
    }
}
        

You also can subclass the Gtk.Dialog when you want to use the same Dialog on several places in your application.

C# Example

using System;
using Gtk;

namespace GtkDialogSample
{

	public class MyDialog:Dialog
	{
	
		public MyDialog(Window w,DialogFlags f ):base("Sample", w, f)
		{
            this.Modal = true;
            this.AddButton ("Close", ResponseType.Close);     	
		}
									
		protected override void OnResponse (ResponseType response_id){
		Console.WriteLine (response_id);
		}
		
	
	}



    public class GtkDialogSample
    {
        MyDialog dialog;
        Window win;
          
        static void Main()
        {
            new GtkDialogSample ();
        }
     
        GtkDialogSample ()
        {
            Application.Init ();
            win = new Window ("Test");
            win.SetDefaultSize (250, 250);
            win.DeleteEvent += new DeleteEventHandler (on_win_delete);
            
            Button btn = new Button ("Show About");
            btn.Clicked += new EventHandler (on_btn_clicked);
            win.Add (btn);
            
            win.ShowAll ();
            Application.Run ();
        }
          
        void on_btn_clicked (object obj, EventArgs args)
        {
            dialog = new MyDialog(win, Gtk.DialogFlags.DestroyWithParent);
            dialog.Run ();
            dialog.Destroy ();
        }
          
      
          
        void on_win_delete (object obj, DeleteEventArgs args)
        {
            Application.Quit ();
        }
    }    

}
   
  

Requirements

Namespace: Gtk
Assembly: gtk-sharp (in gtk-sharp.dll)
Assembly Versions: 2.12.0.0