C# Detect if Form is in the “Background” / Invisible (for the User)










0















We have some Forms that have no border / no toolbox (overlays)



Whenever the user clicks somewhere else in the underlaying window, the overlay-form is send to the background (regular non-modal-form behaviour)



Is there an Event for this, so the "overlay" could detect it's visibility change and close itself?



Maybe it can be handled within in resize / paint event, where the "invisibility" can be catched?




Background:
Typical "Select-Or-Create-New" UseCase. Clicking "plus" shows the tiny creation-form. Currently it's "topmost", so the user needs to hit "Escape" to get rid of it. (Else there would be a mess of "background-overlays", hence the question)



Would be more "userfriendly" if a click on something else closes that "tiny form":



enter image description here




enter image description here










share|improve this question



















  • 1





    Form.Deactivate?

    – TnTinMn
    Nov 13 '18 at 22:58











  • @TnTinMn Form.Deactivate!

    – dognose
    Nov 13 '18 at 23:03











  • Change the pop-up form to TopLevel = false; and try using this example: How to create drop down information box in C# Winforms?

    – LarsTech
    Nov 13 '18 at 23:15











  • @LarsTech yes, ofc. its no longer "TopLevel". That was just a workaround to avoid having a lot overlays beeing send to the background whenever the user clicks "somewhere else".

    – dognose
    Nov 13 '18 at 23:22












  • I think you missed my point. A pop-up control using a ToolStripControlHost would close the pop-up for you when the user clicks somewhere else. It also wouldn't deactivate your main form.

    – LarsTech
    Nov 13 '18 at 23:27















0















We have some Forms that have no border / no toolbox (overlays)



Whenever the user clicks somewhere else in the underlaying window, the overlay-form is send to the background (regular non-modal-form behaviour)



Is there an Event for this, so the "overlay" could detect it's visibility change and close itself?



Maybe it can be handled within in resize / paint event, where the "invisibility" can be catched?




Background:
Typical "Select-Or-Create-New" UseCase. Clicking "plus" shows the tiny creation-form. Currently it's "topmost", so the user needs to hit "Escape" to get rid of it. (Else there would be a mess of "background-overlays", hence the question)



Would be more "userfriendly" if a click on something else closes that "tiny form":



enter image description here




enter image description here










share|improve this question



















  • 1





    Form.Deactivate?

    – TnTinMn
    Nov 13 '18 at 22:58











  • @TnTinMn Form.Deactivate!

    – dognose
    Nov 13 '18 at 23:03











  • Change the pop-up form to TopLevel = false; and try using this example: How to create drop down information box in C# Winforms?

    – LarsTech
    Nov 13 '18 at 23:15











  • @LarsTech yes, ofc. its no longer "TopLevel". That was just a workaround to avoid having a lot overlays beeing send to the background whenever the user clicks "somewhere else".

    – dognose
    Nov 13 '18 at 23:22












  • I think you missed my point. A pop-up control using a ToolStripControlHost would close the pop-up for you when the user clicks somewhere else. It also wouldn't deactivate your main form.

    – LarsTech
    Nov 13 '18 at 23:27













0












0








0








We have some Forms that have no border / no toolbox (overlays)



Whenever the user clicks somewhere else in the underlaying window, the overlay-form is send to the background (regular non-modal-form behaviour)



Is there an Event for this, so the "overlay" could detect it's visibility change and close itself?



Maybe it can be handled within in resize / paint event, where the "invisibility" can be catched?




Background:
Typical "Select-Or-Create-New" UseCase. Clicking "plus" shows the tiny creation-form. Currently it's "topmost", so the user needs to hit "Escape" to get rid of it. (Else there would be a mess of "background-overlays", hence the question)



Would be more "userfriendly" if a click on something else closes that "tiny form":



enter image description here




enter image description here










share|improve this question
















We have some Forms that have no border / no toolbox (overlays)



Whenever the user clicks somewhere else in the underlaying window, the overlay-form is send to the background (regular non-modal-form behaviour)



Is there an Event for this, so the "overlay" could detect it's visibility change and close itself?



Maybe it can be handled within in resize / paint event, where the "invisibility" can be catched?




