.NET

Reply
*Maksim Sestic
Message 1 of 25 (619 Views)

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

619 Views, 24 Replies
01-17-2006 06:46 AM

I've noticed strange behaviour when hiding a
modal Form:

 

Dim Form
color=#0000ff size=2>As

size=2>New
MyForm

Application.ShowModalDialog(Form)

Form.Hide

''' Do something...

Form Show

 

When Form.Hide gets executed AutoCAD's
main window completely looses it's

face=Verdana> focus, causing ugly flickering (if only). Is there any smart
workaround to force AutoCAD not to lose focus when Form.Hide gets
executed?

 

Regards,

Maksim Sestic

 

 

 

 
Active Contributor
jimmie_fulton
Posts: 44
Registered: ‎04-06-2005
Message 2 of 25 (620 Views)

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

01-18-2006 08:04 PM in reply to: *Maksim Sestic
Does this work better for you?

Form.Visible = False
' Do Something
Form.Visible = True
*Maksim Sestic
Message 3 of 25 (620 Views)

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

01-19-2006 02:10 AM in reply to: *Maksim Sestic

No, it didn't
help. Annoying flickering (ACAD looses focus and then regains it) still
happening. It seems to me that
size=2>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

size=1>System.Windows.Forms.IWin32Window
,
ByVal
formToShow As

face="Courier New">System.Windows.Forms.Form

face="Courier New">,
ByVal
persistSizeAndPosition As

size=1>Boolean

face="Courier New">) As
color=#008000
size=1>System.Windows.Forms.DialogResult


When should I
use it?  

 

Regards,

Maksim Sestic

 

Does this work better for
you?

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

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

01-19-2006 07:54 AM in reply to: *Maksim Sestic
Maksim,

First off, what versions of AutoCAD & Visual Studio are you using.

Second, how are you initially hiding the form after you ShowModalDialog? Are you calling the hide method from within the form? Is it immediately after the form is shown?

Third, maybe you could reconsider the variable name "Form" you are using. Form is a type and it is probably not good practice to use it. Although it's not restricted, I can conceive several situations where this is going to cause headaches.
*Maksim Sestic
Message 5 of 25 (619 Views)

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

01-19-2006 10:17 AM in reply to: *Maksim Sestic

1) AutoCAD
2006 / VS.NET 2003

 

2) I'm calling the .Hide method from control
class which initializes MyForm in first place. There are point-picking loops in
my code that require form to be invisible/hidden. It doesn't get hidden
immediately after Form.Show gets executed, it just gets hidden when user
clicks on a form's button.

 

3) Well, that was just an example
:-)

 

To conclude - there's someting tricky about
AutoCAD's ModalDialog implementation...

 

Regards,

Maksim Sestic

 

 

 

 

 

Maksim,

First off, what
versions of AutoCAD & Visual Studio are you using.

Second, how are
you initially hiding the form after you ShowModalDialog? Are you calling the
hide method from within the form? Is it immediately after the form is
shown?

Third, maybe you could reconsider the variable name "Form" you are
using. Form is a type and it is probably not good practice to use it. Although
it's not restricted, I can conceive several situations where this is going to
cause headaches.
*Tony Tanzillo
Message 6 of 25 (621 Views)

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

01-19-2006 02:26 PM in reply to: *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.

--
http://www.caddzone.com

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

"Maksim Sestic" wrote in message news:5063409@discussion.autodesk.com...
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

wrote in message news:5063304@discussion.autodesk.com...
Does this work better for you?

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

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

01-19-2006 02:32 PM in reply to: *Maksim Sestic
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
Active Member
HenryHe
Posts: 9
Registered: ‎08-22-2005
Message 8 of 25 (618 Views)

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

01-19-2006 05:59 PM in reply to: *Maksim Sestic
You can use this dll(attach file).
For example:
//"this" is the class derived from "Form".
using(ARX.HideFormTool tool=new ARX.HideFormTool(this))
{
if(!this.DoIt())
tool.ShowWhenDispose=false;
}
*Tony Tanzillo
Message 9 of 25 (618 Views)

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

01-19-2006 06:30 PM in reply to: *Maksim Sestic
>> 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 10 of 25 (618 Views)

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

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

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

 

 

 

 

 

>> 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community