Page 1 of 1

Modal window and TopMost future does not always work

PostPosted: Sat Jan 27, 2018 11:32 am
by shad
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?

Re: Modal window and TopMost future does not always work

PostPosted: Mon Jan 29, 2018 7:47 am
by cncdrive
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);
}

Re: Modal window and TopMost future does not always work

PostPosted: Mon Jan 29, 2018 3:06 pm
by shad
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!

Re: Modal window and TopMost future does not always work

PostPosted: Mon Jan 29, 2018 3:16 pm
by shad
In Plugin it's work perfect.
Thank you!

Re: Modal window and TopMost future does not always work

PostPosted: Tue Jan 30, 2018 8:03 am
by shad
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!

Re: Modal window and TopMost future does not always work

PostPosted: Tue Jan 30, 2018 11:18 am
by cncdrive
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);
}

Re: Modal window and TopMost future does not always work

PostPosted: Tue Jan 30, 2018 11:27 am
by shad
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 .

Re: Modal window and TopMost future does not always work

PostPosted: Thu Feb 01, 2018 10:43 am
by shad
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

Re: Modal window and TopMost future does not always work

PostPosted: Thu Feb 01, 2018 11:16 am
by cncdrive
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);
}

Re: Modal window and TopMost future does not always work

PostPosted: Thu Feb 01, 2018 12:05 pm
by shad
Thank you!!