Background:
Typical "Select-Or-Create-New" UseCase. Clicking "plus" shows the tiny creation-form. Currently it's "topmost", so the user needs to hit "Escape" to get rid of it. (Else there would be a mess of "background-overlays", hence the question)



Would be more "userfriendly" if a click on something else closes that "tiny form":



enter image description here




enter image description here







c# winforms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 22:54







dognose

















asked Nov 13 '18 at 22:45









dognosedognose

15.9k64790




15.9k64790







  • 1





    Form.Deactivate?

    – TnTinMn
    Nov 13 '18 at 22:58











  • @TnTinMn Form.Deactivate!

    – dognose
    Nov 13 '18 at 23:03











  • Change the pop-up form to TopLevel = false; and try using this example: How to create drop down information box in C# Winforms?

    – LarsTech
    Nov 13 '18 at 23:15











  • @LarsTech yes, ofc. its no longer "TopLevel". That was just a workaround to avoid having a lot overlays beeing send to the background whenever the user clicks "somewhere else".

    – dognose
    Nov 13 '18 at 23:22












  • I think you missed my point. A pop-up control using a ToolStripControlHost would close the pop-up for you when the user clicks somewhere else. It also wouldn't deactivate your main form.

    – LarsTech
    Nov 13 '18 at 23:27












  • 1





    Form.Deactivate?

    – TnTinMn
    Nov 13 '18 at 22:58











  • @TnTinMn Form.Deactivate!

    – dognose
    Nov 13 '18 at 23:03











  • Change the pop-up form to TopLevel = false; and try using this example: How to create drop down information box in C# Winforms?

    – LarsTech
    Nov 13 '18 at 23:15











  • @LarsTech yes, ofc. its no longer "TopLevel". That was just a workaround to avoid having a lot overlays beeing send to the background whenever the user clicks "somewhere else".

    – dognose
    Nov 13 '18 at 23:22












  • I think you missed my point. A pop-up control using a ToolStripControlHost would close the pop-up for you when the user clicks somewhere else. It also wouldn't deactivate your main form.

    – LarsTech
    Nov 13 '18 at 23:27







1




1





Form.Deactivate?

– TnTinMn
Nov 13 '18 at 22:58





Form.Deactivate?

– TnTinMn
Nov 13 '18 at 22:58













@TnTinMn Form.Deactivate!

– dognose
Nov 13 '18 at 23:03





@TnTinMn Form.Deactivate!

– dognose
Nov 13 '18 at 23:03













Change the pop-up form to TopLevel = false; and try using this example: How to create drop down information box in C# Winforms?

– LarsTech
Nov 13 '18 at 23:15





Change the pop-up form to TopLevel = false; and try using this example: How to create drop down information box in C# Winforms?

– LarsTech
Nov 13 '18 at 23:15













@LarsTech yes, ofc. its no longer "TopLevel". That was just a workaround to avoid having a lot overlays beeing send to the background whenever the user clicks "somewhere else".

– dognose
Nov 13 '18 at 23:22






@LarsTech yes, ofc. its no longer "TopLevel". That was just a workaround to avoid having a lot overlays beeing send to the background whenever the user clicks "somewhere else".

– dognose
Nov 13 '18 at 23:22














I think you missed my point. A pop-up control using a ToolStripControlHost would close the pop-up for you when the user clicks somewhere else. It also wouldn't deactivate your main form.

– LarsTech
Nov 13 '18 at 23:27





I think you missed my point. A pop-up control using a ToolStripControlHost would close the pop-up for you when the user clicks somewhere else. It also wouldn't deactivate your main form.

– LarsTech
Nov 13 '18 at 23:27












1 Answer
1






active

oldest

votes


















1














You can use the Deactivate event of the form:



private void Form1_Deactivate(object sender, EventArgs e)

Visible = false;






