回复 6楼March的帖子
看了你的代码,是你DrawString画的位置问题。
有关OwerDrawCell事件的用法,我这里有个代码片段和效果供你参考:
- private void c1FlexGrid1_OwnerDrawCell(object sender, C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e)
- <pre>{
- //Verify Row/Col index
- if (e.Col == 1 && e.Row == 1)
- {
- //Let the grid draw the BackGround and Border of the cell
- e.DrawCell(C1.Win.C1FlexGrid.DrawCellFlags.Background | C1.Win.C1FlexGrid.DrawCellFlags.Border);
-
- if (!(string.IsNullOrEmpty(e.Text)))
- {
- //Create an array of brushes and Fonts
- SolidBrush[] brushes = new SolidBrush[] {
- new SolidBrush(Color.Red),
- new SolidBrush(Color.Green),
- new SolidBrush(Color.Blue),
- new SolidBrush(Color.Purple)
- };
- Font[] fonts = new Font[] {
- new Font("Verdana", 10),
- new Font("Tahoma", 12,FontStyle.Underline),
- new Font("Calibri", 8, FontStyle.Bold),
- new Font("Calibri", 12, FontStyle.Italic)
- };
- Single x = 0;
- string text = e.Text;
- //Traverse celltext and set Font/ForeColor.
- for (int i = 0; i < text.Length; i++)
- {
- string character = text<em class="bbcode-em"></em>.ToString();
- e.Graphics.DrawString(character, fonts<em class="bbcode-em"></em>, brushes<em class="bbcode-em"></em>, e.Bounds.X + x, e.Bounds.Y);
-
- //Next character needs to be shifted right;
- //depending on the space occupied by the previous character as per its FontSize/FontStyle
- x += (e.Graphics.MeasureString(character, this.c1FlexGrid1.Font)).Width;
- }
- }
- //we're done
- e.Handled = true;
- }
- }
复制代码
效果:
|