没什么好说的...是是建立了一个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;
}
其实非常的少..