[英]Spreadsheetlight: Border around cell range, no internal borders
[英]Border around text range
我正在使用WPF创建聊天应用程序。 将文本消息添加到在运行时创建的Rich文本框,并将这些框添加到“堆栈”面板。
对于来自不同用户的消息,我需要使用不同的彩色边框 。
如何在运行时围绕这些消息设置边界?
您可以使用Border():)即:
Border b = new Border()
{
BorderBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x80, 0x80, 0x80)),
BorderThickness = new Thickness(1, 0, 1, 2),
CornerRadius = new CornerRadius(1, 1, 1, 5)
};
您可以将StackPanel作为占位符,然后在运行时添加到其中。 sp.Children.Add(b);
编辑:一个示例:
void Main()
{
StackPanel sp = new StackPanel();
for (int i = 0; i < 10; i++)
{
Border b = new Border()
{
BorderBrush = new SolidColorBrush(
i % 2 == 0
? Color.FromArgb(0xFF, 0x80, 0x80, 0x80)
: Color.FromArgb(0xFF, 0xFF, 0x0, 0x0)
),
BorderThickness = new Thickness(1, 0, 1, 2),
CornerRadius = new CornerRadius(1, 1, 1, 5),
Child = new RichTextBox()
};
sp.Children.Add(b);
}
new Window { Content = sp }.ShowDialog();
Dispatcher.CurrentDispatcher.InvokeShutdown();
}
您可以使用边框画笔属性,任何具有边框的控件都具有此属性,例如,如果您想向按钮添加边框颜色,请编写以下代码:
myButton.BorderBrush = new SolidColorBrush(Color.FromArgb(a: 255, r: 204, g: 204, b: 204));
我希望这能解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.