如何更改 Telerik winform Treeview 上的展开/折叠图标?

发布于 2024-11-23 15:29:22 字数 324 浏览 4 评论 0原文

我正在尝试自定义 Telerik Winform TreeView 控件上的展开/折叠图标。

如果我使用 PropertyBuilder 填充 TreeView 控件,我可以看到 Telerik.WinControls.UI.ExpandCollapseElements,我可以修改它来更改展开/折叠图标。不过我想动态地填充我的树。

我已经检查过修改主题,但在 Visual Style Builder 中的任何地方都没有看到 ExpandCollapseElements,也没有看到任何在对象模型的 RadTreeView 端修改这些图标的方法。

屏幕截图说可以做到,但是我缺少什么?

I'm trying to customise the expand/collapse icon on a Telerik Winform TreeView control.

If I populate a TreeView control with the PropertyBuilder, I can see Telerik.WinControls.UI.ExpandCollapseElements which I can modify to change the expand/collapse icons. However I want to populate my tree dynamically.

I have examined modifying the theme but I don't see ExpandCollapseElements anywhere in Visual Style Builder, nor do I see any way to modify these icons at the RadTreeView end of the object model.

Screenshots say it can be done, but what am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

断爱 2024-11-30 15:29:22

您可以在创建节点时直接设置展开/折叠图标。例如:

Image imageToUseForExpand   = /* get this image from somewhere */;
Image imageToUseForCollapse = /* get this image from somewhere */;

RadTreeNode item = new RadTreeNode("Node with custom icons");

//NOTE: You need to add the node to the treeview before working
//      with the TreeViewElement property (otherwise it will be null)
radTreeView1.Nodes.Add(item);

//Set the expand and collapse images to whatever you want
item.TreeViewElement.ExpandImage = imageToUseForExpand;
item.TreeViewElement.CollapseImage = imageToUseForCollapse;

或者,如果您想更通用地进行格式化(不需要每次创建节点时都指定图像),您可以像这样处理 NodeFormatting 事件:

//Either register the even in code (like this) or via the Designer
radTreeView1.NodeFormatting += radTreeView1_NodeFormatting;

//Then in the event handler, set the appropriate image
private void radTreeView1_NodeFormatting(object sender, 
                                         TreeNodeFormattingEventArgs e)
{
    //See whether the node is currently expanded and set the image accordingly
    if (e.Node.Expanded)
        e.NodeElement.ExpanderElement.SignImage = imageToUseForExpand;
    else
        e.NodeElement.ExpanderElement.SignImage = imageToUseForCollapse;
}

注意:我相信 NodeFormatting 事件是相对较新,因此您需要最新版本的 Telerik 才能使用它。如果您在使用此代码时遇到问题,请确保您运行的是最新版本的控件。

You can set the expand/collapse icons directly when you are creating the nodes. For example:

Image imageToUseForExpand   = /* get this image from somewhere */;
Image imageToUseForCollapse = /* get this image from somewhere */;

RadTreeNode item = new RadTreeNode("Node with custom icons");

//NOTE: You need to add the node to the treeview before working
//      with the TreeViewElement property (otherwise it will be null)
radTreeView1.Nodes.Add(item);

//Set the expand and collapse images to whatever you want
item.TreeViewElement.ExpandImage = imageToUseForExpand;
item.TreeViewElement.CollapseImage = imageToUseForCollapse;

Or if you would like to do the formatting more generically (where you don't need to specify the images every time you create a node), you could handle the NodeFormatting event like this:

//Either register the even in code (like this) or via the Designer
radTreeView1.NodeFormatting += radTreeView1_NodeFormatting;

//Then in the event handler, set the appropriate image
private void radTreeView1_NodeFormatting(object sender, 
                                         TreeNodeFormattingEventArgs e)
{
    //See whether the node is currently expanded and set the image accordingly
    if (e.Node.Expanded)
        e.NodeElement.ExpanderElement.SignImage = imageToUseForExpand;
    else
        e.NodeElement.ExpanderElement.SignImage = imageToUseForCollapse;
}

Note: I believe the NodeFormatting event is relatively new so you'll need a recent version of Telerik to use it. If you have trouble with this code, make sure you're running the latest version of the controls.

紫瑟鸿黎 2024-11-30 15:29:22

要全局更改展开和折叠图像,请执行以下操作:

Image imageToUseForExpand   = /* get this image from somewhere */;
Image imageToUseForCollapse = /* get this image from somewhere */;

radTreeView1.TreeViewElement.ExpandImage = imageToUseForExpand;
radTreeView1.TreeViewElement.CollapseImage = imageToUseForCollapse;

To globally change the expand and collapse images then do the following:

Image imageToUseForExpand   = /* get this image from somewhere */;
Image imageToUseForCollapse = /* get this image from somewhere */;

radTreeView1.TreeViewElement.ExpandImage = imageToUseForExpand;
radTreeView1.TreeViewElement.CollapseImage = imageToUseForCollapse;
爱你不解释 2024-11-30 15:29:22

我最终将我使用的主题保存为 XML,手动编辑该主题的 XML,重新导入 XML 并将其另存为 .tssp。我很幸运,我想要的图像是另一个主题的一部分。

这种方法可能最适合我的情况,因为我们需要主题支持才能使事情在我们支持的所有平台上看起来都很好。

建议的其他方法看起来不错;我还没有尝试过其中任何一个。

I ended up saving the theme I was using as XML, hand editing the XML for that theme, reimporting the XML and saving it as .tssp. I was fortunate that the image I wanted was part of another theme.

This approach probably works best in my situation because we will need theme support to make things look good in all the platforms we support.

The other approaches suggested look good; I haven't tried any of them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文