请参考这篇文章中的实现方法,基本思路,首先获取单元格中第一行的 TextBounds 属性,然后获取单元格最后一行的TextBounds,从而计算出单元格的高度
TX Text Control 中表格操作之获取选中单元格的大小
- private void heightToolStripMenuItem_Click(object sender, EventArgs e)
- {
- TXTextControl.Table table = textControl1.Tables.GetItem(1000);
- TXTextControl.TableCell cell = table.Cells.GetItem();
- TXTextControl.Line lstart = textControl1.Lines.GetItem(cell.Start);
- TXTextControl.Line lend = textControl1.Lines.GetItem(cell.Start + cell.Length - 1);
- int width = cell.Width - cell.CellFormat.LeftTextDistance - cell.CellFormat.RightTextDistance;
- int height = lend.TextBounds.Top - lstart.TextBounds.Top + lend.TextBounds.Height;
- MessageBox.Show(string.Format("当前单元格坐标为:({0},{1}),宽度:{2},高度:{3}", cell.Row, cell.Column, width, height));
- }
复制代码 |