将设计器支持添加到自定义树控件 [英] Adding designer support to a custom tree control

查看:64
本文介绍了将设计器支持添加到自定义树控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿所有......我也在vs.net ide组中发布了这个,但人们没有回答,所以我认为这可能更合适。我不确定我是否正确地为我的代码添加了一名设计师。我只是将它添加到树节点,然后将每个自定义树节点添加到普通树控件中


我正在尝试使用加载项进行交互与VS.Net中的属性窗口。基本上,我创建了一个包含自定义树控件的工具窗口。当用户单击树节点时,我希望某些属性显示在属性窗口中。我的理解是我需要为组件创建一个设计器,并覆盖prefilterproperties方法。现在的问题是,当我使用点击一个节点时,我没有得到属性窗口的更新。我是否需要挂钩事件以通知属性窗口单击树节点?关于这方面的文档似乎有点稀疏,所以任何帮助都会非常感激。


另外,我看过这篇文章: http://www.msdn.microsoft.com /librar...dsgnrdotnet.as


感谢


Ji


以下是我已经拥有的一些片段


[Designer(typeof(MyTreeNodeDesigner))]

公共类MyTreeNode:TreeNod


private XmlNode _xmlNode

private string _type = String.Empty


///< summary

/ //代表这个My objec的xml片段

///< / summary

public XmlNode XmlNod


get { return this._xmlNode;

set {this._xmlNode = value;

///< summary

///表示<见cref =" IMyObject" />类型为nam

///< / summary

public string Typ


get {return this._type;

set {this._type = value;

public MyTreeNode(string nodeName


this.Text = nodeName

public MyTreeNode(string nodeName,string name


this.Text = nodeName +" - ''" + name +"''"

>
公共类MyTreeNodeDesigner:System.Windows.Forms.Design.ControlDesigne


bool lock


private bool已锁定


获得


返回锁定


设定


已锁定=值;


public MyTreeNodeDesigner(


protected override void PreFilterProperties(IDictionary properties


base .PreFilterProperties(属性)

properties [" Locked"] = TypeDescriptor.CreateProperty

typeof(MyTreeNode),

" ;锁定,

typeof(bo ol),new Attribute [0])

Hey all... I posted this in the vs.net ide group too, but people are not answering, so I figured that it might be more appropriate here. I''m not sure if I''m adding a designer to my code properly. I''m only adding it to the tree node, where each custom tree node is then added to a normal tree control

I''m trying to get an add-in to interact with the property window in VS.Net. Basically, I created a tool window containing a custom tree control. When the user clicks on a tree node, I want certain properties to show up in the property window. My understanding is that I need to create a designer for the component, and override the prefilterproperties method. The problem right now is that when I use clicks a node, I get no update to the property window. Do I need to hook an event to notify the property window that the tree node was clicked? Documentation on this seems sort of sparse, so any help would greatly be appreciated.

Also, I''ve seen this article: http://www.msdn.microsoft.com/librar...dsgnrdotnet.as

Thank

Ji

Here are some snippets of what I already have

[Designer(typeof(MyTreeNodeDesigner))]
public class MyTreeNode : TreeNod

private XmlNode _xmlNode
private string _type = String.Empty

/// <summary
/// Represents the xml fragment for this My objec
/// </summary
public XmlNode XmlNod

get { return this._xmlNode;
set { this._xmlNode = value;
/// <summary
/// Represents the <see cref="IMyObject"/> type nam
/// </summary
public string Typ

get { return this._type;
set { this._type = value;
public MyTreeNode(string nodeName

this.Text = nodeName
public MyTreeNode(string nodeName, string name

this.Text = nodeName + " - ''" + name + "''"

public class MyTreeNodeDesigner : System.Windows.Forms.Design.ControlDesigne

bool locked

private bool Locked

get

return locked

set

locked = value;

public MyTreeNodeDesigner(

protected override void PreFilterProperties(IDictionary properties

base.PreFilterProperties(properties)

properties["Locked"] = TypeDescriptor.CreateProperty
typeof(MyTreeNode),
"Locked",
typeof(bool), new Attribute[0])

推荐答案



嗨吉姆,


感谢您在社区中发帖!


根据我的理解,您想编写一个自定义的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.


这篇关于将设计器支持添加到自定义树控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