Reputation: 1457
I have TreeView
object and I need when a node
of treeview
is selected, form
is shown in definite location (properties of the node
), and when another node
is selected, the form
changes. When no node is selected, the form
disappear. Form
contains only ListView
object. I need something like properties window in visual studio.
The problem I have now:
Form
appear randomly, in wrong location, I need it to be shown in definite location in another form
.
After each mouse down event, appear a new form
, but I need there will be only one form
(or old disappear - new appear)
When no nodes are selected, the form
doesn't disappear.
How can I solve this problems, or maybe there is a better solution ?
Upvotes: 0
Views: 3373
Reputation: 32453
About After each mouse down event, appear a new form, but I need there will be only one form (or old disappear - new appear) My solution:
Add to Form class a static variable Form frm; Add to Form class a static function
//Create new form if not yet created
//Or return instance of opened form which can update by new parameters
public static Form Instance()
{
if (Form.frm = null)
Form.frm = new Form();
return Form.frm;
}
Then create all new forms only through this static function. Create overload functions for this static function if you want open different instances of Form.
And of course remember dispose static Form.frm object on closing form
Upvotes: 0
Reputation: 2111
Try these codes for showing your form :
private Form2 f2;
private void button1_Click(object sender, EventArgs e)
{
if (f2 == null) {
f2 = new Form2();
f2.FormClosed += delegate { f2 = null; };
f2.Show();
}
else {
f2.Activate();
}
}
Upvotes: 0
Reputation: 21034
What I think you are seeking is the PropertyGrid control.
http://msdn.microsoft.com/en-us/library/aa302326.aspx
It is a very deep and complex control, but can give amazing result.
Upvotes: 5