When I click on any control in my form or usercontrol then propertygrid shows but it repeats for each control on to the form. How can I show only once for each control click
public void Selectpropertygrid()
{
foreach (Control c in dock_Control1.Controls)
{
c.MouseClick+=new MouseEventHandler(c_MouseClick);
}
foreach (Control ctr in this.Controls)
{
ctr.MouseClick += new MouseEventHandler(c_MouseClick);
}
}
public void c_MouseClick(object sender, MouseEventArgs e)
{
Control ct=sender as Control;
prp = new PropertyGrid();
prp.CommandsVisibleIfAvailable = true;
prp.Location = new Point(0, 0);
prp.Size = new Size(220 ,800);
prp.Enabled = true;
prp.Visible = true;
prp.Text = "Properties";
prp.Dock = DockStyle.Left;
prp.Enabled = true;
this.Controls.Add(prp);
prp.SelectedObject = ct;
}
It is quite likely that you’ve got multiple event subscriptions to the
c_MouseClickevent handler. It is preferable, if not advisable to remove any event handler before adding the desired one.Try modifying your code to something like this and see if it is fixed.