且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将设计器支持添加到自定义树控件

更新时间:2023-10-02 19:24:40



嗨吉姆,


感谢您在社区中发帖!


根据我的理解,您想编写一个自定义的TreeView控件,

和你想为它添加一些设计时支持。也就是说,您希望选择TreeView中的

TreeNodes并从

属性浏览器中修改属性。


== ================================================ == ===

我认为这是一项非常复杂的工作,需要做很多工作。


在.Net Windows表单设计器中,TreeNode是容器在TreeView

控件中,它的设计时行为首先由TreeView

控件管理。所以为了得到你想要的东西,你应该首先为TreeView控件编写设计器。


TreeView控件实际上使用了一个INTERNAL

TreeViewControlDesigner(此名称为伪造)的设计时间

behaviro(不是默认的ControlDesigner)。因为这个设计师是内部的
,你必须为你的TreeView编写一个自定义的设计师。


下面的代码将允许你展开和折叠你的TreeView

控制。(这不是ControlDesigner类的默认行为)


[Designer(typeof(MyTreeViewDesigner))]

公共类MyTreeView:System.Windows.Forms.TreeView

{

}


公共类MyTreeViewDesigner:System.Windows。 Forms.Design.ControlDesigner

{

protected override bool GetHitTest(Point point)

{

return true;

}

}


此外,您必须为TreeNode类提供自定义设计器。

不幸的是,TreeNode不是*控件*(不继承自

System.Windows.Forms.Control),并且它没有实现IComponent

接口。所以你不能在它上面应用ControlDesigner(更详细,

ComponentDesigner)。


所以你必须为你的TreeNode实现IComponent接口,然后

用户root设计者将TreeNode添加到VS.net设计器。


直到现在,你会看到你需要做多少事情才能获得这样做了(我说的是什么

可能不是你应该做的全部工作,可能需要额外的工作)。我强烈建议您使用其他方式解决方法。


我认为您可以将CollectionEditor用于TreeView的Nodes属性。并且

在编辑器中修改TreeNode的属性。


================== ================================ =========

请应用我的建议,让我知道它是否有助于解决你的问题。


感谢您的耐心和合作。如果您有任何疑问或

担忧,请随时将其发布在小组中。我正准备等待

的帮助。

祝你有美好的一天!!


祝你好运,

Jeffrey Tan

Microsoft在线合作伙伴支持

安全! - www.microsoft.com/security

此帖子按原样提供没有保证,也没有授予任何权利。


Hi Jim,

Thank you for posting in the community!

Based on my understanding, you want to write a customized TreeView control,
and you want to add some design-time support for it. That is, you want the
TreeNodes in the TreeView to be selected and modify properties from
Property Browser.

================================================== =====
I think this is a much complex work, and need a lots work to do.

In .Net Windows Form designer, TreeNode is container in the TreeView
control, and it design-time behavior is first be managed by the TreeView
control. So to get what you want, you should first write the designer for
the TreeView control.

The TreeView control actually use an INTERNAL
"TreeViewControlDesigner"(This name is bogus) for its design-time
behaviro(Not the default ControlDesigner). Because this designer is
internal, you must write a customized designer for your TreeView.

The code below will allow you to expand and collapse your TreeView
control.(This is not allowed for ControlDesigner class''s default behaviro)

[Designer(typeof(MyTreeViewDesigner))]
public class MyTreeView : System.Windows.Forms.TreeView
{
}

public class MyTreeViewDesigner: System.Windows.Forms.Design.ControlDesigner
{
protected override bool GetHitTest(Point point)
{
return true;
}
}

And also, you must provide your customized designer for the TreeNode class.
Unfortunately, TreeNode is not a *control*(Does not inherited from
System.Windows.Forms.Control), and it does not implement IComponent
interface. So you can not apply ControlDesigner(More detailed,
ComponentDesigner) on it.

So you must implement the IComponent interface for the your TreeNode, then
user root designer''s to add the TreeNode to the VS.net designer.

Till now, you will see how many thing you need to do to get this done(What
I stated may be not the whole work you should do, extra work may need). I
strongly recommanded that you use other way to workaround.

I think you may use CollectionEditor for TreeView''s Nodes property. And
modify the TreeNode''s property in the Editor.

================================================== =========
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.




嗨Jim,


非常感谢您的反馈。


我已经审核了您的帖子,我将花一些时间审阅文章。


我会回复研究结束后你很快。


感谢你的理解。


祝你好运,

Jeffrey Tan >
Microsoft在线合作伙伴支持

获取安全保障! - www.microsoft.com/security

此帖子按原样提供没有保证,也没有授予任何权利。


Hi Jim,

Thanks very much for your feedback.

I have reviewed your post, I will spend sometime in review that articles.

I will reply to you ASAP after research.

Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.




嗨Jim,


在第一次快速浏览文章后,我发现它的一些

功能是运行时属性编辑。


你想编辑你的treenode在运行时或设计时?


如果你想在运行时完成这项工作,你只需要使用PropertyGrid

控制你的表格。


有关如何在WinForm应用程序中使用Property Grid的文章,

请参考:
http://msdn.microsoft.com/ library / de ... us / dndotnet / ht

ml / usingpropgrid.asp


如果您需要运行时功能,请随意向我反馈


祝你好运,

Jeffrey Tan

微软在线合作伙伴支持

获取安全! - www.microsoft.com/security

此帖子按原样提供没有保证,也没有赋予任何权利。


Hi Jim,

After quick reviewing the article for the first time, I found some of its
features are the run-time property editing.

Do you want to edit your treenode at run-time or design-time?

If you want to get this done at run-time, you only need to use PropertyGrid
control on your Form.

For an article about how to use Property Grid in your WinForm application,
please refer to:
http://msdn.microsoft.com/library/de...us/dndotnet/ht
ml/usingpropgrid.asp

If you need the runtime feature, please feel free to feedback to me

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.