当前位置:编程文档 >> C# >> Treeview 拖动的下横线
首页

Treeview 拖动的下横线

所属类别:C#
推荐指数:★★☆
文档人气:5
本周人气:1
发布日期:2008-8-2

    对于treeview 节点的拖动网上有很多,不想再多写了。我把自己地址贴出来:http://www.chenjiliang.com/Article/View.aspx?ArticleID=1578&TypeID=79

我实现的效果:

   我想说的是拖动的下横线。

   最初的想法是通过拖动绘图的方法,这种方法可以实现,不过要刷新特别多。对于用gdi+绘图方法不知道

大家怎样处理让刷新减少一点的方法?请指教

  由于gid+绘图刷新的问题,我只好想到一些比较笨的方法,用一个label来实现一条细线的效果。

label 细线看起来不好看。自己绘图的个控件得了。下面是我绘图一个控件的主要代码(vb.net ):

view plaincopy to clipboardprint?
  1. Imports System.Drawing   
  2. Imports System.Drawing.Drawing2D   
  3. Imports System.Collections   
  4. Imports System.Collections.Generic   
  5. Imports System.ComponentModel   
  6. Imports System.Drawing.Imaging   
  7. Public Class SplitLine   
  8.     Sub New()   
  9.         ' 此调用是 Windows 窗体设计器所必需的。   
  10.         InitializeComponent()   
  11.   
  12.         ' 在 InitializeComponent() 调用之后添加任何初始化。   
  13.         SetStyle(ControlStyles.AllPaintingInWmPaint, True)   
  14.         SetStyle(ControlStyles.ResizeRedraw, True)   
  15.         SetStyle(ControlStyles.UserPaint, True)   
  16.         SetStyle(ControlStyles.OptimizedDoubleBuffer, True)   
  17.     End Sub  
  18.   
  19.     Dim _color As Color = Color.Red   
  20.      _   
  21.     Public Property MyColor() As Color   
  22.         Get  
  23.             Return _color   
  24.         End Get  
  25.         Set(ByVal value As Color)   
  26.             _color = value   
  27.         End Set  
  28.     End Property  
  29.   
  30.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)   
  31.         MyBase.OnPaint(e)   
  32.   
  33.         Dim br As New SolidBrush(MyColor)   
  34.         Dim g As Graphics = e.Graphics   
  35.         Dim path As New GraphicsPath   
  36.         Dim path1 As New GraphicsPath   
  37.         Dim path2 As New GraphicsPath   
  38.         path.AddLine(New Point(0, 0), New Point(0, 9))   
  39.         path.AddLine(New Point(0, 9), New Point(5, 5))   
  40.         path.AddLine(New Point(5, 5), New Point(0, 0))   
  41.         path.CloseAllFigures()   
  42.   
  43.         path1.AddLine(New Point(Me.Width - 5, 5), New Point(Me.Width, 0))   
  44.         path1.AddLine(New Point(Me.Width, 0), New Point(Me.Width, 9))   
  45.         path1.AddLine(New Point(Me.Width, 9), New Point(Me.Width - 5, 5))   
  46.         path1.CloseAllFigures()   
  47.   
  48.         path2.AddRectangle(New Rectangle(5, 5, Me.Width - 5, 1))   
  49.         path2.CloseAllFigures()   
  50.   
  51.         Dim pen As New Pen(Color.Black, 2)   
  52.         g.FillPath(br, path)   
  53.         g.FillPath(br, path1)   
  54.         g.FillPath(br, path2)   
  55.   
  56.         Dim re As New Region(path)   
  57.         re.Union(path2)   
  58.         re.Union(path1)   
  59.         Me.Region = re   
  60.     End Sub  
  61.   
  62. End Class  
view plaincopy to clipboardprint?
  1. 说明:这个控件继承control  

文档说明:

     

相关文档


读取评论列表……