Modal window and TopMost future does not always work

This is where you talk about Plugins. How they are made and how they work, show examples.

Modal window and TopMost future does not always work

Postby shad » Sat Jan 27, 2018 11:32 am

Hello!
We have a lot messages to operator from plugin and macros. Always this is a Modal Window (called via ShowDialog() function) and TopMost is true.
But I am notice that sometimes a window can be hidden when the operator changes focus to the main UCCNC window. This is not good, because the operator loses the message.
There may be special requirements for opening a modal window from a plug-in or macro. Any ideas?
-- Andrew
UC400ETH
UC300ETH-5LPT
NEURON Lite THC
http://neuroncnc.com/
shad
 
Posts: 331
Joined: Thu Sep 15, 2016 5:23 pm

Re: Modal window and TopMost future does not always work

Postby cncdrive » Mon Jan 29, 2018 7:47 am

The form can get behind if Windows does not know who is the parent/owner of your form.

In a macro you can try:

MyForm.ShowDialog(exec.mainform);

In a plugin you can try:

using (var DummyForm = new Form() { TopMost = true, TopLevel = true })
{
MyForm.ShowDialog(DummyForm);
}
cncdrive
Site Admin
 
Posts: 4717
Joined: Tue Aug 12, 2014 11:17 pm

Re: Modal window and TopMost future does not always work

Postby shad » Mon Jan 29, 2018 3:06 pm

Hmm, strange.
I have a form opened from macros via
Code: Select all
StartupForm.ShowDialog(exec.mainform);

If I try to close this form via button on the form UCCNC halted.
Code: Select all
void CancelHomeButton_Click(object sender, EventArgs e)
{
   StartupForm.Close();
}

How it's work in plugin will check Later.

Thank you!
-- Andrew
UC400ETH
UC300ETH-5LPT
NEURON Lite THC
http://neuroncnc.com/
shad
 
Posts: 331
Joined: Thu Sep 15, 2016 5:23 pm

Re: Modal window and TopMost future does not always work

Postby shad » Mon Jan 29, 2018 3:16 pm

In Plugin it's work perfect.
Thank you!
-- Andrew
UC400ETH
UC300ETH-5LPT
NEURON Lite THC
http://neuroncnc.com/
shad
 
Posts: 331
Joined: Thu Sep 15, 2016 5:23 pm

Re: Modal window and TopMost future does not always work

Postby shad » Tue Jan 30, 2018 8:03 am

Hello Balazs!
Can you check why Frame opened from macro halt UCCNC?
I have a form opened from macro via

Code: Select all
StartupForm.ShowDialog(exec.mainform);


If I try to close this form via button on the form UCCNC halted.

Code: Select all
void CancelHomeButton_Click(object sender, EventArgs e)
{
   StartupForm.Close();
}


Thank you!
Attachments
M27058.rar
This a macro for checking
(1.27 KiB) Downloaded 727 times
-- Andrew
UC400ETH
UC300ETH-5LPT
NEURON Lite THC
http://neuroncnc.com/
shad
 
Posts: 331
Joined: Thu Sep 15, 2016 5:23 pm

Re: Modal window and TopMost future does not always work

Postby cncdrive » Tue Jan 30, 2018 11:18 am

It is likely because the macro is not on the UI thread and Showdialog tries to attach the new Form to the main form,
but the 2 forms are not in the same thread and so there is a conflict.

What you can do is you can invoke the Showdialog on the UI thread, like this:

Code: Select all
exec.mainform.Invoke(new MethodInvoker(() => UI_thr_invoke()));

#Events

void UI_thr_invoke()
{
   MyFrom.ShowDialog(exec.mainform);
}
cncdrive
Site Admin
 
Posts: 4717
Joined: Tue Aug 12, 2014 11:17 pm

Re: Modal window and TopMost future does not always work

Postby shad » Tue Jan 30, 2018 11:27 am

Thank you!!!
It's work PERFECT!!
Now a big problem in the UI was solved for all of us in the plugin and macro :D .
-- Andrew
UC400ETH
UC300ETH-5LPT
NEURON Lite THC
http://neuroncnc.com/
shad
 
Posts: 331
Joined: Thu Sep 15, 2016 5:23 pm

Re: Modal window and TopMost future does not always work

Postby shad » Thu Feb 01, 2018 10:43 am

Hello Balazs!
Today I had to return to the 1.2047 version and this code in macro:
Code: Select all
exec.mainform.Invoke(new MethodInvoker(() => UI_thr_invoke()));

#Events

void UI_thr_invoke()
{
   StartupForm.ShowDialog(exec.mainform);
}

causes an error and the macro does not execute.
when I return to
Code: Select all
StartupForm.ShowDialog();

All fine.

But The
Code: Select all
exec.mainform.Invoke(new MethodInvoker(() => UI_thr_invoke()));

#Events

void UI_thr_invoke()
{
   MyFrom.ShowDialog(exec.mainform);
}

works perfect in the 1.2102
-- Andrew
UC400ETH
UC300ETH-5LPT
NEURON Lite THC
http://neuroncnc.com/
shad
 
Posts: 331
Joined: Thu Sep 15, 2016 5:23 pm

Re: Modal window and TopMost future does not always work

Postby cncdrive » Thu Feb 01, 2018 11:16 am

Yep, .NET 2.0 does not support the lambda operator that good as .NET 4.0, so is why it does not work with the =>.
One solution is to do it like this:

Code: Select all
exec.mainform.Invoke(new MethodInvoker(UI_thr_invoke));

#Events

void UI_thr_invoke()
{
   Form MyForm = new Form();
   MyForm.ShowDialog(exec.mainform);
}
cncdrive
Site Admin
 
Posts: 4717
Joined: Tue Aug 12, 2014 11:17 pm

Re: Modal window and TopMost future does not always work

Postby shad » Thu Feb 01, 2018 12:05 pm

Thank you!!
-- Andrew
UC400ETH
UC300ETH-5LPT
NEURON Lite THC
http://neuroncnc.com/
shad
 
Posts: 331
Joined: Thu Sep 15, 2016 5:23 pm


Return to Plugins

Who is online

Users browsing this forum: No registered users and 3 guests