How to release mouse button when pressed on titlebar while form is disposing and reloading

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
itanas
Posts: 7
Last visit: Mon Jan 29, 2018 2:30 pm

Re: How to release mouse button when pressed on titlebar while form is disposing and reloading

Post by itanas »

Thanks, that makes sense, I will update to how you've shown it. I considered background jobs but code executes in about 1-2 seconds and didn't seem to freeze anything up, yet. I'll try to figure out a solution to when number of labels/pictures is dynamic, that's when re-starting the form with newly discovered number of labels/pictures was handy.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: How to release mouse button when pressed on titlebar while form is disposing and reloading

Post by jvierra »

All of this can be done without restarting the form. Any event can add controls to the form and they will be immediately available. No refresh is required.
User avatar
itanas
Posts: 7
Last visit: Mon Jan 29, 2018 2:30 pm

Re: How to release mouse button when pressed on titlebar while form is disposing and reloading

Post by itanas »

Would you have the answer to my original question. How to ensure mouse is not pressed when the form first loads, or "reset" whatever state the mouse is in.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: How to release mouse button when pressed on titlebar while form is disposing and reloading

Post by jvierra »

There is no way to turn off the mouse on a per-application basis.

Why would you think that you need to do this.
No controls will accept input until after the form is loaded. If you are running some other process after the form is loaded you can just disable controls that you don't want to send events.
User avatar
itanas
Posts: 7
Last visit: Mon Jan 29, 2018 2:30 pm

Re: How to release mouse button when pressed on titlebar while form is disposing and reloading

Post by itanas »

If, at the time of when form.dispose() happens and new form loads a mouse is being pressed on the title-bar/minimize/close button area, the new form's title-bar will be unresponsive.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: How to release mouse button when pressed on titlebar while form is disposing and reloading

Post by jvierra »

As I noted before. You do not need to "Dispose" of a form. You also cannot create a form from inside of a form that will be closed.

I recommend starting by reading what there is on forms programming is Windows. There are still a couple of books available from Wrox and there are many tutorials on MSDN.

Note that PowerShell cannot "Run" a form. Only "ShowDialog" is supported in a console application. Exiling from a form can only be done by either an explicit or implicit "Close".

"Run" and "Show" are not possible in a console application because there is not main window message loop and the code is not compiled with the form but is attached from the main PowerShell thread.

What is it that you are trying to accomplish? Why can you not use Forms as required by PS and the Framework?
This topic is 6 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked