简体   繁体   English

如何使属性网格像按钮的上下文菜单?

[英]how to make a property grid like context menu for button?

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. 属性网格将是可见的,当单击其他位置时,将隐藏。

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 最好的主意可能是使用PropertyGrid控件显示选定的(单击的)对象属性: http : //msdn.microsoft.com/zh-cn/library/system.windows.forms.propertygrid.aspx

http://msdn.microsoft.com/en-us/library/aa302326.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 此控件中已实现了大多数“标准属性类型”的逻辑,例如String,Int ...

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...". 在所有Windows应用程序中,标准方法是:右键单击某个对象时,将获得该对象特定的上下文菜单,最后一项通常是“属性...”。 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. 如果要使用PropertyGrid控件显示上下文菜单,则不确定上下文菜单控件是否支持该菜单。 But one way to do it would be to make new form, "PropertyGridForm", with that PropertyGrid on it. 但是,一种方法是使用其上的PropertyGrid制作新表单“ PropertyGridForm”。 Then, on your Object.CellMouseDown event just show that form, something like this: 然后,在您的Object.CellMouseDown事件上,仅显示该表单,如下所示:

 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. 取决于您到底需要什么行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM