简体   繁体   English

如何在Visual Studio中制作类似属性窗口的表格?

[英]How to make a form like properties window in visual studio?

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. 我有TreeView对象,当选择treeview一个node ,需要在确定的位置(该node属性)中显示form ,而当选择另一个node时,则需要更改form When no node is selected, the form disappear. 当未选择任何节点时,该form消失。 Form contains only ListView object. Form仅包含ListView对象。 I need something like properties window in visual studio. 我需要类似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 . Form随机出现在错误的位置,我需要以另一种form在确定的位置显示它。

After each mouse down event, appear a new form , but I need there will be only one form (or old disappear - new appear) 在每次按下鼠标事件后,出现一个新form ,但是我需要只有一个form (或旧form消失-新出现)

When no nodes are selected, the form doesn't disappear. 如果未选择任何节点,则form不会消失。

How can I solve this problems, or maybe there is a better solution ? 我该如何解决这个问题,或者有更好的解决方案?

What I think you are seeking is the PropertyGrid control. 我认为您正在寻找的是PropertyGrid控件。

http://msdn.microsoft.com/en-us/library/aa302326.aspx http://msdn.microsoft.com/en-us/library/aa302326.aspx

It is a very deep and complex control, but can give amazing result. 这是一个非常深入和复杂的控件,但可以产生惊人的效果。

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; 向Form类添加一个静态变量Form frm; Add to Form class a static function 将静态函数添加到Form类

//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. 如果要打开Form的其他实例,请为此静态函数创建重载函数。

And of course remember dispose static Form.frm object on closing form 当然,请记住在关闭窗体上放置静态Form.frm对象

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();
    }
}

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

相关问题 属性窗口,如Silverlight中的Visual Studio - Properties window like visual studio in Silverlight 如何在Visual Studio的属性窗口中使类型可编辑? - How to make a type editable in properties window in visual studio? 列出对象属性,例如“ Visual Studio立即”窗口 - Listing object properties like the Visual Studio Immediate window 如何隐藏DataGridViewComboBoxColumn的下拉箭头,如Visual Studio Properties窗口? - How can I hide the drop-down arrow of a DataGridViewComboBoxColumn like Visual Studio Properties window? Visual Studio 2015属性窗口按钮不适用于Windows窗体 - Visual Studio 2015 properties window button not working for windows form 将类属性公开给Visual Studio属性窗口 - Expose Class properties to Visual Studio Properties window 如何在Visual Studio扩展的“属性窗口对象列表”中修改名称 - How to modify name in Properties Window Object List for Visual Studio extension 如何在Visual Studio 2015的属性窗口中更改字体大小单位? - How to change the font size unit in the properties window in Visual Studio 2015? 如何在另一个窗体(如Visual Studio)中显示窗体 - How to display a form inside another form like Visual Studio 如何枚举所有任务,如Visual Studio任务窗口 - How to enumerate all Tasks like Visual Studio Task window
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM