找回密码
 立即注册

QQ登录

只需一步,快速开始

DCAgile

中级会员

83

主题

247

帖子

794

积分

中级会员

积分
794

活字格认证微信认证勋章元老葡萄

DCAgile
中级会员   /  发表于:2015-12-25 09:23  /   查看:11201  /  回复:16

C1FlexGrid控件如何实现一列添加3个图片

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

16 个回复

倒序浏览
Alice
社区贡献组   /  发表于:2015-12-25 09:47:00
沙发
回复 1楼DCAgile的帖子

谢谢您的反馈。
可以通过CellFactory功能自定义单元格。
可以参考随机安装Demo,路径如下:
\Documents\ComponentOne Samples\WPF\C1.WPF.FlexGrid\CS\FlexGridSamples\iTunes

效果如下:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

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

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
DCAgile
中级会员   /  发表于:2015-12-25 09:49:00
板凳
回复 2楼Alice的帖子

现在是winfrom界面,可以写代码参考一下吗
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-12-25 11:42:00
地板
回复 3楼DCAgile的帖子

很抱歉。之前给您回复的是WPF平台的。
WinForm平台下使用OwnerDrawCell的功能,DrawMode设置为OwerDraw,然后再OwnerDrawCell事件里添加多个Image(e.Graphics.DrawImage方法)。
代码参考:
  1. c1FlexGrid1.DrawMode = C1.Win.C1FlexGrid.DrawModeEnum.OwnerDraw;
  2. c1FlexGrid1.OwnerDrawCell += (s1, e1) =>
  3. {
  4. if (e1.Col == 1 && e1.Row == 1)
  5. {
  6.   //let the grid paint the background and border for the cell
  7.   e1.DrawCell(C1.Win.C1FlexGrid.DrawCellFlags.Background | C1.Win.C1FlexGrid.DrawCellFlags.Border);

  8.   //find text width
  9.   var width = (int)e1.Graphics.MeasureString(e1.Text, e1.Style.Font).Width;

  10.   //x-coordinate for each image
  11.   var img1_x = e1.Bounds.X + width - 10;
  12.   var img2_x = img1_x + img1.Width + 5;
  13.   var img3_x = img2_x + img2.Width + 5;

  14.   //location for each image
  15.   var img1_loc = new Point(img1_x, e1.Bounds.Y + img1.Height - 18);
  16.   var img2_loc = new Point(img2_x, e1.Bounds.Y + img1.Height - 18);
  17.   var img3_loc = new Point(img3_x, e1.Bounds.Y + img1.Height - 18);

  18.   //draw images at aforementioned points
  19.   e1.Graphics.DrawImage(img1, img1_loc);
  20.   e1.Graphics.DrawImage(img2, img2_loc);
  21.   e1.Graphics.DrawImage(img3, img3_loc);

  22.   //draw text
  23.   e1.Graphics.DrawString(e1.Text, e1.Style.Font, Brushes.Black, e1.Bounds.Location);
  24.   e1.Handled = true;
  25.   }
  26. };
复制代码
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
DCAgile
中级会员   /  发表于:2015-12-25 13:20:00
5#
回复 4楼Alice的帖子

指定显示在那一列如何确定,如何多次循环
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-12-25 15:03:00
6#
回复 5楼DCAgile的帖子

需要在哪一列设置直接通过e1.Col属性指定即可。
这个事件会对所有列进行渲染,因此不需要循环。
如果对事件里的方法会多次使用,可以抽出来一个方法,使用的时候进行调用即可。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
DCAgile
中级会员   /  发表于:2015-12-25 15:23:00
7#
回复 6楼Alice的帖子

那如何实现点击一个图片之后就变色的功能,可以发一个demo吗
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-12-25 17:06:00
8#
回复 7楼DCAgile的帖子

很抱歉没有Demo。
您可以通过鼠标相关事件来处理点击的逻辑。具体点击到哪个位置可以通过HitTest方法获取到。
以下代码演示了之前添加的一列中的图片哪个被点击到,您根据被点击的图片是哪一个来做您相应的逻辑。
代码参考:
  1. c1FlexGrid1.BeforeMouseDown += (s1, e1) =>
  2. {
  3. var hti = this.c1FlexGrid1.HitTest(new Point(e1.X, e1.Y));

  4. if (hti.Row == 1 && hti.Column == 1)
  5. {
  6.   var _row = hti.Row;
  7.   var _col = hti.Column;

  8.   if (this.c1FlexGrid1.GetDataDisplay(_row, _col).ToString() != null)
  9.   {
  10.    //cell rectangle
  11.    var _cellRect = c1FlexGrid1.GetCellRect(_row, _col);
  12.    //graphics object
  13.    var graphics = c1FlexGrid1.CreateGraphics();
  14.    //cell text
  15.    var _text = c1FlexGrid1.GetDataDisplay(_row, _col).ToString();
  16.    //text Font
  17.    var _font = c1FlexGrid1.GetCellStyleDisplay(_row, _col).Font;
  18.    //Text width
  19.    var text_width = (int)graphics.MeasureString(_text, _font).Width;
  20.    //Cursor location
  21.    var cursor_loc = new Point(e1.X, e1.Y);

  22.    //find x-coordinate for each image
  23.    var img1_X = _cellRect.Location.X + text_width - 10;
  24.    var img2_X = img1_X + img1.Width + 5;
  25.    var img3_X = img2_X + img2.Width + 5;

  26.    //find rectangle for each image
  27.    var img1_Rect = new Rectangle(new Point(img1_X, e1.Y), img1.Size);
  28.    var img2_Rect = new Rectangle(new Point(img2_X, e1.Y), img2.Size);
  29.    var img3_Rect = new Rectangle(new Point(img3_X, e1.Y), img3.Size);

  30.    //find which image-rectangle contains mouse-pointer
  31.    if (img1_Rect.Contains(cursor_loc))
  32.    c1FlexGrid1[_row, _col + 1] = "Left Image";
  33.    else if (img2_Rect.Contains(cursor_loc))
  34.    c1FlexGrid1[_row, _col + 1] = "Middle Image";
  35.    else if (img3_Rect.Contains(cursor_loc))
  36.    c1FlexGrid1[_row, _col + 1] = "Right Image";
  37.   }
  38. }
  39. };
复制代码
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
DCAgile
中级会员   /  发表于:2015-12-28 10:12:00
9#
回复 8楼Alice的帖子

可以发一个实例吗,根据你的提示做的没有显示出效果
回复 使用道具 举报
gw0506
超级版主   /  发表于:2015-12-28 10:49:00
10#
你把你做的,没有显示出来的demo发过来,我们直接调吧。要不然给你个思路,跑不起来,给你个代码片段你说不起作用。效率比较低。
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部