[英]C# add avatar to RichTextBox
What I'm trying to accomplish here , is having the ability to add a text msg like this: 我要在这里完成的工作是能够添加这样的文本消息:
to be able to make a chat box , where I have lets say 1000 msgs , like this .. So I created a custom RichTextBox
as follow : 为了能够创建一个聊天框,我可以说是1000 msgs,就像这样..因此,我创建了一个自定义
RichTextBox
,如下所示:
public class CustomRichTextBox : RichTextBox
{
public CustomRichTextBox()
{
}
public static byte[] ImageToByte(Image img)
{
ImageConverter converter = new ImageConverter();
return (byte[])converter.ConvertTo(img, typeof(byte[]));
}
public static string ByteArrayToString(byte[] ba)
{
StringBuilder hex = new StringBuilder(ba.Length * 2);
foreach (byte b in ba)
hex.AppendFormat("{0:x2}", b);
return hex.ToString();
}
public void AddPic(Image img)
{
string imgStr = ByteArrayToString(ImageToByte(img));
string mpic = @"{\pict\pngblip\picw" +
img.Width.ToString() + @"\pich" + img.Height.ToString() +
@"\picwgoal" + img.Width.ToString() + @"\pichgoal" + img.Height.ToString() +
@"\hex " + imgStr + "}";
Rtf += mpic + " Username \r\n Said!...";
}
}
but nothing really shows on the RichTextBox
, what I'm missing here!? 但是
RichTextBox
上什么也没显示,我在这里缺少什么! I just want it to show the avatar and a paragraph next to it , later I will change the font/color etc
我只希望它显示头像和旁边的一个段落,以后我将更改
font/color etc
I think your avatar image as well as textbox for username should be separate controls from comment/message contents. 我认为您的头像图片以及用户名文本框应与评论/消息内容分开。 This is sort of how it should be done:
这是应该如何做的一种方式:
<StackPanel orientation="horizontal">
<Image alt="avatar" />
<StackPanel orientation="vertical">
<TextBox>Username</TextBox>
<RichTextBox>Message or Comment</RichTextBox>
</StackPanel>
</StackPanel>
Translate to your layout of choice. 转换为您选择的布局。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.