Game Development Reference
In-Depth Information
++elementNum;
}
}
catch (Exception e)
{
MessageBox.Show(
“
Error in ComponentName
”
+ componentName +
“
\n
”
);
}
return lineNum;
}
The idea behind adding a dynamic control and attaching it to code that runs when it
changes is pretty similar, no matter what type of data you are editing. Let
'
s take a
look at the code needed to select a file:
public void AddFileElement(XmlNode actorValues, string xpath, int lineNum)
{
const int boxWidth = 160;
const int horizSpacing = 20;
TextBox textBox = new TextBox();
Drawing.Point location = new Drawing.Point(
g_LabelColumnWidth, lineNum * m_LineSpacing);
textBox.Name = xpath;
textBox.Location = location;
textBox.Text = actorValues.FirstChild.Value;
textBox.TextChanged += new EventHandler(FileElementChanged);
m_Panel.Controls.Add(textBox);
Button button = new Button();
location = new Drawing.Point(
g_LabelColumnWidth + boxWidth + horizSpacing, lineNum * m_LineSpacing);
button.Name = xpath + “Button”;
button.Text = “Browse…”;
button.Location = location;
button.MouseClick += new MouseEventHandler(SelectFile);
m_Panel.Controls.Add(button);
}
A text box is created with the value set to the value stored in
actorValues.FirstChild.Value
. Since file elements are defined in XML like
this,
<Texture>art\grid.dds</Texture>
,
the
first
child
is
the
text
“
The name of the text box is the XPath of the element in the XML.
Because there may be multiple text boxes created, this is a convenient way to
art.grid.dds.
”