找回密码
 立即注册

QQ登录

只需一步,快速开始

tydou

中级会员

8

主题

23

帖子

986

积分

中级会员

积分
986

活字格认证

tydou
中级会员   /  发表于:2015-8-24 20:03  /   查看:6030  /  回复:9
TextBoxCell框长度可以显示13位 编辑时只显示12位
输入大于12位时 末尾每输入一位 前面就少一位 始终保持在12位

9 个回复

倒序浏览
dafo
版主   /  发表于:2015-8-25 11:15:00
沙发
我不能重现你说的问题,是否能够给更多的信息,TextBoxCell.Size,  Font, 显示的文字信息。
你也可以设置TextBoxCell.Style.UseCompatibleTextRendering = true, 看看是否能够消除你说的问题。
回复 使用道具 举报
tydou
中级会员   /  发表于:2015-8-25 14:56:00
板凳
回复 2楼dafo的帖子

不好意思 我想实现这样的效果 不知可否实现 ?
回复 使用道具 举报
tydou
中级会员   /  发表于:2015-8-26 11:58:00
地板
求大神们回复
回复 使用道具 举报
dafo
版主   /  发表于:2015-8-26 15:14:00
5#
请在GcMultiRow.CellEditedFormattedValueChanged事件中添加如下代码:
  1.         private void gcMultiRow1_CellEditedFormattedValueChanged(object sender, CellEditedFormattedValueChangedEventArgs e)
  2.         {
  3.             if (this.gcMultiRow1.IsCurrentCellInEditMode)
  4.             {
  5.                 if (this.gcMultiRow1.EditingControl is TextBox)
  6.                 {
  7.                     var textBox = this.gcMultiRow1.EditingControl as TextBox;
  8.                     if (textBox.Text.Length > 12)
  9.                     {
  10.                         textBox.Text = textBox.Text.Remove(0, textBox.Text.Length - 12);
  11.                         textBox.SelectionLength = 0;
  12.                         textBox.SelectionStart = textBox.Text.Length;
  13.                     }
  14.                 }
  15.             }
  16.         }
复制代码
回复 使用道具 举报
tydou
中级会员   /  发表于:2015-8-26 15:40:00
6#
回复 5楼dafo的帖子

如果用这种方法的话 显示上可能没有问题了 但是实际值是不是就不对了
回复 使用道具 举报
dafo
版主   /  发表于:2015-8-26 16:45:00
7#
先和你确认下需求:
你是要非编辑状态下只显示后12位字符,实际存储的值是一个不裁剪的完整输入值?

当前的这个方案,如果输入长度超过12位将自动将开头的裁剪掉,所以存储到Cell.Value值也是一个裁剪后的值。
回复 使用道具 举报
tydou
中级会员   /  发表于:2015-8-26 19:39:00
8#
回复 7楼dafo的帖子

在编辑状态下
一直显示12位字符 实际输入的东西不变
回复 使用道具 举报
dafo
版主   /  发表于:2015-8-27 10:54:00
9#
请尝试下边实例代码:
  1.         private void gcMultiRow1_CellPainting(object sender, CellPaintingEventArgs e)
  2.         {
  3.             if (e.Scope == CellScope.Row)
  4.             {
  5.                 if (e.Value != null && e.Value is string)//In here, you can filter target cell by e.CellIndex/CellName
  6.                 {
  7.                     string str = (string)e.Value;
  8.                     if (str.Length > 12)
  9.                     {
  10.                         e.PaintBackground(e.ClipBounds);
  11.                         str = str.Remove(0, str.Length - 12);
  12.                         using (SolidBrush brush = new SolidBrush(e.CellStyle.ForeColor))
  13.                         {
  14.                             var strSize = e.Graphics.MeasureString(str, e.CellStyle.Font);
  15.                             e.Graphics.DrawString(str, e.CellStyle.Font, brush, new PointF(e.CellBounds.Location.X, e.CellBounds.Location.Y + (e.CellBounds.Height - strSize.Height) / 2));
  16.                         }
  17.                         e.PaintBorder(e.ClipBounds);
  18.                         e.PaintCellNoteTriangleSymbol(e.ClipBounds);
  19.                         e.PaintErrorIcon(e.ClipBounds);
  20.                         e.PaintWaveLine(e.ClipBounds);
  21.                         e.Handled = true;
  22.                     }
  23.                 }
  24.             }
  25.         }
复制代码

评分

参与人数 1金币 +999 收起 理由
Alice + 999 提供相关代码,奖励1000金币

查看全部评分

回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-9-6 09:43:00
10#
回复 9楼dafo的帖子

谢谢@dafo
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部