C# 获取RICHTEXTBOX所有图形的位置和大小

26 篇文章 0 订阅

 

没什么好说的...是是建立了一个RichTextBox. 然后去判断RichTextBox的类型为OBJECT

而且 有RTF的OBJ定义字段 objw objh 来获取的

 

 

全部代码

 

        public IList<Rectangle> GetRichTextObjRectangle(RichTextBox p_RichTextBox)
        {
            IList<Rectangle> _RectangleList =new List<Rectangle>();
            RichTextBox _RichText = new RichTextBox();
            _RichText.Rtf = p_RichTextBox.Rtf;
            int _Count = p_RichTextBox.Text.Length;

            for (int i = 0; i != _Count; i++)
            {
                if (p_RichTextBox.Text[i] == ' ')
                {
                    _RichText.Select(i, 1);

                    if (_RichText.SelectionType.ToString() == "Object")
                    {
                        Point _StarPoint = p_RichTextBox.GetPositionFromCharIndex(i);

                        System.Text.RegularExpressions.Regex _RegexWidth = new System.Text.RegularExpressions.Regex(@"(?<=//objw)[^//]+");
                        System.Text.RegularExpressions.Regex _RegexHeight = new System.Text.RegularExpressions.Regex(@"(?<=//objh)[^{]+");

                        int _Width = 0;
                        int _Height = 0;

                        if(int.TryParse(_RegexWidth.Match(_RichText.SelectedRtf).Value,out _Width) &&  int.TryParse(_RegexHeight.Match(_RichText.SelectedRtf).Value,out _Height))
                        {
                            //这里的数字要 /15才可以
                            _RectangleList.Add(new Rectangle(_StarPoint.X, _StarPoint.Y, _Width/15, _Height/15));                          
                        }                       
                    }
                }      
            }
            _RichText.Dispose();
            return _RectangleList;
        }

 

其实非常的少..

 

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值