带图像的 RichTextBox - 行距问题
我有这个问题。我从扩展 WPF 工具包将图像(微笑)添加到 richTextBox 控件中。
在将简单文本转换为带有图像的文本的函数中,我设置了行高 段落和本段落我添加到 richTextBox 块中。就是这样:
private void RpTextToTextWithEmoticons(string msg)
{
//set line height
var para = new Paragraph {LineHeight = 40};
var r = new Run(msg);
para.Inlines.Add(r);
string emoticonText = GetEmoticonText(r.Text);
//if paragraph does not contains smile only add plain text to richtextbox rtb2
if (string.IsNullOrEmpty(emoticonText))
{
RtbConversation.Document.Blocks.Add(para);
}
else
{
while (!string.IsNullOrEmpty(emoticonText))
{
TextPointer tp = r.ContentStart;
// keep moving the cursor until we find the emoticon text
while (!tp.GetTextInRun(LogicalDirection.Forward).StartsWith(emoticonText))
tp = tp.GetNextInsertionPosition(LogicalDirection.Forward);
// select all of the emoticon text
var tr = new TextRange(tp, tp.GetPositionAtOffset(emoticonText.Length)) { Text = string.Empty };
//relative path to image smile file
string path = _mappings[emoticonText];
var image = new Image
{
Source = new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute)),
Width = 30,
Height = 30,
};
//insert smile
new InlineUIContainer(image, tp);
if (para != null)
{
var endRun = para.Inlines.LastInline as Run;
if (endRun == null)
{
break;
}
else
{
emoticonText = GetEmoticonText(endRun.Text);
}
}
}
RtbConversation.Document.Blocks.Add(para);
}
}
但是如果我添加新段落到块中,所有段落都有不同的行高/间距。我需要恒定的行高/各个段落之间的间距,就像在 Skype 中聊天一样。
我的问题你可以在图片上看到:
哪里有问题,我很无奈。感谢您的任何提前。
I have this problem. I add images (smiles) into richTextBox control from Extended WPF Toolkit.
In function on converting simple text to text with images I set line height
of paragraph and this paragraph I add to blocks of richTextBox. Here is it:
private void RpTextToTextWithEmoticons(string msg)
{
//set line height
var para = new Paragraph {LineHeight = 40};
var r = new Run(msg);
para.Inlines.Add(r);
string emoticonText = GetEmoticonText(r.Text);
//if paragraph does not contains smile only add plain text to richtextbox rtb2
if (string.IsNullOrEmpty(emoticonText))
{
RtbConversation.Document.Blocks.Add(para);
}
else
{
while (!string.IsNullOrEmpty(emoticonText))
{
TextPointer tp = r.ContentStart;
// keep moving the cursor until we find the emoticon text
while (!tp.GetTextInRun(LogicalDirection.Forward).StartsWith(emoticonText))
tp = tp.GetNextInsertionPosition(LogicalDirection.Forward);
// select all of the emoticon text
var tr = new TextRange(tp, tp.GetPositionAtOffset(emoticonText.Length)) { Text = string.Empty };
//relative path to image smile file
string path = _mappings[emoticonText];
var image = new Image
{
Source = new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute)),
Width = 30,
Height = 30,
};
//insert smile
new InlineUIContainer(image, tp);
if (para != null)
{
var endRun = para.Inlines.LastInline as Run;
if (endRun == null)
{
break;
}
else
{
emoticonText = GetEmoticonText(endRun.Text);
}
}
}
RtbConversation.Document.Blocks.Add(para);
}
}
But If I add new paragraphs to blocks all paragraphs have various line height/spacing. I need constat line height/spaccing between individual paragraph, something like chat in skype.
My problem you can see on image:
Where can be problem, I am helpless. Thank for any advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这个
如何更改 RichTextBox 段落间距?
just have a look at this
How do I change RichTextBox paragraph spacing?