彩票走势图

用户界面套包DotNetBar for WinForms使用教程:如何在显示行号?

翻译|使用教程|编辑:鲍佳佳|2020-08-19 14:26:25.890|阅读 435 次

概述:DotNetBar for WinForms是一个拥有89个组件的用户界面控件套包,本文讲述了如何在DotNetBar for WinForms AdvTree控件中显示行号,以及如何用代码实现在AdvTree的左边距中添加显示行号。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

DotNetBar for WinForms是一个拥有89个组件的用户界面控件套包,用户可以使用Visual Studio 2005-2015轻松地创建专业的用户界面。十多年来DotNetBar帮助开发人员轻松地创建易用的专业Windows Forms (WinForms) 用户界面。DotNetBar是全世界第一个引入全功能Office 2013、Office 2010、Windows 7、 Office 2007 style Ribbon控件以及Visual Studio 2005-2013,Metro等主题风格和样式的控件。

点击下载DotNetBar for WinForms最新试用版

如何在WinForms AdvTree控件的DotNetBar中显示行号

仅使用几行代码,就有可能在AdvTree的左边距中呈现任何内容,本文将说明如何添加行号。

向控件集advTree添加边距。BackgroundStyle.PaddingLeft = 24 property。在此示例中,它将设置为24像素。处理advTree.Render和advTree.GetRenderer()。RenderNodeBackground事件以渲染左边距背景和行号。您可以将此代码放置在表单加载事件中:

advTree1.Render + =new AdvTreeRenderEventHandler(AdvTreeRender);
advTree1.GetRenderer()。RenderNodeBackground + =new NodeRendererEventHandler(TreeRenderNodeBackground);

void TreeRenderNodeBackground(object sender, DevComponents.AdvTree.Display.NodeRendererEventArgs e)
{
    Graphics g = e.Graphics;
    Node n = e.Node;
    Rectangle r = e.NodeBounds;
    Rectangle numberBounds = new Rectangle(4, r.Y, advTree1.BackgroundStyle.PaddingLeft - 4, r.Height);
 
    Region oldClip = g.Clip;
 
    int i = advTree1.GetNodeFlatIndex(n);
    Rectangle lineNumberBounds = advTree1.ClientRectangle;
    lineNumberBounds.X += 1; // Border
    lineNumberBounds.Width = advTree1.BackgroundStyle.PaddingLeft - 1;
    lineNumberBounds.Y = advTree1.Columns.Bounds.Bottom;
    lineNumberBounds.Height = lineNumberBounds.Height - advTree1.Columns.Bounds.Bottom;
    if (advTree1.HScrollBar != null && advTree1.HScrollBar.Visible)
        lineNumberBounds.Height -= advTree1.HScrollBar.Height;
    g.SetClip(lineNumberBounds);
    g.SetClip(numberBounds, System.Drawing.Drawing2D.CombineMode.Intersect);
    g.DrawString(i.ToString(), advTree1.Font, Brushes.Red, numberBounds.Location);
 
    g.Clip = oldClip;
}
 
void AdvTreeRender(object sender, AdvTreeRenderEventArgs e)
{
    if (e.RenderType == eAdvTreeRenderType.Background)
    {
        AdvTree tree = (AdvTree)sender;
        Graphics g = e.Graphics;
        Region oldClip = g.Clip;
        g.ResetClip();
        g.FillRectangle(Brushes.WhiteSmoke, new Rectangle(0, 0, 24, tree.Height));
        g.Clip = oldClip;
    }
}

慧都高端UI界面开发

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@cahobeh.cn

文章转载自:

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP