The problem you're having is that your command
method is non-static.
This is no good, because the runtme is going
to create an instance of the containing/declaring
class (e..g, the UserControl that you add to the
palette) to invoke the command method on.
IOW, the command method is not being invoked
on the instance of your control on the palette, it
is being invoked on a different instance of that
control, that was created by the runtime the first
time you execute the command in the current
document.
One solution:
1. Add a static variable to your TestControl class:
private static TestControl ThisControl = null;
2. In your TestControl's c'tor, initialize the static
variable (assign it to the 'this' pointer):
public TestControl()
{
InitializeComponent();
ThisControl = this;
}
3. Delcare your command method as static,
and in place of 'this', use 'ThisControl':
[CommandMethod("CommandName")]
public static void aRountine()
{
ThisControl.textBox1.Text = "abc";
}
Note that this will only work if your UserControl
is a singleton (e.g., there is only one instance of
it created).
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
wrote in message news:5316454@discussion.autodesk.com...
There are three controls on a docking pallette, one "Textbox" and tow "Button". Button2 change the TextBox's text directly, it works, Button1 do it by execute a AutoCAD command, it doesn't works. Why?
As if the rountine register to AutoCAD Command is annother thread...Is there a way to get data form routine which is registered to AutoCAD Command? I need it to interact with the dockingpallette.
Below is the code and the source file is in the attachment.:
//Button1 c
an not change the Textbox, but Button2 do, why? Please help.
private void button1_Click(object sender, EventArgs e)
{
AcadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("CommandName\n", true, false, false);
}
[Autodesk.AutoCAD.Runtime.CommandMethod("CommandName")]
public void aRountine()
{
// Notice, it can not change the TextBox1
this.textBox1.Text = "abc";
MessageBox.Show("
this.textBox1.Text is: " + this.textBox1.Text,"Click form Button1");
}
private void button2_Click(object sender, EventArgs e)
{
this.textBox1.Text = "abc";
MessageBox.Show("this.textBox1.Text is: " + this.textBox1.Text, "Click form Button2");
}
}
Thanks for any help.