CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    [RESOLVED] How to recognize form [X] close?

    I've just found this article on codeproject
    http://www.codeproject.com/KB/dialog/CustomDialogs.aspx
    and it's quite clear to me. However instead of using ShowDialog I'd like to use a simple Show because it should be a modeless form. I can set the DialogResult to OK or Cancel when I clicked a button and read it in a FormClosed event but how can I set it to Cancel when I clicked on the form's [X] symbol? I just can't figure it out I cannot change the DialogResult in FormClose or FormClosing event because it overwrites this what I've set on button's click.
    Last edited by memeloo; May 5th, 2009 at 09:39 AM. Reason: resolved

  2. #2
    Join Date
    Dec 2005
    Location
    Waterloo ON
    Posts
    545

    Re: How to recognize form [X] close?

    Then don't use DialogResult value if you can't figure out how to handle it. Declare a public variable in the form to save DialogResult value, after the form is closed, check the public variable.

    Like: when OK button is clicked, set the public variable to DialogResult.OK; when Cancel button is clicked or [X] is clicked, set it to DIalogResult.Cancel.

    Hope it helps.
    Last edited by jasonli; May 5th, 2009 at 09:22 AM.
    The difficulty is that you have no idea how difficult it is.

    .Net 3.5/VS 2008

  3. #3
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: How to recognize form [X] close?

    oh man, it's always the same, evertime when I ask a question I find the answer few minutes later. Before I asked it here I was looking everywhere with no success *lol* (this must be one of this creazy muphy's laws)

    jasonli: that was the problem, I couldn't distinguish when a form was closed by a button and consequently with the Close() function and when with the [X] symbol, now I know how to do it

    here's the cool solution: http://bytes.com/groups/net-c/278710-form-x-button
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured