我尝试了很多方法,但无法完全掌握它。
注意:winform richtextbox
感谢您的回复。
以下代码是我尝试过的,但它并没有得到确切的大小,也许你知道为什么。
无论如何,这段代码并不重要,但你如何获得合适的尺寸呢?
string rtfTxt = richTextBox1.SelectedRtf;
Match mat = Regex.Match(rtfTxt, @"picw[\d]+");
mat = Regex.Match(rtfTxt, @"picwgoal[\d]+");
//width of image
int width = int.Parse(mat.Value.Replace("picwgoal", "")) / 15;
mat = Regex.Match(rtfTxt, @"pichgoal[\d]+");
//height of image
int height = int.Parse(mat.Value.Replace("pichgoal", "")) / 15;
label2.Text = width + "x" + height;
View my description from the picture.
如果方便的话,您也可以尝试使用此代码,源链接。 https://pan.baidu.com/s/1dHfcBV7
答案 0 :(得分:0)
基于@Taw的评论,您可以使用pictsize
块来提取大小:
rtb.SelectionChanged += (s, e) =>
{
var pictureSizes = Regex.Matches(rtb.SelectedRtf.Dump(), @"\\picw(?<picw>\d+)\\pich(?<pich>\d+)(\\picwgoal(?<picwgoal>\d+))?(\\pichgoal(?<pichgoal>\d+))?")
.Cast<Match>()
.Select(m => m.Groups)
.Select(grp => new
{
Width = int.Parse(grp["picw"].Value),
Height = int.Parse(grp["pich"].Value),
DesiredWidth = grp["picwgoal"].Success ? int.Parse(grp["picwgoal"].Value) : default(int?),
DesiredHeight = grp["pichgoal"].Success ? int.Parse(grp["pichgoal"].Value) : default(int?),
});
};
语法:
(\picw & \pich) \picwgoal? & \pichgoal? \picscalex? & \picscaley? & \picscaled? & \piccropt? & \piccropb? & \piccropr? & \piccropl?
- 资料来源:https://msdn.microsoft.com/en-us/library/aa140283(office.10).aspx