[英]C# add avatar to RichTextBox
我要在這里完成的工作是能夠添加這樣的文本消息:
為了能夠創建一個聊天框,我可以說是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!...";
}
}
但是RichTextBox
上什么也沒顯示,我在這里缺少什么! 我只希望它顯示頭像和旁邊的一個段落,以后我將更改font/color etc
我認為您的頭像圖片以及用戶名文本框應與評論/消息內容分開。 這是應該如何做的一種方式:
<StackPanel orientation="horizontal">
<Image alt="avatar" />
<StackPanel orientation="vertical">
<TextBox>Username</TextBox>
<RichTextBox>Message or Comment</RichTextBox>
</StackPanel>
</StackPanel>
轉換為您選擇的布局。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.