Author Topic: Custom dialog boxes examples?  (Read 18199 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Custom dialog boxes examples?
« Reply #15 on: August 02, 2006, 01:35:15 PM »
Tim:

 One good source is The AutoLisp Tutorials DCL-Dialog Control Language by Kenny Rammage @ www.afralisp.com

MGF
Thanks for the tip, but I know how to write dcl's, it this .Net (C#) that I don't know how to write.
FYI...
It's not "afralisp.com" anymore, it www.afralisp.net now.  :-)

And welcome to theswamp MGF.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Custom dialog boxes examples?
« Reply #16 on: August 04, 2006, 03:16:43 PM »
So here is my first (working) attempt.  Do I use the LockDocument method apporiatly? and why do you need it?  I'm trying to understand what it does.

Thanks in advance. Now on to the code.  :lmao:
Code: [Select]
using System;
using System.Drawing;
using System.Windows.Forms;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(Test.MyDialog))]

namespace Test
{
/// <summary>
/// Description of MyDialog.
/// </summary>
public class MyDialog : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Button button2;
public MyDialog()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();

//
// TODO: Add constructor code after the InitializeComponent() call.
//
}

#region Windows Forms Designer generated code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent() {
this.button2 = new System.Windows.Forms.Button();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button2
//
this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button2.Location = new System.Drawing.Point(104, 48);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "Cancel";
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(16, 8);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(168, 24);
this.richTextBox1.TabIndex = 2;
this.richTextBox1.Text = "Test just to see.";
//
// button1
//
this.button1.Location = new System.Drawing.Point(8, 48);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Okay";
this.button1.Click += new System.EventHandler(this.Button1Click);
//
// MyDialog
//
this.AcceptButton = this.button1;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.button2;
this.ClientSize = new System.Drawing.Size(200, 77);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "MyDialog";
this.Text = "MyDialog";
this.ResumeLayout(false);
}
#endregion
void Button1Click(object sender, System.EventArgs e)
{
this.Close();
}
void Button2Click(object sender, System.EventArgs e)
{
this.Close();
}
[CommandMethod("TestDialog")]
public void ShowMyDialog()
{
DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
MyDialog modalForm = new MyDialog();
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(modalForm);
docLock.Dispose();
}

}
}
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Custom dialog boxes examples?
« Reply #17 on: August 04, 2006, 03:36:35 PM »
I made my box even prettier.  I anchored all the elements, and I gave it a min and max size.  That is easy, and fun.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Re: Custom dialog boxes examples?
« Reply #18 on: August 04, 2006, 04:50:42 PM »
Do I use the LockDocument method apporiatly?
Hey Tim,
Anytime that an object implements the IDisposable interface and it needs to be disposed, you should use the Try..Catch..Finally construct, or what I generally prefer, wrap everything in a Using(DocumentLock docLock = ...) {} block.
Bobby C. Jones

LE

  • Guest
Re: Custom dialog boxes examples?
« Reply #19 on: August 04, 2006, 04:59:08 PM »
Tim;

You are doing your homework my friend, I do not have the IDE installed at home, but will try your sample ... can you describe each of the steps (I asked this, because that's how I was able to understand what I know now about ObjectARX/C++) - that will help others better.

Cheers!

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Custom dialog boxes examples?
« Reply #20 on: August 04, 2006, 05:21:38 PM »
Do I use the LockDocument method apporiatly?
Hey Tim,
Anytime that an object implements the IDisposable interface and it needs to be disposed, you should use the Try..Catch..Finally construct, or what I generally prefer, wrap everything in a Using(DocumentLock docLock = ...) {} block.

So if I read you correctly, you would have done something like (not tested)
Code: [Select]
public void ShowMyDialog()
{
using (DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();)
                       {
MyDialog modalForm = new MyDialog();
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(modalForm);
}
docLock.Dispose();
}
or
Code: [Select]
public void ShowMyDialog()
{
try
                       {
MyDialog modalForm = new MyDialog();
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(modalForm);
}
catch
{
}
finally
{
}
}
Nothing to dispose of, since I don't get and 'object' right?  Or am I way off base.  I know, I'm slow, but I'm trying.  Thanks for your help Bobby.  :roll: :wink:



Tim;

You are doing your homework my friend, I do not have the IDE installed at home, but will try your sample ... can you describe each of the steps (I asked this, because that's how I was able to understand what I know now about ObjectARX/C++) - that will help others better.

Cheers!
Sure Luis.  I dl'ed the artice here which helped a lot with understanding dialog boxes (forms), even though it is written for VB.net (I had to become a member, so that I could dl the pdf version of the file [its free]).  Once I had the look of the dialog I wanted, I then changed each objects properties.

First I changed the "Cancel" buttons properties:  I anchored it to both the right side, and the bottom of the form

Second I changed the "Okay" buttons properties: I also anchored it to the bottom and right side, but the right side of this button is anchored to the left side of the "Cancel" button (which happens by default), so they will always be the same space apart.

Third I change the "richTextBox" properties:  I anchored this on all sides, so the bottom is now anchored to the top of the buttons, so now that space is always the same.

The order of the anchoring is important.  I'm not sure if it's the order of the anchoring, or the order of making the items in the form.  But my worked with the ordering of the anchoring, so that is what I'm going to go with.  :-)

Then I saw that I could make the dialog as big or as small as I wanted.  This didn't work because you could make it so small that you couldn't see anything.  So on the form there is an area for minimum and maximum size.  You can set those to what you want.  A helpful hint I noticed is, there is also a property that tells you the current size of the dialog, so you can use that as a starting point.

Hope that is what you wanted Luis.   :-D
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Re: Custom dialog boxes examples?
« Reply #21 on: August 04, 2006, 05:39:14 PM »
So if I read you correctly, you would have done something like (not tested)
close.  There's no need for you to call .Dispose() when using Using.  When the using code block is exited, whether by hook or crook, .Dispose() will be called on the object that you're Using (not tested either :-)).

Code: [Select]
public void ShowMyDialog()
{
  using (DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
  {
    MyDialog modalForm = new MyDialog();
    Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(modalForm);
  }
}

You can do the exact same with try..catch..finally like this
Code: [Select]
public void ShowMyDialog()
  {
    try
    {
      DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
      MyDialog modalForm = new MyDialog();
      Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(modalForm);
    }
    catch
    {}
    finally
    {
      docLock.Dispose();
    }
}

Thanks for your help Bobby.  :roll: :wink:
You're most welcome :-)
Bobby C. Jones

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Custom dialog boxes examples?
« Reply #22 on: August 04, 2006, 05:56:23 PM »
Thanks Bobby!!!  I found out some stuff (much what you just told me) about using the 'using' statement here on the MSDN website, after I posted, and before you did.  I like this idea so far......

Now I'm doing my reading on the try...catch...finally, which the MSDN site only calls try....finally.  Whoops.  Now I see a link to the try...catch...finally block on the MSDN.  I think I like both these methods.  Since I only code for myself, I think I would want to use the TCF way (right now), so that I can write the error message to the screen, and see what I did wrong, code or using wise.

A lot to learn.  Getting interresting though.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Custom dialog boxes examples?
« Reply #23 on: August 04, 2006, 07:05:54 PM »
Tim,
speaking of the using statement,
 have a look at this use for using as well ..
Quote
using System ;
using System.Text;
using Autodesk.AutoCAD.Runtime ;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;


namespace blablabla
{
  // .....
which allows this sort of thing
Quote
    Editor e = AcadApp.DocumentManager.MdiActiveDocument.Editor;
         using ( Transaction tr = e.Document.Database.TransactionManager.StartTransaction() )
         {
« Last Edit: August 04, 2006, 07:07:48 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Custom dialog boxes examples?
« Reply #24 on: August 04, 2006, 07:25:02 PM »
Tim,
speaking of the using statement,
 have a look at this use for using as well ..
Quote
using System ;
using System.Text;
using Autodesk.AutoCAD.Runtime ;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;


namespace blablabla
{
  // .....
which allows this sort of thing
Quote
    Editor e = AcadApp.DocumentManager.MdiActiveDocument.Editor;
         using ( Transaction tr = e.Document.Database.TransactionManager.StartTransaction() )
         {

Thanks Kerry.  I used that before, but didn't think I was going to need it for the this dialog routine.  It took me so long just to get this thing working, maybe 5 tries, that I just forgot it.  I like that style also.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Custom dialog boxes examples?
« Reply #25 on: August 04, 2006, 08:15:48 PM »
In regards to document locking, it's more of a recource management problem for the application. AutoCAD and windows have to work together to handle messages from devices such as the keyboard and by locking the document you're sort of saying 'stop everything, I'm doing something here' and AutoCAD will let you do your stuff without losing all your resources.
That's a simple explaination anyways :)
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

LE

  • Guest
Re: Custom dialog boxes examples?
« Reply #26 on: August 04, 2006, 08:54:21 PM »
Excuse my ignorance and confusion here;

Why the locking document is needed - ? -

Is this a wrap from the lockDocument method (ARX) - ? -

If it is, in all the code I have done in ARX, I only had needed to use in one solution (preview & inserting drawings) ie:

acDocManager->lockDocument(curDoc());
or
acDocManager->lockDocument(acDocManager->curDocument());

That I uploaded in the ARX forum here...

Hope that someone that knows could explain that... thanks!

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Custom dialog boxes examples?
« Reply #27 on: August 05, 2006, 04:43:50 AM »
.... Why the locking document is needed - ? -


Hi Luis ,

There is a real chance that the code behind the dialog will be modifying 'something' in the database. If this IS the case, then when the document is being accessed it must be locked first.
Personally, the overhead to lock the document irrespective doesn't seem wastefull .... perhaps not the most efficient, but safe.
« Last Edit: August 05, 2006, 04:46:42 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Custom dialog boxes examples?
« Reply #28 on: August 05, 2006, 02:57:14 PM »
In regards to document locking, it's more of a recource management problem for the application. AutoCAD and windows have to work together to handle messages from devices such as the keyboard and by locking the document you're sort of saying 'stop everything, I'm doing something here' and AutoCAD will let you do your stuff without losing all your resources.
That's a simple explaination anyways :)
Thanks Mick.  Simple is good right now, maybe later I will be able to understand the complex ones.

.... Why the locking document is needed - ? -


Hi Luis ,

There is a real chance that the code behind the dialog will be modifying 'something' in the database. If this IS the case, then when the document is being accessed it must be locked first.
Personally, the overhead to lock the document irrespective doesn't seem wastefull .... perhaps not the most efficient, but safe.
Thanks Kerry.  Is it correct to assume then, that you use LockDocument with each of your apps?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Custom dialog boxes examples?
« Reply #29 on: August 05, 2006, 05:36:44 PM »
Quote
... Is it correct to assume then, that you use LockDocument with each of your apps?

No.
This is my understanding, which may need confirmation, 'cause I'm not aware of all the ramifications :

If code executes in a document context, LockDocument is not required, 'cause AutoCAD locks the current document.
Otherwise, locking is required.

There is a distinction between the command session flags used with command registration which affect this.

I believe a context menu callback event runs code from outside the document, so if database changes are to be made, the 'user' is obliged to lock the document.

I believe the same applies when defining a COM interface which modifies the document or its objects.

I hope someone corrects me if my understanding is skewed.


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.