.NET

.NET

Reply
*Maksim Sestic
Message 11 of 25 (434 Views)

Re: Hiding a Form causes entire ACAD application to lose focus (AutoCAD 2006)

01-20-2006 05:32 AM in reply to: *Maksim Sestic

It's almost
identical to example code you've sent. Here it is:

 

<CommandMethod("TestCommand")>
_

Public
size=2>
Sub
DisplayForm()

  
Dim
 Form
size=2>As 
New
MyForm

  
class=205360014-19012006>
class=205360014-19012006>
size=2>Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(Form)


color=#0000ff>
class=205360014-19012006>

face="Courier New">End
Sub

 

Form has a button which hides it (
face="Courier New">Me.Hide
), but this is handled via MyForm's
class event handlers.
Even if I create
new object that displays my form within specified command handler
- it should run within defined execution context
neverthless. Could you explain what code do you consider "out of
execution context"?

 

Regards,

Maksim Sestic

 

 

 

Is the code that
calls ShowModalDialog() executed from
a registered command handler, or
something else?

Your problem is most likely that your form is being
shown
by code that's running in the wrong execution context.

--


size=2>http://www.caddzone.com



size=2>AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006

href="http://www.acadxtabs.com">
size=2>http://www.acadxtabs.com



size=2>"Maksim Sestic" <

face=Verdana size=2>info@geoinova.com
>
wrote in message

face=Verdana size=2>news:5063409@discussion.autodesk.com

face=Verdana size=2>...
No, it didn't help. Annoying flickering (ACAD looses
focus and then regains it) still happening. It seems to me that
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog implementation,
which is (I believe) based on AutoCAD's Application Form, passes certain events
to it's parent without some handy overriding.
 
How about a third
constructor of ShowModaDialog:
Public Shared Function ShowModalDialog(ByVal
owner As System.Windows.Forms.IWin32Window, ByVal formToShow As
System.Windows.Forms.Form, ByVal persistSizeAndPosition As Boolean) As
System.Windows.Forms.DialogResult

When should I use it? 

 
Regards,
Maksim Sestic
 
<Jimmie Fulton> wrote
in message

face=Verdana size=2>news:5063304@discussion.autodesk.com

face=Verdana size=2>...
Does this work better for you?

Form.Visible =
False
' Do Something
Form.Visible = True
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 12 of 25 (434 Views)

Re: Hiding a Form causes entire ACAD application to lose focus (AutoCAD 2006)

01-20-2006 07:21 AM in reply to: *Maksim Sestic
Maksim,
As far as the code I sent goes, if you do not want AutoCAD to handle the hiding/showing of the form, just put a me.visible=false at the beginning of the event handler, and a me.visible=true at the end of it.

Also, I have noticed the flickering, but only in explorer windows that have been opened AFTER AutoCAD has been launched. Do you see this same behavior?

C
*Maksim Sestic
Message 13 of 25 (434 Views)

Re: Hiding a Form causes entire ACAD application to lose focus (AutoCAD 2006)

01-20-2006 09:54 AM in reply to: *Maksim Sestic

Yeah, that's it
:-)

 

Maksim,
As far as the code I
sent goes, if you do not want AutoCAD to handle the hiding/showing of the form,
just put a me.visible=false at the beginning of the event handler, and a
me.visible=true at the end of it.

Also, I have noticed the flickering,
but only in explorer windows that have been opened AFTER AutoCAD has been
launched. Do you see this same behavior?

C
*Tony Tanzillo
Message 14 of 25 (434 Views)

Re: Hiding a Form causes entire ACAD application to lose focus (AutoCAD 2006)

01-20-2006 10:09 AM in reply to: *Maksim Sestic
Looks like you caught a bug. I just noticed the same
problem you cite, with my test code. It only seems to
happen with windows that are created while AutoCAD
is running.

I have no idea why they're doing this, but it certainly
isn't pretty and looks very unprofessional.

I have a bit of a problem with Autodesk not fixing API
defects, in cases where the manifestation results in
making our applications look as unprofessional as this
defect seems to do. While the defect isn't 'critical',
it makes your solutions look very unprofessional, and
that's not good.

