how to make a property grid like context menu for button ? So when right click on button . property grid will be visible and when click some where else , that will hide.
Hi,
the best idea is probably to use PropertyGrid control to show selected (clicked) object properties: http://msdn.microsoft.com/en-us/library/system.windows.forms.propertygrid.aspx
http://msdn.microsoft.com/en-us/library/aa302326.aspx
Most of the logic for "standard property types" like String, Int... is already implemented in this control
But I would not show it immediately on right click. Standard way in all windows apps is, when you make right click on a object, you get context menu specific for that object, and the last item is usually "Properties...". After you select that option the property grid will be displayed.
If you want to display context menu with PropertyGrid control, I am not sure that it is supported with context menu control. But one way to do it would be to make new form, "PropertyGridForm", with that PropertyGrid on it. Then, on your Object.CellMouseDown event just show that form, something like this:
private void Button1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
PropertyGridForm f = new PropertyGridForm();
f.PropertyGrid.SelectedObject = Button1; // (or sender?) whatever you need
f.Location = e.Location;
f.Show(); //or ShowDialog?
}
}
You will have to find the best way to close that form. Will you make Close button on it, close it on Leave event, Deactivate event? Depends what behavior exactly you need.