回复 7楼DCAgile的帖子
很抱歉没有Demo。
您可以通过鼠标相关事件来处理点击的逻辑。具体点击到哪个位置可以通过HitTest方法获取到。
以下代码演示了之前添加的一列中的图片哪个被点击到,您根据被点击的图片是哪一个来做您相应的逻辑。
代码参考:
- c1FlexGrid1.BeforeMouseDown += (s1, e1) =>
- {
- var hti = this.c1FlexGrid1.HitTest(new Point(e1.X, e1.Y));
- if (hti.Row == 1 && hti.Column == 1)
- {
- var _row = hti.Row;
- var _col = hti.Column;
- if (this.c1FlexGrid1.GetDataDisplay(_row, _col).ToString() != null)
- {
- //cell rectangle
- var _cellRect = c1FlexGrid1.GetCellRect(_row, _col);
- //graphics object
- var graphics = c1FlexGrid1.CreateGraphics();
- //cell text
- var _text = c1FlexGrid1.GetDataDisplay(_row, _col).ToString();
- //text Font
- var _font = c1FlexGrid1.GetCellStyleDisplay(_row, _col).Font;
- //Text width
- var text_width = (int)graphics.MeasureString(_text, _font).Width;
- //Cursor location
- var cursor_loc = new Point(e1.X, e1.Y);
- //find x-coordinate for each image
- var img1_X = _cellRect.Location.X + text_width - 10;
- var img2_X = img1_X + img1.Width + 5;
- var img3_X = img2_X + img2.Width + 5;
- //find rectangle for each image
- var img1_Rect = new Rectangle(new Point(img1_X, e1.Y), img1.Size);
- var img2_Rect = new Rectangle(new Point(img2_X, e1.Y), img2.Size);
- var img3_Rect = new Rectangle(new Point(img3_X, e1.Y), img3.Size);
- //find which image-rectangle contains mouse-pointer
- if (img1_Rect.Contains(cursor_loc))
- c1FlexGrid1[_row, _col + 1] = "Left Image";
- else if (img2_Rect.Contains(cursor_loc))
- c1FlexGrid1[_row, _col + 1] = "Middle Image";
- else if (img3_Rect.Contains(cursor_loc))
- c1FlexGrid1[_row, _col + 1] = "Right Image";
- }
- }
- };
复制代码 |