wangf1978 发表于 2018-7-17 15:43:55

关于tx 添加控件的问题

请问,可以在tx控件内指定位置添加控件吗?tx 中指定文字的位置可以转换为locatoin的属性参数不?

Richard.Ma 发表于 2018-7-17 18:54:52

可以添加,如
_textControl.Controls.Add(new System.Windows.Forms.Button() { Text="test"});

您可以通过获取光标的位置并进行转换,然后在相应的位置来添加,但是最终只是实现一个界面上的效果,并非是添加到文档中
Point p=_textControl.InputPosition.Location;

wangf1978 发表于 2018-7-17 20:49:52

非常感谢,试试看。

wangf1978 发表于 2018-7-17 21:07:12

如果在selection 最后位置插入控件,应如何处理呢?

wangf1978 发表于 2018-7-17 21:39:54

好像坐标值太大了,按您的方法添加控件,调试在光标位置无法看到所添加的控件。

Richard.Ma 发表于 2018-7-18 10:24:28

可以参考下面的代码因为在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]
查看完整版本: 关于tx 添加控件的问题