I expect better than what we're seeing in the way of
'quirks' in the managed wrapper API.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"Maksim Sestic" wrote in message news:5064496@discussion.autodesk.com...
Tony's right, I need to pick several points (as explained in my previous post) and don't want to rely on AutoCAD showing/hiding my ModalDialog consequently. Try to reproduce that odd behaviour via:

1) Open few Explorer windows and let them remain open
2) Run AutoCAD and NETLOAD Tony's library (ACAD keeps focus)
3) Run GetPointTest command (now Form1 gets displayed and keeps focus)
4) Click the button to start points acquisition - what happens then?

4.1) Form1 gets hidden
4.2) ACAD's main window looses it's focus for a second, enough time to see opened windows in step 1)
4.3) ACAD's main window regains focus and lets you pick points...

Pretty odd behaviour.

Regards,
Maksim Sestic





"Tony Tanzillo" wrote in message news:5064392@discussion.autodesk.com...
>> If you are prompting the user, you don't need to hide a form.
>> AutoCAD will hide it when you call the editor.get??? methods.

Yes it will, but if the form is already hidden, then
the GetXxxx method should do nothing.

It needs to work that way because there's cases
where I may want to prompt for several values
while the form remains hidden, so repeatedly
showing/hiding it between each successive input
request isn't going to work well in that case
(for example, the Hatch dialog's "Add Pick points"
button works like that).

A simple test (C#, with nothing but a form with
a single button and label on it) seems to confirm
that the form can be hidden and shown manually,
without relying on the call to GetPoint() to do it
for you:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace ExtensionApplication1
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(150, 66);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(157, 25);
this.button1.TabIndex = 0;
this.button1.Text = "Pick points";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(162, 119);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 16);
this.label1.TabIndex = 1;
this.label1.Text = "label1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(450, 182);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion


[CommandMethod("GetPointTest")]
public static void GetPointTest()
{
using( Form1 form = new Form1() )
AcadApp.ShowModalDialog(form);
}

private void button1_Click(object sender, System.EventArgs e)
{
Editor editor = AcadApp.DocumentManager.MdiActiveDocument.Editor;
ArrayList list = new ArrayList();
PromptPointOptions opts = new PromptPointOptions();
opts.Message = "\nNext point (or ENTER when done): ";
opts.AllowNone = true;
this.Visible = false;
try
{
while( true )
{
PromptPointResult res = editor.GetPoint(opts);
if( res.Status != PromptStatus.OK )
break;

list.Add(res.Value);
}
}
finally
{
this.Visible = true;
label1.Text = string.Format("{0} points picked", list.Count);
}
}
}
}


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

wrote in message news:5064254@discussion.autodesk.com...
Maksim,

I have created a simple project that may help you.

If you are prompting the user, you don't need to hide a form.
AutoCAD will hide it when you call the editor.get??? methods.

Let me know if it works or not.

C
*Maksim Sestic
Message 15 of 25 (434 Views)

Re: Hiding a Form causes entire ACAD application to lose focus (AutoCAD 2006)

01-20-2006 10:40 AM in reply to: *Maksim Sestic

Tony, this one looks sooo non-critical that I'm
expecting it to get fixed in AutoCAD 2008 :-)))

 

Regards,

Maksim Sestic

 

 

Looks like you
caught a bug.  I just noticed the same
problem you cite, with my test
code. It only seems to
happen with windows that are created while
AutoCAD
is running.

I have no idea why they're doing this, but it
certainly
isn't pretty and looks very unprofessional.

I have a bit of
a problem with Autodesk not fixing API
defects, in cases where the
manifestation results in
making our applications look as unprofessional as
this
defect seems to do.  While the defect isn't 'critical',
it
makes your solutions look very unprofessional, and
that's not good.

I
expect better than what we're seeing in the way of
'quirks' in the managed
wrapper API.

--

face=Verdana size=2>http://www.caddzone.com



size=2>AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006

href="http://www.acadxtabs.com">
size=2>http://www.acadxtabs.com



size=2>"Maksim Sestic" <

face=Verdana size=2>info@geoinova.com
>
wrote in message

face=Verdana size=2>news:5064496@discussion.autodesk.com

