algorithmic modeling for Rhino
Hi Everyone,
I want to have a situation where component 1 is linked to component 2 so that when the name of the component 1 is changed, the name of component 2 will update.
However, unfortunately I can't find a clean hook to do this, I tried overriding the default textbox on each GH component where the name can be set, with the code below which will call my own event for the name change.
However unforunately I can't add my custom ToolStripTextBox to the AppendMenuItems.
Any ideas? Thanks!
public override bool AppendMenuItems(System.Windows.Forms.ToolStripDropDown menu)
{
ToolStripTextBox toolStripTextBox = new ToolStripTextBox(this.NickName);
toolStripTextBox.TextChanged += new EventHandler(NameChanged);
ToolStripMenuItem toolStripMenuItemName = GH_DocumentObject.Menu_AppendItem()
// Custom event which is called when the name is changed and the other component's name will be updated:
private void NameChanged(object sender, EventArgs e)
{
ToolStripTextBox textBox = (ToolStripTextBox)sender;
this.NickName = textBox.Text;
this.linkedCheckList.NickName = textBox.Text;
}
Tags:
You can do like this.
public override bool AppendMenuItems(System.Windows.Forms.ToolStripDropDown menu)
{
GH_DocumenObject.Menu_AppendTextItem(menu, this.NickName,new GH_MenuTextBox.KeyDownEventHandler(NameChanged), null, true);
}
private void NameChanged(GH_MenuTextBox sender, KeyEventArgs e)
{
Keys keyCode = e.KeyCode;
if (keyCode == System.Windows.Forms.Keys.Return)
{
ToolStripTextBox textBox = (ToolStripTextBox)sender;
this.NickName = textBox.Text;
this.linkedCheckList.NickName = textBox.Text;
}
else if (keyCode == Keys.Escape || keyCode == Keys.Cancel)
{
}
}
Panda,
As always many thanks! Unfortunately at the line:
ToolStripTextBox textBox = (ToolStripTextBox)sender;
It is telling me that GH_MenuTextBox cannot be converted to toolStripTextbox, did you build a cast for GH_MenuTextBox? I am going to try doing this
Sorry,it my fault!Just like this,
if (keyCode == System.Windows.Forms.Keys.Return)
{
this.NickName = sender.Text;
this.linkedCheckList.NickName = sender.Text;
}
The commit and cancel changes tabs are parts of GH_MenuTextBox.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by