share|improve this answer























  • Thx, missed the obvious it seems.

    – dognose
    Nov 13 '18 at 23:03






  • 1





    @dognose, this happens, although I have used this event many times (long time ago) I opened a new winform project and looked in the events, because although I knew it was there I didn't remember what was it ;)

    – Ashkan Mobayen Khiabani
    Nov 13 '18 at 23:05











  • @dognose Instead of Visible = false;, you might want to do something like Opacity = .5; so that the form can still be seen (and re-activated again, where you would set Opacity = 1;)

    – Rufus L
    Nov 13 '18 at 23:06












  • Also checked all Events, but after VisibleChanged just reacted on this.visible=x - I expected Disabled to require an explicit setting of this.enabled=false as well :-)

    – dognose
    Nov 13 '18 at 23:08











  • @RufusL this was only to show the event, and dognose is an experienced programmer as his rep shows, he'll get hang of it. and I actually set visibility because of this:**Is there an Event for this, so the "overlay" could detect it's visibility change and close itself**

    – Ashkan Mobayen Khiabani
    Nov 13 '18 at 23:08











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',
autoActivateHeartbeat: false,
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%2f53290645%2fc-sharp-detect-if-form-is-in-the-background-invisible-for-the-user%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









1














You can use the Deactivate event of the form:



private void Form1_Deactivate(object sender, EventArgs e)

Visible = false;






share|improve this answer























  • Thx, missed the obvious it seems.

    – dognose
    Nov 13 '18 at 23:03






  • 1





    @dognose, this happens, although I have used this event many times (long time ago) I opened a new winform project and looked in the events, because although I knew it was there I didn't remember what was it ;)

    – Ashkan Mobayen Khiabani
    Nov 13 '18 at 23:05











  • @dognose Instead of Visible = false;, you might want to do something like Opacity = .5; so that the form can still be seen (and re-activated again, where you would set Opacity = 1;)

    – Rufus L
    Nov 13 '18 at 23:06












  • Also checked all Events, but after VisibleChanged just reacted on this.visible=x - I expected Disabled to require an explicit setting of this.enabled=false as well :-)

    – dognose
    Nov 13 '18 at 23:08











  • @RufusL this was only to show the event, and dognose is an experienced programmer as his rep shows, he'll get hang of it. and I actually set visibility because of this:**Is there an Event for this, so the "overlay" could detect it's visibility change and close itself**

    – Ashkan Mobayen Khiabani
    Nov 13 '18 at 23:08
















1














You can use the Deactivate event of the form:



private void Form1_Deactivate(object sender, EventArgs e)

Visible = false;






share|improve this answer























  • Thx, missed the obvious it seems.

    – dognose
    Nov 13 '18 at 23:03






  • 1





    @dognose, this happens, although I have used this event many times (long time ago) I opened a new winform project and looked in the events, because although I knew it was there I didn't remember what was it ;)

    – Ashkan Mobayen Khiabani
    Nov 13 '18 at 23:05











  • @dognose Instead of Visible = false;, you might want to do something like Opacity = .5; so that the form can still be seen (and re-activated again, where you would set Opacity = 1;)

    – Rufus L
    Nov 13 '18 at 23:06












  • Also checked all Events, but after VisibleChanged just reacted on this.visible=x - I expected Disabled to require an explicit setting of this.enabled=false as well :-)

    – dognose
    Nov 13 '18 at 23:08











  • @RufusL this was only to show the event, and dognose is an experienced programmer as his rep shows, he'll get hang of it. and I actually set visibility because of this:**Is there an Event for this, so the "overlay" could detect it's visibility change and close itself**

    – Ashkan Mobayen Khiabani
    Nov 13 '18 at 23:08














1












1








1







You can use the Deactivate event of the form:



private void Form1_Deactivate(object sender, EventArgs e)

Visible = false;






share|improve this answer













You can use the Deactivate event of the form:



private void Form1_Deactivate(object sender, EventArgs e)

Visible = false;







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 22:59









Ashkan Mobayen KhiabaniAshkan Mobayen Khiabani

20.6k1566115




