我爱电脑技术论坛's Archiver

小迷糊 发表于 2008-6-11 02:12

C#怎样在RowHeader显示字符串和图标

private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) @j0[&u0Q/Q!c Q|x?
{    jQ(R8^ X*^x%z flk

])Yp@v7K%K if (e.RowIndex >= 0 && e.ColumnIndex == -1)
JPHD._ { @kj_4Y w Tk
Rectangle newRect = new Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Height, e.CellBounds.Height);
L)WZI ~-fH9s,n //新建一个图标
H%BMl%{5_+`M System.Drawing.Icon ico = new Icon("F:\\xx.ico");"K,T F8\.A }5O&{9k
using (Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor),
:\\Za HiY backColorBrush = new SolidBrush(e.CellStyle.BackColor))[OV$t4D?1w
{b]*W6K0h?t
using (Pen gridLinePen = new Pen(gridBrush,2)) aIu(nw-b_
        {}$tG)S"P lyI1w
            // Erase the cell.rBR5I,|.YMy
            e.Graphics.FillRectangle(backColorBrush, e.CellBounds);         
rK%O I*{*Og"w?
;b{4V3vX&pmZ             //划线EH)E1L2P
            Point p1 = new Point(e.CellBounds.Left+e.CellBounds.Width, e.CellBounds.Top);
'Wt@;ZNw$f             Point p2 = new Point(e.CellBounds.Left+e.CellBounds.Width, e.CellBounds.Top+e.CellBounds.Height);
5x0}d-b{Y0q$AV             Point p3 = new Point(e.CellBounds.Left,e.CellBounds.Top+ e.CellBounds.Height);!Re&Au"x$v
            Point[] ps = new Point[]{p1,p2,p3};
3j1O5K;VR1["~             e.Graphics.DrawLines(gridLinePen,ps);4{c5f2o3K[;o
,a$d[ z$XR
            //画图标
-q [H7XR m8{             e.Graphics.DrawIcon(ico, newRect);
.X|d3uG\G             //画字符串b6P8E@1\;N5O
            e.Graphics.DrawString("123", e.CellStyle.Font, Brushes.Crimson, e.CellBounds.Left + 20, e.CellBounds.Top, StringFormat.GenericDefault);
-~/j4f7S XZ3t:_~             e.Handled = true;
BF)l2w"TDZw           }
Fq @:\ G D,c       }-Ii#W H3D{ f)m
}P1b [ey `?F0O[
}

页: [1]
   

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.