[Gtk-sharp-list] Modal property of Dialog not working

vanosten rick@vanosten.net
11 Jan 2003 10:13:41 +0100

Hi Mike and Gonzalo

Thank you for your help. Dialog::Run() makes the trick :-) I include a
short program that shows the behaviour for reference. Those interested
can play with lines 60 and 62.

Have a nice weekend ... Rick

lÝr, 2003-01-11 kl. 01:35 skrev Mike Kestner:
> On Fri, 2003-01-10 at 13:25, vanosten wrote:
> > Hi
> > The modal property of dialog seems not to be working. Even if I set
> > "dialog.Modal = true" the code in my method goes on, i.e. the appliation
> > is not freezed. I might be missing some general GTK behaviour?
> I've used the Dialog::Run() method successfully in Gtk# for modal
> dialogs.  Haven't gotten around to trying the Modal prop.

lÝr, 2003-01-11 kl. 01:59 skrev Gonzalo Paniagua Javier:
> After setting the dialog as modal, try dialog.TransientFor = parent,
> where parent is the main application window.
> -Gonzalo

using System;

using Gtk;
using GtkSharp;

public class MyApp : Window {

    private VBox mainBox;
    private Dialog dialog;

    public MyApp(string title) : base(title) {
        this.SetDefaultSize(800, 600); //width, height
        this.DeleteEvent += new DeleteEventHandler(OnWindowDelete);
        mainBox = new VBox(false, 2);
        //menu bar with one menu
        MenuBar mb = new MenuBar();
        Menu fileMenu = new Menu();
        MenuItem fileMenuMI = new MenuItem("_File");
        MenuItem dialogMI = new MenuItem("_Dialog");
        dialogMI.Activated += new EventHandler(OnDialog);
        fileMenuMI.Submenu = fileMenu;
        mainBox.PackStart(mb, false, false, 0);
        //rest of gui
        Button button = new Button("Do not press me ;-)");
        mainBox.PackStart(button, true, true, 0);
    } //END public DMyApp(string)

    public static int Main(string[] args) {
        MyApp app = new MyApp("Hello");
        return 0;
    } //END public static int Main(string[])
    private void ShowDialogs() {
        Console.WriteLine("ShowInfoDialog() returned in ShowDialogs()");
    } //END private void ShowDialogs()
    private void ShowInfoDialog() {
        dialog = new Dialog();
        dialog.Title = "A simple dialog";
        VBox vbox = dialog.VBox;
        HBox hbox = new HBox(false, 4);
        vbox.PackStart(hbox, true, true, 0);
        Gtk.Image icon = new Gtk.Image(Stock.DialogInfo, IconSize.Dialog);
        hbox.PackStart(icon, false, false, 0);
        hbox.PackStart(new Label("Maybe it is working"), false, false, 0);
        dialog.AddButton(Stock.Close, 1);
        dialog.Response += new ResponseHandler(OnDialogResponse);
        dialog.Modal = true;
        //dialog.TransientFor = this;
        Console.WriteLine("ShowInfoDialog() reached internally end of method");
    } //END private void ShowInfoDialog()

    //---- EventHandlers -------------------------------------/
    private void OnWindowDelete(object obj, DeleteEventArgs args) {
        args.RetVal = true;
    }   //END private void OnWindowDelete(object, DeleteEventArgs)
    private void OnDialog(object o, EventArgs args) {
    } //private void OnDialog(object, EventArgs)
    private void OnDialogResponse(object o, ResponseArgs args) {
    } //private void OnDialog(object, EventArgs)
} //END public class MyApp : Window