您的位置: 首页 - 站长

wap网站搜索公关公司职级

当前位置: 首页 > news >正文

wap网站搜索,公关公司职级,广州网站模块建设,电子商务平台经营者有哪些义务转自https://www.cnblogs.com/huangxincheng/archive/2012/07/14/2591941.html 这一篇我们聊聊wpf中的画刷#xff0c;在wpf中如果想玩各种花哨#xff0c;那么如何使用画刷则是我们的基本功#xff0c;首先看一下类图 从图中可以看出#xff0c;wpf有5种画刷和1种自定义画…转自https://www.cnblogs.com/huangxincheng/archive/2012/07/14/2591941.html 这一篇我们聊聊wpf中的画刷在wpf中如果想玩各种花哨那么如何使用画刷则是我们的基本功首先看一下类图 从图中可以看出wpf有5种画刷和1种自定义画刷都是继承自基类Brush我们看看基类中有哪些好玩的东西。 这里有3个比较感兴趣的属性分别属于”透明度“和”图像转换“好下面我们一一解说。 一SolidColorBrush实心画刷 实心画刷是我们用的最多的也是最简单的一个其实也就是填充色的意思一个很简单的例子 其实这里的BackgroundRed使用的就是SolidColorBrushxaml进行解析时发现Background是Brush类型刚才我也说了 Brush具有图形转换的能力最后xaml就会通过Transform把”Red字符串解析成SolidColorBrush更直观一点的话我们可以 用C#代码来描述。 1 public partial class MainWindow : Window 2 { 3 public MainWindow() 4 { 5 InitializeComponent(); 6 7 button1.Background new SolidColorBrush(Colors.Red); 8 } 9 } 二GradientBrush(梯度画刷) 如果我们使用过ps或者freehand我们肯定知道在填充色方面有一个叫做“渐变色”的概念我们使用的最多的渐变色要么是“线性”的 要么是“圆形”的刚好这里对应wpf中的“LinearGradientBrush”和“RadialGradientBrush”。 1 LinearGradientBrush线性梯度画刷 线性画刷也是比较简单的一般情况下我们只要设定一个“StartPoint”和“EndPoint”即可。 1 Window x:ClassWpfApplication2.MainWindow2 xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation3 xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml4 TitleMainWindow Height350 Width5255 Canvas6 Rectangle Canvas.Left51 Canvas.Top187 Height101 Namerectangle2 StrokeBlack Width3257 Rectangle.Fill8 LinearGradientBrush StartPoint0,0 EndPoint1,09 GradientStop ColorYellow Offset0.5/ 10 GradientStop ColorGreen Offset1/ 11 /LinearGradientBrush 12 /Rectangle.Fill 13 /Rectangle 14 /Canvas 15 /Window 这里要注意的就是我设定的坐标是(0,0),(0,1)我们知道两点一条直线这条直线与X轴平行我们可以看到颜色的分布是垂直于Y轴的 如果说我们把坐标改为(0,0)(1,1)那么颜色分割线还是与(0,0),(1,1)这条斜线垂直吗最后发现严格垂直。 2RadialgradientBrush(圆形梯度画刷) 在ps中我们玩”圆形渐变“的时候只需要设定圆心坐标和X坐标和Y坐标的值就可以画一个圆形渐变在wpf中同样需要这三个元素 分别对应设Center,RadiusX,RadiusY,当然在wpf中还存在一个“梯度原点“GradientOrigin。 1 Window x:ClassWpfApplication3.MainWindow2 xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation3 xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml4 TitleMainWindow Height350 Width5255 Grid6 Rectangle Height200 HorizontalAlignmentLeft Margin128,45,0,0 Namerectangle1 StrokeBlack VerticalAlignmentTop Width2007 Rectangle.Fill8 RadialGradientBrush GradientOrigin0.5,0.5 Center0.5,0.5 RadiusX0.5 RadiusY0.59 RadialGradientBrush.GradientStops 10 GradientStop ColorYellow Offset0/ 11 GradientStop ColorRed Offset0.25/ 12 GradientStop ColorBlue Offset0.75/ 13 GradientStop ColorLimeGreen Offset1/ 14 /RadialGradientBrush.GradientStops 15 /RadialGradientBrush 16 /Rectangle.Fill 17 /Rectangle 18 /Grid 19 /Window 三ImageBrush图像画刷 这种画刷也是很有意思的有时我们在炫时需要用图片做装饰那么此时ImageBrush就可以祝你一臂之力。 1 Window x:ClassWpfApplication7.MainWindow2 xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation3 xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml4 xmlns:myclr-namespace:WpfApplication75 TitleMainWindow Height350 Width5256 Grid7 Grid.Background8 ImageBrush x:NamelandBrush ImageSourceC:\Users\Administrator\Desktop\weibo\64512.gif/9 /Grid.Background 10 /Grid 11 /Window 四VisualBrush控件画刷 这种画刷是作用在控件级别上的也就是说任何控件都可以作为画刷很神奇的说。 1 Window x:ClassWpfApplication1.MainWindow2 xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation3 xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml4 TitleMainWindow Height350 Width5255 Window.Resources6 VisualBrush x:Keytest TileModeTile Opacity0.87 VisualBrush.Visual8 StackPanel9 TextBlock ForegroundGold 10 唧唧复唧唧 11 /TextBlock 12 TextBlock ForegroundLightBlue 13 木兰开飞机 14 /TextBlock 15 TextBlock ForegroundLightGray 16 开的什么机 17 /TextBlock 18 TextBlock ForegroundPink 19 波音747 20 /TextBlock 21 /StackPanel 22 /VisualBrush.Visual 23 /VisualBrush 24 /Window.Resources 25 Grid 26 Button Content我是超大按钮 Height213 HorizontalAlignmentLeft Margin32,34,0,0 Namebutton1 27 VerticalAlignmentTop Width414 Background{StaticResource ResourceKeytest}/ 28 /Grid 29 /Window 五DrawingBrush自定义画刷 最灵活最复杂的也就是这种自定义画刷毕竟wpf不能给我们满足所有的要求就必须留一道口子给我们程序员自定义实现。 1 Window x:ClassWpfApplication4.MainWindow2 xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation3 xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml4 TitleMainWindow Height350 Width5255 Window.Resources6 DrawingBrush x:Keytest7 DrawingBrush.Drawing8 DrawingGroup9 DrawingGroup.Children 10 GeometryDrawing 11 !– 绘制矩形 – 12 GeometryDrawing.Geometry 13 RectangleGeometry RadiusX0.2 RadiusY0.5 14 Rect0.02,0.02,0.96,0.96 / 15 /GeometryDrawing.Geometry 16 !– 矩形填充色 – 17 GeometryDrawing.Brush 18 LinearGradientBrush StartPoint0,0 EndPoint0,1 19 GradientStop ColorGreen Offset0 / 20 GradientStop ColorRed Offset1 / 21 /LinearGradientBrush 22 /GeometryDrawing.Brush 23 !– 矩形边框 – 24 GeometryDrawing.Pen 25 Pen Thickness0.02 26 Pen.Brush 27 LinearGradientBrush StartPoint0,0 EndPoint0,1 28 GradientStop ColorAliceBlue Offset0 / 29 GradientStop ColorBlack Offset1 / 30 /LinearGradientBrush 31 /Pen.Brush 32 /Pen 33 /GeometryDrawing.Pen 34 /GeometryDrawing 35 /DrawingGroup.Children 36 /DrawingGroup 37 /DrawingBrush.Drawing 38 /DrawingBrush 39 /Window.Resources 40 Grid 41 Button Background{StaticResource ResourceKeytest} FontSize40 ContentButton Height113 HorizontalAlignmentLeft Margin89,80,0,0 Namebutton1 VerticalAlignmentTop Width292 / 42 /Grid 43 /Window