20.6k1566115












  • Thx, missed the obvious it seems.

    – dognose
    Nov 13 '18 at 23:03






  • 1





    @dognose, this happens, although I have used this event many times (long time ago) I opened a new winform project and looked in the events, because although I knew it was there I didn't remember what was it ;)

    – Ashkan Mobayen Khiabani
    Nov 13 '18 at 23:05











  • @dognose Instead of Visible = false;, you might want to do something like Opacity = .5; so that the form can still be seen (and re-activated again, where you would set Opacity = 1;)

    – Rufus L
    Nov 13 '18 at 23:06












  • Also checked all Events, but after VisibleChanged just reacted on this.visible=x - I expected Disabled to require an explicit setting of this.enabled=false as well :-)

    – dognose
    Nov 13 '18 at 23:08











  • @RufusL this was only to show the event, and dognose is an experienced programmer as his rep shows, he'll get hang of it. and I actually set visibility because of this:**Is there an Event for this, so the "overlay" could detect it's visibility change and close itself**

    – Ashkan Mobayen Khiabani
    Nov 13 '18 at 23:08


















  • Thx, missed the obvious it seems.

    – dognose
    Nov 13 '18 at 23:03






  • 1





    @dognose, this happens, although I have used this event many times (long time ago) I opened a new winform project and looked in the events, because although I knew it was there I didn't remember what was it ;)

    – Ashkan Mobayen Khiabani
    Nov 13 '18 at 23:05











  • @dognose Instead of Visible = false;, you might want to do something like Opacity = .5; so that the form can still be seen (and re-activated again, where you would set Opacity = 1;)

    – Rufus L
    Nov 13 '18 at 23:06












  • Also checked all Events, but after VisibleChanged just reacted on this.visible=x - I expected Disabled to require an explicit setting of this.enabled=false as well :-)

    – dognose
    Nov 13 '18 at 23:08











  • @RufusL this was only to show the event, and dognose is an experienced programmer as his rep shows, he'll get hang of it. and I actually set visibility because of this:**Is there an Event for this, so the "overlay" could detect it's visibility change and close itself**

    – Ashkan Mobayen Khiabani
    Nov 13 '18 at 23:08

















Thx, missed the obvious it seems.

– dognose
Nov 13 '18 at 23:03





Thx, missed the obvious it seems.

– dognose
Nov 13 '18 at 23:03




1




1





@dognose, this happens, although I have used this event many times (long time ago) I opened a new winform project and looked in the events, because although I knew it was there I didn't remember what was it ;)

– Ashkan Mobayen Khiabani
Nov 13 '18 at 23:05





@dognose, this happens, although I have used this event many times (long time ago) I opened a new winform project and looked in the events, because although I knew it was there I didn't remember what was it ;)

– Ashkan Mobayen Khiabani
Nov 13 '18 at 23:05













@dognose Instead of Visible = false;, you might want to do something like Opacity = .5; so that the form can still be seen (and re-activated again, where you would set Opacity = 1;)

– Rufus L
Nov 13 '18 at 23:06






@dognose Instead of Visible = false;, you might want to do something like Opacity = .5; so that the form can still be seen (and re-activated again, where you would set Opacity = 1;)

– Rufus L
Nov 13 '18 at 23:06














Also checked all Events, but after VisibleChanged just reacted on this.visible=x - I expected Disabled to require an explicit setting of this.enabled=false as well :-)

– dognose
Nov 13 '18 at 23:08





Also checked all Events, but after VisibleChanged just reacted on this.visible=x - I expected Disabled to require an explicit setting of this.enabled=false as well :-)

– dognose
Nov 13 '18 at 23:08













@RufusL this was only to show the event, and dognose is an experienced programmer as his rep shows, he'll get hang of it. and I actually set visibility because of this:**Is there an Event for this, so the "overlay" could detect it's visibility change and close itself**

– Ashkan Mobayen Khiabani
Nov 13 '18 at 23:08






@RufusL this was only to show the event, and dognose is an experienced programmer as his rep shows, he'll get hang of it. and I actually set visibility because of this:**Is there an Event for this, so the "overlay" could detect it's visibility change and close itself**

– Ashkan Mobayen Khiabani
Nov 13 '18 at 23:08




















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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290645%2fc-sharp-detect-if-form-is-in-the-background-invisible-for-the-user%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

Kleinkühnau

Makov (Slowakei)

Deutsches Schauspielhaus