Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9146915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:51:42+00:00 2026-06-17T10:51:42+00:00

I am trying to close a Gtk# Window in the code by clicking a

  • 0

I am trying to close a Gtk# Window in the code by clicking a button. That is, the button should have the same effect as the X button in the title bar.

While the window does close, however, the DeleteEvent does not fire when clicking my own button, as opposed to clicking the X title bar button.

This is some minimal sample code:

    using System;

    using Gtk;

    namespace GtkSharpTest
    {
        class Program
        {
            [STAThread]
            public static void Main(string[] args)
            {
                Application.Init();

                using (Window win = new Window("Test")) {
                    win.SetSizeRequest(300, 200);
                    win.Hidden += delegate(object sender, EventArgs e) {
                        Application.Quit();
                    };
                    win.DeleteEvent += delegate(object o, DeleteEventArgs e) {
                        using (MessageDialog dlg = new MessageDialog(win,
                                                                     DialogFlags.Modal,
                                                                     MessageType.Question,
                                                                     ButtonsType.YesNo,
                                                                     "Really close?")) {
                            ResponseType result = (ResponseType)dlg.Run();
                            dlg.Destroy();
                            if (result == ResponseType.No) {
                                e.RetVal = true;
                            }
                        }
                    };

                    Button bClose = Button.NewWithLabel("Close");
                    bClose.Clicked += delegate(object sender, EventArgs e) {
                        // ???
                    };
                    win.Add(bClose);

                    win.ShowAll();
                    Application.Run();
                }
            }
        }
    }

The line that I’m looking for is marked with // ???.

I have tried various calls there:

  • win.Hide();
  • win.HideAll();
  • win.Destroy();

Both Hide and Destroy were suggested in this forum for closing Gtk windows. The selected answer in this SO post suggests Destroy, too, and even claims that the delete event gets fired when calling that method. However, I cannot reproduce that claim; all the aforementioned methods just make the window disappear, but the DeleteEvent is only ever fired if I close the window with the X title bar button.

In other words, you could say I am looking for a Gtk# equivalent of the Windows Forms/WPF Close() methods. Calling these exactly simulates a click on the X title bar button, as the respective Closing events are fired and there is still a chance to prevent the form/window from being closed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:51:43+00:00Added an answer on June 17, 2026 at 10:51 am

    You are correct, the delete event is only fired when the window manager tries to close the window (i.e. the user clicks on the X button.)

    You can use Destroy to close a window. I’m not 100% sure but I think this triggers the DestroyEvent.

    However, if you want to exactly simulate clicking the X button, then you need to send a DeleteEvent with window.Event().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to close the window on button click but am unable
I am trying to close child window if host name are same of parent
When trying to compile with Code::Blocks the example that comes up with GTK+: #include
I am trying to close a window after executing a function that is not
I'm trying to close a child window with JavaScript, and in Firefox everything works
i am trying to write a program that close explorer then runs another program.
I'm trying to close a parent container when an internally nested button is clicked.
I am trying to close a window using window.close() but this works on IE
i'm trying to close the browser window with the ESC key, but dont know
I am trying to close parent window from child window using javascript, but its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.