回复 1楼xjsxjs197的帖子
抱歉,请问“【西安葡萄城技术...】的形式”是否是通过 “OwnerDrawCell”来实现的?
以下是 TrueDBGrid 的实现代码,FlexGrid 实现形式相同
- void c1TrueDBGrid1_OwnerDrawCell(object sender, C1.Win.C1TrueDBGrid.OwnerDrawCellEventArgs e)
- {
-   e.Handled = true;
-   e.Graphics.FillRectangle(new SolidBrush(e.Style.BackColor), e.CellRect);
-   object val = c1TrueDBGrid1.Columns[e.Col].CellValue(e.Row);
-   SizeF size = e.Graphics.MeasureString(val.ToString(), c1TrueDBGrid1.Splits[0].DisplayColumns[e.Col].Style.Font);
-   int width = (int)Math.Ceiling(size.Width);
-   int cellwidth = e.CellRect.Width;
-   if (width > cellwidth)
-   {
-     int r = 1;
-     string s = e.Text;
-     string ns = "";
-     while (width > cellwidth - 5)
-     {
-       ns = s.Substring(0, s.Length - r);
-       size = e.Graphics.MeasureString(ns.ToString(), c1TrueDBGrid1.Splits[0].DisplayColumns[e.Col].Style.Font);
-       width = (int)Math.Ceiling(size.Width);
-       r++;
-       s = ns;
-     }
-     ns = ns + "....";
-     e.Graphics.DrawString(ns, e.Style.Font, new SolidBrush(Color.Black), new PointF(e.CellRect.X, e.CellRect.Y));
-    }
-    else
-    {
-      e.Graphics.DrawString(e.Text, e.Style.Font, new SolidBrush(Color.Black), new PointF(e.CellRect.X, e.CellRect.Y));
-    }
- }
复制代码
如果是这样,只能通过代码来重新拼写字符串实现。也就是再做一次事件中的判断。 |