C#學習的第一個代碼,WPF下的“Say Hello”。點選按鈕會使文本框的字型随機修改顔色。
代碼如下:
Private void SayHelloButton_click(object sender, RoutedEventArgs e)
{
byte[] rgb = getRandomBytes(3);
var randomColorBrush = new SolidColorBrush(Color.FromArgb(255, rgb[0], rgb[1], rgb[2]));
TextBox1.BorderBrush = randomColorBrush;
TextBox1.Foreground = randomColorBrush;