DialogResult.Cancel on Form.ShowDialog() when switching to Desktop











up vote
0
down vote

favorite












I am trying to show a UI (WinForms) via result = new Form().ShowDialog(). The dialog pops up, works as expected but when i press Windows + D to tab away, the result immediately returns DialogResult.Cancel. Is there any way to keep the Form open when i am switching to desktop?



If there are any more questions or if it is unclear, please ask.



Best regards










share|improve this question






















  • Do you have a keyboard accelerator which is using D in a Dialog's Button?
    – Jimi
    Nov 15 at 17:25












  • @Jimi No i don't, it is a basic Form with 2 buttons, one returning DialogResult.Canceland one returning DialogResult.OK
    – Julian Peil
    Nov 16 at 8:37










  • Well, since Win+D does not close any dialog, there's something that triggers the Cancel Button Click event (it could also be a System HotKey). Try setting the CancelButton property of the Form to (none) and set the DialogResult in the Button.Click event, with: this.DialogResult = DialogResult.Cancel;. But keep it commented out, or set a BreakPoint there, and try again. Btw, you do know that an accelerator is defined by a letter prefixed by &. Not necessarily set on the Button.
    – Jimi
    Nov 16 at 9:15












  • @Jimi i tried your suggestion out but it does not work for me. the breakpoint is hit when i click on the button, but is not hit when i tab to my desktop but the DialogResult is still set somehow. I have looked at the HotKeys aswell, but could not find anything either. Guess it might not be possible then. Thank you for your help!
    – Julian Peil
    Nov 16 at 12:48










  • Since this happens, than it's possible :). If you have disabled the DialogResult related properties on the Form dialog (have you?), it's then triggered by the code the instanciate the Dialog. There's not enough code here to tell where/why.
    – Jimi
    Nov 16 at 13:07















up vote
0
down vote

favorite












I am trying to show a UI (WinForms) via result = new Form().ShowDialog(). The dialog pops up, works as expected but when i press Windows + D to tab away, the result immediately returns DialogResult.Cancel. Is there any way to keep the Form open when i am switching to desktop?



If there are any more questions or if it is unclear, please ask.



Best regards










share|improve this question






















  • Do you have a keyboard accelerator which is using D in a Dialog's Button?
    – Jimi
    Nov 15 at 17:25












  • @Jimi No i don't, it is a basic Form with 2 buttons, one returning DialogResult.Canceland one returning DialogResult.OK
    – Julian Peil
    Nov 16 at 8:37










  • Well, since Win+D does not close any dialog, there's something that triggers the Cancel Button Click event (it could also be a System HotKey). Try setting the CancelButton property of the Form to (none) and set the DialogResult in the Button.Click event, with: this.DialogResult = DialogResult.Cancel;. But keep it commented out, or set a BreakPoint there, and try again. Btw, you do know that an accelerator is defined by a letter prefixed by &. Not necessarily set on the Button.
    – Jimi
    Nov 16 at 9:15












  • @Jimi i tried your suggestion out but it does not work for me. the breakpoint is hit when i click on the button, but is not hit when i tab to my desktop but the DialogResult is still set somehow. I have looked at the HotKeys aswell, but could not find anything either. Guess it might not be possible then. Thank you for your help!
    – Julian Peil
    Nov 16 at 12:48










  • Since this happens, than it's possible :). If you have disabled the DialogResult related properties on the Form dialog (have you?), it's then triggered by the code the instanciate the Dialog. There's not enough code here to tell where/why.
    – Jimi
    Nov 16 at 13:07













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to show a UI (WinForms) via result = new Form().ShowDialog(). The dialog pops up, works as expected but when i press Windows + D to tab away, the result immediately returns DialogResult.Cancel. Is there any way to keep the Form open when i am switching to desktop?



If there are any more questions or if it is unclear, please ask.



Best regards










share|improve this question













I am trying to show a UI (WinForms) via result = new Form().ShowDialog(). The dialog pops up, works as expected but when i press Windows + D to tab away, the result immediately returns DialogResult.Cancel. Is there any way to keep the Form open when i am switching to desktop?



If there are any more questions or if it is unclear, please ask.



Best regards







c# winforms modal-dialog showdialog






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 at 15:37









Julian Peil

657




