关于tx 添加控件的问题
请问,可以在tx控件内指定位置添加控件吗?tx 中指定文字的位置可以转换为locatoin的属性参数不?可以添加,如
_textControl.Controls.Add(new System.Windows.Forms.Button() { Text="test"});
您可以通过获取光标的位置并进行转换,然后在相应的位置来添加,但是最终只是实现一个界面上的效果,并非是添加到文档中
Point p=_textControl.InputPosition.Location; 非常感谢,试试看。 如果在selection 最后位置插入控件,应如何处理呢? 好像坐标值太大了,按您的方法添加控件,调试在光标位置无法看到所添加的控件。 可以参考下面的代码因为在tx文档中,单位不是像素而是twips,和像素之间需要进行转换
Point p=_textControl.InputPosition.Location;
int dpiX = 15;
int left = (p.X - _textControl.ScrollLocation.X) / dpiX;
int top = (p.Y - _textControl.ScrollLocation.Y) / dpiX;
System.Windows.Forms.Button btn = new System.Windows.Forms.Button() { Text = "dfdd" };
btn.Location = new Point(left,top);
_textControl.Controls.Add(btn);
页:
[1]