WPF學習筆記(五)Brush

來源:互聯網
上載者:User

   畫刷是WPF中最常用的對象之一,主要在System.Windows.Media命名空間內,Brush的繼承樹為

        object---dispatchobject----dependencyObject---Freezable---Animatable---Brush---GradientBrush等

      其中SolidColorBrush對象是最簡單的畫刷,是單一顏色的,而GradientBrush是漸層畫刷,包括兩個子類LinearGradientBrush

   與RadialGradientBrush.       也有Brushes對象可以用來直接使用。 例如:

                      PropertyInfo[] pro=typeof(Brushes).GetProperties();

                      Background=(Brush)pro[index].GetValue(null,null);

            註:須在命名空間中加入System.Reflection。

  漸層畫刷大致包括指定幾個Point對象,並指定該點的顏色。。例 :LinearGradientBrush linear=new LinearGradientBrush(Colors.Red,Colors.Blue,new Point(0.5,0.5),new Point(0.8,0.8)); 紅色到藍色的漸層。

   GradientBrush有以下幾個屬性值得注意:

                StartPoint與EndPoint .

                MappingMode決定是否使用相對座標 (即(1,1)代表右下角),它是BrushMappingMode的枚舉;

                SpreadMethod 屬性決定超出部分的顏色。 是GradientSpreadMethod的枚舉,Pad,Reflect,Repeat 。

                GradientStops是GradientStopCollection類型,而GradientStop具有Color與Offset屬性  ,

            RadialGradientBrush 橢圓形漸層,其中Center  RadiusX   RadiusY  決定橢圓,GradientOrigin是漸層開始的點,

此外還有TileBrush---DrawingBrush.  ImageBrush  . VisualBrush  

      ImageBrush :  顧名思義就是映像畫刷。主要屬性是ImageSource

      等

              

首先繼承樹如下:

Object---DispatcherObject---DependencyObject---Visual---UIElement---FrameworkElement---Control--ContentControl

表單表現的重點就是內容Content;Content幾乎可以是任何對象。

WPF中沒有專用的Font類,與字型相關的主要是FontFamily , FontStyle ,FontWeight FontSize

常用的字型有Courier New, Times New Roman , Arial Palatino Linotype ,Verdana, Comic Sans MS, Century Gothic

例:FontFamily=new FontFamily("Times New Roman Bold Italic");

shape---ellipse,polyline,line,path,rectangle

TextBlock對象;

TextBlock txb=new TextBlock();

txb.Inlines.Add("hello");

txb.Inlines.Add(new Italic(new Run("hello")));

txb.Inlines.Add(new Bold(new Run("hello")));

       

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.