657












  • Do you have a keyboard accelerator which is using D in a Dialog's Button?
    – Jimi
    Nov 15 at 17:25












  • @Jimi No i don't, it is a basic Form with 2 buttons, one returning DialogResult.Canceland one returning DialogResult.OK
    – Julian Peil
    Nov 16 at 8:37










  • Well, since Win+D does not close any dialog, there's something that triggers the Cancel Button Click event (it could also be a System HotKey). Try setting the CancelButton property of the Form to (none) and set the DialogResult in the Button.Click event, with: this.DialogResult = DialogResult.Cancel;. But keep it commented out, or set a BreakPoint there, and try again. Btw, you do know that an accelerator is defined by a letter prefixed by &. Not necessarily set on the Button.
    – Jimi
    Nov 16 at 9:15












  • @Jimi i tried your suggestion out but it does not work for me. the breakpoint is hit when i click on the button, but is not hit when i tab to my desktop but the DialogResult is still set somehow. I have looked at the HotKeys aswell, but could not find anything either. Guess it might not be possible then. Thank you for your help!
    – Julian Peil
    Nov 16 at 12:48










  • Since this happens, than it's possible :). If you have disabled the DialogResult related properties on the Form dialog (have you?), it's then triggered by the code the instanciate the Dialog. There's not enough code here to tell where/why.
    – Jimi
    Nov 16 at 13:07


















  • Do you have a keyboard accelerator which is using D in a Dialog's Button?
    – Jimi
    Nov 15 at 17:25












  • @Jimi No i don't, it is a basic Form with 2 buttons, one returning DialogResult.Canceland one returning DialogResult.OK
    – Julian Peil
    Nov 16 at 8:37










  • Well, since Win+D does not close any dialog, there's something that triggers the Cancel Button Click event (it could also be a System HotKey). Try setting the CancelButton property of the Form to (none) and set the DialogResult in the Button.Click event, with: this.DialogResult = DialogResult.Cancel;. But keep it commented out, or set a BreakPoint there, and try again. Btw, you do know that an accelerator is defined by a letter prefixed by &. Not necessarily set on the Button.
    – Jimi
    Nov 16 at 9:15












  • @Jimi i tried your suggestion out but it does not work for me. the breakpoint is hit when i click on the button, but is not hit when i tab to my desktop but the DialogResult is still set somehow. I have looked at the HotKeys aswell, but could not find anything either. Guess it might not be possible then. Thank you for your help!
    – Julian Peil
    Nov 16 at 12:48










  • Since this happens, than it's possible :). If you have disabled the DialogResult related properties on the Form dialog (have you?), it's then triggered by the code the instanciate the Dialog. There's not enough code here to tell where/why.
    – Jimi
    Nov 16 at 13:07
















Do you have a keyboard accelerator which is using D in a Dialog's Button?
– Jimi
Nov 15 at 17:25






Do you have a keyboard accelerator which is using D in a Dialog's Button?
– Jimi
Nov 15 at 17:25














@Jimi No i don't, it is a basic Form with 2 buttons, one returning DialogResult.Canceland one returning DialogResult.OK
– Julian Peil
Nov 16 at 8:37




@Jimi No i don't, it is a basic Form with 2 buttons, one returning DialogResult.Canceland one returning DialogResult.OK
– Julian Peil
Nov 16 at 8:37












Well, since Win+D does not close any dialog, there's something that triggers the Cancel Button Click event (it could also be a System HotKey). Try setting the CancelButton property of the Form to (none) and set the DialogResult in the Button.Click event, with: this.DialogResult = DialogResult.Cancel;. But keep it commented out, or set a BreakPoint there, and try again. Btw, you do know that an accelerator is defined by a letter prefixed by &. Not necessarily set on the Button.
– Jimi
Nov 16 at 9:15






Well, since Win+D does not close any dialog, there's something that triggers the Cancel Button Click event (it could also be a System HotKey). Try setting the CancelButton property of the Form to (none) and set the DialogResult in the Button.Click event, with: this.DialogResult = DialogResult.Cancel;. But keep it commented out, or set a BreakPoint there, and try again. Btw, you do know that an accelerator is defined by a letter prefixed by &. Not necessarily set on the Button.
– Jimi
Nov 16 at 9:15














@Jimi i tried your suggestion out but it does not work for me. the breakpoint is hit when i click on the button, but is not hit when i tab to my desktop but the DialogResult is still set somehow. I have looked at the HotKeys aswell, but could not find anything either. Guess it might not be possible then. Thank you for your help!
– Julian Peil
Nov 16 at 12:48




@Jimi i tried your suggestion out but it does not work for me. the breakpoint is hit when i click on the button, but is not hit when i tab to my desktop but the DialogResult is still set somehow. I have looked at the HotKeys aswell, but could not find anything either. Guess it might not be possible then. Thank you for your help!
– Julian Peil
Nov 16 at 12:48












Since this happens, than it's possible :). If you have disabled the DialogResult related properties on the Form dialog (have you?), it's then triggered by the code the instanciate the Dialog. There's not enough code here to tell where/why.
– Jimi
Nov 16 at 13:07




Since this happens, than it's possible :). If you have disabled the DialogResult related properties on the Form dialog (have you?), it's then triggered by the code the instanciate the Dialog. There's not enough code here to tell where/why.
– Jimi
Nov 16 at 13:07












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










I have not come up with a solution for this exact problem. Therefore, to workaround, I used Form.Show() instead of Form.ShowDialog() and referenced the DialogResult property of the Form, rather than the return value of Form.ShowDialog().






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322901%2fdialogresult-cancel-on-form-showdialog-when-switching-to-desktop%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    I have not come up with a solution for this exact problem. Therefore, to workaround, I used Form.Show() instead of Form.ShowDialog() and referenced the DialogResult property of the Form, rather than the return value of Form.ShowDialog().






    share|improve this answer

























      up vote
      0
      down vote



      accepted










      I have not come up with a solution for this exact problem. Therefore, to workaround, I used Form.Show() instead of Form.ShowDialog() and referenced the DialogResult property of the Form, rather than the return value of Form.ShowDialog().






      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        I have not come up with a solution for this exact problem. Therefore, to workaround, I used Form.Show() instead of Form.ShowDialog() and referenced the DialogResult property of the Form, rather than the return value of Form.ShowDialog().






        share|improve this answer












        I have not come up with a solution for this exact problem. Therefore, to workaround, I used Form.Show() instead of Form.ShowDialog() and referenced the DialogResult property of the Form, rather than the return value of Form.ShowDialog().







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 18:24









        Julian Peil

        657




        657






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322901%2fdialogresult-cancel-on-form-showdialog-when-switching-to-desktop%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy