[Gtk-sharp-list] How to validate input on Gtk.Dialog?

Paul Wallimann pwallimann at hotmail.com
Mon Sep 5 13:12:33 EDT 2005

I am still rather new to GTK# and currently struggling with the following:
I want to implement a (modal) Login Dialog that only returns to the calling
method when the user either hits Cancel or enters the correct password and
hits OK. When the user enters the wrong password and hits OK the dialog
should remain open.

I thought I could implement this by simply subclassing from Gtk.Dialog.
Unfortunately, the dialog gets closed immediately after either of the 2
buttons is hit and I have not found a way to execute the validation and
keep the dialog open when the password is wrong. Following is my code
(using gtk-sharp, Version=

using System;
using Gtk;

namespace Testing
        public class LoginDialog : Dialog
                public static void Main (string[] args)
                        LoginDialog dlg = new LoginDialog();
                        dlg.Modal = true;
                        int response = dlg.Run();
                        Console.WriteLine("Main: Response was {0}", (ResponseType)response);
                public LoginDialog()
                        : base()
                        this.AddButton(Stock.Cancel, ResponseType.Cancel);
                        this.AddButton(Stock.Ok, ResponseType.Ok);
                        this.Response += new ResponseHandler(On_dialog_response);
                private void On_dialog_response (object obj, ResponseArgs args)
            Console.WriteLine ("On_dialog_response: args.ResponseId = {0}",
            if (args.ResponseId == ResponseType.Ok)
                args.RetVal = false; // keep dialog open
                protected override bool OnDeleteEvent(Gdk.Event e)
                        // This method is not called. Why?
                        Console.WriteLine("OnDeleteEvent: called");
                        return false;

I would appreciate if someone could tell me how to do it correctly or point
me to an appropriate resource on the internet. Thanks in advance.

Paul Wallimann

More information about the Gtk-sharp-list mailing list