首页 技术 正文
技术 2022年11月16日
0 收藏 408 点赞 4,919 浏览 1743 个字

DevExpress的TreeList默认是没有树状线的,修改TreeLineStyle属性无效,这对于Tree并不好看。

DevExpress中TreeList树样式调整

解决方案一

官方解释说对于DevExpress的标准主题是不支持TreeList有TreeLine的(不是技术问题,是设计理念不同),如DevExpress Style, DevExpress Dark Style、Office 2013、Office 2010, Visual Studio 2013, VS2010, Seven Classic等,默认如下:

DevExpress中TreeList树样式调整

而主题皮肤和其他皮肤是支持的。所以使用非标准皮肤就可以实现TreeLine的支持

DevExpress中TreeList树样式调整

关于三类皮肤的划分如下:

DevExpress中TreeList树样式调整

解决方案二

很多时候,我们都会使用标准皮肤,只有使用代码强制这个属性,修改代码如下:

Skin skin = GridSkins.GetSkin(treeList1.LookAndFeel);
skin.Properties[GridSkins.OptShowTreeLine] = true;

效果如下:

DevExpress中TreeList树样式调整

虽然是实现了,但看起来还是怪怪的,领导还想要自行车。

最新款自动车

DevExpress中TreeList树样式调整

DevExpress中TreeList树样式调整

由于标准皮肤不支持+/-号(plus/minus),所以官方给出的解决方案:一是使用其他非标准皮肤,二是自定义绘制节点按键事件(CustomDrawNodeButton),代码如下:

private void TreeList1_CustomDrawNodeButton(object sender, CustomDrawNodeButtonEventArgs e)
{
//1、矩形
Rectangle rect = Rectangle.Inflate(e.Bounds, 0, -2);
//矩形背景
Brush backBrush = e.Cache.GetGradientBrush(rect, BackColor, BackColor, LinearGradientMode.ForwardDiagonal);
e.Cache.FillRectangle(backBrush, rect);
//矩形边框
Pen pen = e.Cache.GetPen(Color.Gray);
//pen.DashStyle = DashStyle.Dot;
e.Cache.DrawRectangle(pen, rect);
//2、显示的文字
string displayCharacter = e.Expanded ? "-" : "+";
//文字格式
StringFormat outCharacterFormat = e.Appearance.GetStringFormat();
outCharacterFormat.Alignment = StringAlignment.Center;
outCharacterFormat.LineAlignment = StringAlignment.Center; //绘制文字
e.Appearance.FontSizeDelta = -2;
e.Appearance.FontStyleDelta = FontStyle.Bold;
e.Cache.DrawString(displayCharacter, e.Appearance.Font,e.Cache.GetSolidBrush(ForeColor), rect, outCharacterFormat); //禁止默认绘画
e.Handled = true;
}

参考

https://www.devexpress.com/Support/Center/Question/Details/Q380748/force-treelines-on-treelist

https://blog.csdn.net/u010613052/article/details/79752671

https://documentation.devexpress.com/WindowsForms/DevExpress.XtraTreeList.TreeList.CustomDrawNodeButton.event

https://www.devexpress.com/Support/Center/Question/Details/T238989/how-to-change-an-expand-button-image

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,401
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,813
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,896