后台用代码设置color

来源:互联网 发布:js娱乐公司旗下艺人 编辑:程序博客网 时间:2024/06/05 07:14

纯色:

SolidColorBrush brush = new SolidColorBrush(Colors.White);window1.Background = brush;

渐变色:

LinearGradientBrush buttonBrush = new LinearGradientBrush(); buttonBrush.StartPoint = new Point(0, 0.5); buttonBrush.EndPoint = new Point(1, 0.5); buttonBrush.GradientStops.Add(new GradientStop(Colors.Green, 0)); buttonBrush.GradientStops.Add(new GradientStop(Colors.White, 0.9)); 

图片:

textBlock1.Background = new ImageBrush(new BitmapImage(new Uri(@"../Image/Bg.png", UriKind.RelativeOrAbsolute)));

如何将图片设置为窗体的背景:

System.Drawing.Bitmap bitmap = global::WpfApplication1.Properties.Resources.bg;ImageSourceConverter convert = new ImageSourceConverter();System.IO.MemoryStream ms = new System.IO.MemoryStream();bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);ImageBrush b = new ImageBrush();b.ImageSource = (ImageSource)convert.ConvertFrom(ms);this.Background = b; 

转载自:http://www.verydemo.com/demo_c134_i25143.html

0 0
原创粉丝点击