face=Verdana size=2>...
Tony's right, I need to pick several points (as
explained in my previous post) and don't want to rely on AutoCAD showing/hiding
my ModalDialog consequently. Try to reproduce that odd behaviour
via:
 
1) Open few Explorer windows and let them remain open
2)
Run AutoCAD and NETLOAD Tony's library (ACAD keeps focus)
3) Run GetPointTest
command (now Form1 gets displayed and keeps focus)
4) Click the button to
start points acquisition - what happens then?
 
4.1) Form1 gets
hidden
4.2) ACAD's main window looses it's focus for a second, enough time to
see opened windows in step 1)
4.3) ACAD's main window regains focus and lets
you pick points...
 
Pretty odd
behaviour.
 
Regards,
Maksim
Sestic
 
 
 
 
 
"Tony Tanzillo"
<

size=2>tony.tanzillo@U_KNOW_WHERE.com
>
wrote in message

face=Verdana size=2>news:5064392@discussion.autodesk.com

face=Verdana size=2>...
>> If you are prompting the user, you don't
need to hide a form.
>> AutoCAD will hide it when you call the
editor.get??? methods.

Yes it will, but if the form is already hidden,
then
the GetXxxx method should do nothing. 

It needs to work
that way because there's cases
where I may want to prompt for several values

while the form remains hidden, so repeatedly
showing/hiding it between
each successive input
request isn't going to work well in that case
(for
example, the Hatch dialog's "Add Pick points"
button works like
that).

A simple test (C#, with nothing but a form with
a single button
and label on it) seems to confirm
that the form can be hidden and shown
manually,
without relying on the call to GetPoint() to do it
for
you:

using System;
using System.Drawing;
using
System.Collections;
using System.ComponentModel;
using
System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using
Autodesk.AutoCAD.ApplicationServices;
using
Autodesk.AutoCAD.EditorInput;
using AcadApp =
Autodesk.AutoCAD.ApplicationServices.Application;

namespace
ExtensionApplication1
{
   /// <summary>
  
/// Summary description for Form1.
   ///
</summary>
   public class Form1 :
System.Windows.Forms.Form
   {
     
private System.Windows.Forms.Button button1;
     
private System.Windows.Forms.Label label1;
      ///
<summary>
      /// Required designer
variable.
      ///
</summary>
      private
System.ComponentModel.Container components =
null;

      public
Form1()
     
{
        
//
         // Required for Windows
Form Designer support
        
//
        
InitializeComponent();

        
//
         // TODO: Add any
constructor code after InitializeComponent
call
        
//
      }

      ///
<summary>
      /// Clean up any resources
being used.
      ///
</summary>
      protected override void
Dispose( bool disposing )
     
{
         if( disposing
)
        
{
           
if(components !=
null)
           
{
              
components.Dispose();
           
}
        
}
         base.Dispose( disposing
);
      }

     
#region Windows Form Designer generated code
     
/// <summary>
      /// Required method for
Designer support - do not modify
      /// the
contents of this method with the code editor.
     
/// </summary>
      private void
InitializeComponent()
     
{
         this.button1 = new
System.Windows.Forms.Button();
        
this.label1 = new
System.Windows.Forms.Label();
        
this.SuspendLayout();
         //

         //
button1
         //

         this.button1.Location = new
System.Drawing.Point(150,
66);
         this.button1.Name =
"button1";
         this.button1.Size
= new System.Drawing.Size(157,
25);
         this.button1.TabIndex =
0;
         this.button1.Text = "Pick
points";
         this.button1.Click
+= new
System.EventHandler(this.button1_Click);
        
//
         //
label1
         //

         this.label1.AutoSize =
true;
         this.label1.Location =
new System.Drawing.Point(162,
119);
         this.label1.Name =
"label1";
         this.label1.Size =
new System.Drawing.Size(35,
16);
         this.label1.TabIndex =
1;
         this.label1.Text =
"label1";
         //

         //
Form1
         //

         this.AutoScaleBaseSize =
new System.Drawing.Size(5,
13);
         this.ClientSize = new
System.Drawing.Size(450,
182);
        
this.Controls.Add(this.label1);
        
this.Controls.Add(this.button1);
        
this.Name = "Form1";
        
this.Text = "Form1";
        
this.ResumeLayout(false);

     
}
     
#endregion


     
[CommandMethod("GetPointTest")]
      public static
void GetPointTest()
     
{
         using( Form1 form = new
Form1() )
           
AcadApp.ShowModalDialog(form);                 

      }

     
private void button1_Click(object sender, System.EventArgs
e)
     
{
         Editor editor =
AcadApp.DocumentManager.MdiActiveDocument.Editor;
        
ArrayList list = new
ArrayList();
        
PromptPointOptions opts = new
PromptPointOptions();
        
opts.Message = "\nNext point (or ENTER when done):
";
         opts.AllowNone =
true;
         this.Visible =
false;
        
try
        
{
            while(
true )
           
{
              
PromptPointResult res =
editor.GetPoint(opts);
              
if( res.Status != PromptStatus.OK
)
                 
break;

              
list.Add(res.Value);
           
}
        
}
        
finally
        
{
           
this.Visible =
true;
           
label1.Text = string.Format("{0} points picked",
list.Count);
        
}
      }
   }
}


