■ TreeList 클래스에서 커스텀 그리기 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
using System.Drawing; using System.Drawing.Drawing2D; using DevExpress.XtraTreeList; ... private TreeList treeList; ... this.treeList.CustomDrawColumnHeader += treeList_CustomDrawColumnHeader; this.treeList.CustomDrawNodeIndicator += treeList_CustomDrawNodeIndicator; this.treeList.CustomDrawFooter += treeList_CustomDrawFooter; this.treeList.CustomDrawFooterCell += treeList_CustomDrawFooterCell; ... #region 트리 리스트 컬럼 헤더 커스텀 그리기 - treeList_CustomDrawColumnHeader(sender, e) /// <summary> /// 트리 리스트 컬럼 헤더 커스텀 그리기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void treeList_CustomDrawColumnHeader(object sender, CustomDrawColumnHeaderEventArgs e) { if(e.Pressed) { paintSunkenBackground(e.Graphics, e.Bounds); } else { PaintRaisedBackground(e.Graphics, e.Bounds); } if(e.ColumnType == HitInfoType.Column) { PaintText(e.Graphics, e.Bounds, e.Column.GetCaption(), StringAlignment.Near); } e.Handled = true; } #endregion #region 트리 리스트 노드 지시자 커스텀 그리기 - treeList_CustomDrawNodeIndicator(sender, e) /// <summary> /// 트리 리스트 노드 지시자 커스텀 그리기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void treeList_CustomDrawNodeIndicator(object sender, CustomDrawNodeIndicatorEventArgs e) { PaintRaisedBackground(e.Graphics, e.Bounds); e.Handled = true; } #endregion #region 트리 리스트 꼬리말 커스텀 그리기 - treeList_CustomDrawFooter(sender, e) /// <summary> /// 트리 리스트 꼬리말 커스텀 그리기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void treeList_CustomDrawFooter(object sender, CustomDrawEventArgs e) { PaintRaisedBackground(e.Graphics, e.Bounds); e.Handled = true; } #endregion #region 트리 리스트 꼬리말 셀 커스텀 그리기 - treeList_CustomDrawFooterCell(sender, e) /// <summary> /// 트리 리스트 꼬리말 셀 커스텀 그리기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void treeList_CustomDrawFooterCell(object sender, CustomDrawFooterCellEventArgs e) { if(e.Text == string.Empty) { return; } paintSunkenBackground(e.Graphics, e.Bounds); PaintText(e.Graphics, e.Bounds, e.Text, StringAlignment.Far); e.Handled = true; } #endregion #region 양각 배경 칠하기 - PaintRaisedBackground(graphics, boundsRectangle) /// <summary> /// 양각 배경 칠하기 /// </summary> /// <param name="graphics">그래픽스</param> /// <param name="boundsRectangle">테두리 사각형</param> private void PaintRaisedBackground(Graphics graphics, Rectangle boundsRectangle) { LinearGradientBrush linearGradientBrush = new LinearGradientBrush ( boundsRectangle, Color.Yellow, Color.Gold, LinearGradientMode.Vertical ); graphics.FillRectangle(linearGradientBrush, boundsRectangle); ControlPaint.DrawBorder3D(graphics, boundsRectangle, Border3DStyle.RaisedInner); } #endregion #region 음각 배경 칠하기 - paintSunkenBackground(graphics, boundsRectangle) /// <summary> /// 음각 배경 칠하기 /// </summary> /// <param name="graphics">그래픽스</param> /// <param name="boundsRectangle">테두리 사각형</param> private void paintSunkenBackground(Graphics graphics, Rectangle boundsRectangle) { LinearGradientBrush linearGradientBrush = new LinearGradientBrush ( boundsRectangle, Color.CornflowerBlue, Color.LightGray, LinearGradientMode.Vertical ); graphics.FillRectangle(linearGradientBrush, boundsRectangle); ControlPaint.DrawBorder3D(graphics, boundsRectangle, Border3DStyle.SunkenOuter); } #endregion #region 텍스트 칠하기 - PaintText(graphics, boundsRectangle, text, stringAlignment) /// <summary> /// 텍스트 칠하기 /// </summary> /// <param name="graphics">그래픽스</param> /// <param name="boundsRectangle">테두리 사각형</param> /// <param name="text">텍스트</param> /// <param name="stringAlignment">문자열 정렬</param> private void PaintText(Graphics graphics, Rectangle boundsRectangle, string text, StringAlignment stringAlignment) { SolidBrush solidBrush = new SolidBrush(Color.Black); StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = stringAlignment; stringFormat.LineAlignment = StringAlignment.Center; stringFormat.FormatFlags = StringFormatFlags.NoWrap; stringFormat.Trimming = StringTrimming.EllipsisCharacter; graphics.DrawString(text, new Font("Verdana", 8), solidBrush, boundsRectangle, stringFormat); } #endregion |