我需要在Table里面添加CheckBox等科编辑的控件, 现在的做法是通过TableCell.Start取坐标, 但是这个坐标好像不不准,加进去的控件位置不对.
- Table table = textControl1.Tables.GetItem(100);
- if (table == null) return;
- int dpiX = Helper.Instance.GetDpiX(textControl1);
- for (int i = 1; i <= table.Rows.Count; i++)
- {
- int rowIndex = i + 1;
- TableCell cell = table.Cells.GetItem(rowIndex, columnIndex);
- textControl1.InputPosition = new InputPosition(cell.Start - 1);
- int x = textControl1.InputPosition.Location.X;
- int y = textControl1.InputPosition.Location.Y;
- //Line start = textControl1.Lines.GetItem(cell.Start - 1);
- //Line end = textControl1.Lines.GetItem(cell.Start + cell.Length - 1);
- //int x = start.TextBounds.Location.X;
- //int y = start.TextBounds.Location.Y;
- int left = (x - textControl1.ScrollLocation.X) / dpiX;
- int top = (y - textControl1.ScrollLocation.Y) / dpiX;
- //int left = x;
- //int top = y;
- Point p = new Point(left, top);
- CheckBox control = new CheckBox();
- //control.Location = new Point(100, 100);
- control.Location = p;
- //control.Text = "text";
- control.AutoSize = true;
- control.BringToFront();
- textControl1.Controls.Add(control);
- }
复制代码 出来的效果是这样的, 怎么才能精确的把控件添加到Cell里面呢?
|
-
|