--


size=2>http://www.caddzone.com



size=2>AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006

href="http://www.acadxtabs.com">
size=2>http://www.acadxtabs.com



size=2><CougerAC> wrote in message

href="news:5064254@discussion.autodesk.com">
size=2>news:5064254@discussion.autodesk.com

size=2>...
Maksim,

I have created a simple project that may help
you.

If you are prompting the user, you don't need to hide a
form.
AutoCAD will hide it when you call the editor.get???
methods.

Let me know if it works or not.

C
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 16 of 25 (434 Views)

Re: Hiding a Form causes entire ACAD application to lose focus (AutoCAD 2006)

11-27-2006 09:44 PM in reply to: *Maksim Sestic
Has anyone found a workaround/solution.

Regards - Nathan
*Maksim Sestic
Message 17 of 25 (433 Views)

Re: Hiding a Form causes entire ACAD application to lose focus (AutoCAD 2006)

11-29-2006 12:10 AM in reply to: *Maksim Sestic
Not yet :-)

wrote in message news:5407830@discussion.autodesk.com...
Has anyone found a workaround/solution.

Regards - Nathan
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 18 of 25 (433 Views)

Re: Hiding a Form causes entire ACAD application to lose focus (AutoCAD 2006)

11-29-2006 02:13 PM in reply to: *Maksim Sestic
The problem does not occur if you minimize the windows so I tried a few approaches to do that. But they had their own problems. One approach resulted in the AutoCAD screen and my form maximised but without focus and the other that did not result in this but displayed the windows as they were minimized.

I have resigned to living with it and hope it will be fixed in 2008.

Regards - Nathan
Valued Mentor
Rob.O
Posts: 261
Registered: ‎06-25-2007
Message 19 of 25 (372 Views)

Re: Hiding a Form causes entire ACAD application to lose focus (AutoCAD 2006)

02-25-2011 12:05 PM in reply to: *Maksim Sestic

Sorry to bring an old post back from the dead, but I was having this same issue and found this thread. I cannot beleive that I am still seeing this issue (Explorer windows opened after AutoCAD has been started flicker on form hide) in AutoCAD 2011!

 

As someone mentioned, this does not occur if the windows are minimized first.

Mentor
matus.brlit
Posts: 246
Registered: ‎03-11-2008
Message 20 of 25 (273 Views)

Re: Hiding a Form causes entire ACAD application to lose focus (AutoCAD 2006)

05-19-2011 05:47 AM in reply to: *Maksim Sestic

i came across this thread while i was trying to solve a similar problem

 

I have a modal form, that shows a new modal form in a button.click event handler

 

    Private Sub MyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyButton.Click

        Me.Hide()
        Dim modalForm As New MyForm()
        AcApp.ShowModalDialog(modalForm)
        Me.Show()

    End Sub

 

 

 

after MyForm is showed, i see it's window and the background is not AutoCAD, but any application that was focused before AutoCAD

the only way to have it behave normally is to have all windows minimized, then the background for MyForm is AutoCAD

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.