첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

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
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요