TextBox 笔刷特效

TextBox 笔刷特效

开发工具与关键技术:Visual Studio 2017、WPF

撰写时间:2019年8月17日

TextBox 控件是我们开发过程中必不可少的组件,它可以使应用程序方便的与用户进行文字交互。在新WPF
4 中又为TextBox 添加了两种新笔刷特效:Selection 、Caret ,通过这两种特效使得TextBox
更加美观。

默认情况下TextBox 呈现出以下效果,字体为黑色、选区为蓝色、光标为黑色:

<TextBox 
BorderBrush="Gray" BorderThickness="3"
Width="200" Height="30"  Text="Hello World"/>

在这里插入图片描述

而使用了这些属性就发生了变化:

SelectionBrush 属性

  1. 字体颜色(Foreground)与选区颜色(SelectionBrush):
<TextBox
BorderBrush="Gray" BorderThickness="3"
Width="200" Height="30" Text="Hello World" Foreground="Red"
SelectionBrush="Green"/>

在这里插入图片描述
2. 选区透明度(SelectionOpacity):

<TextBox
BorderBrush="Gray" BorderThickness="3"
Width="200" Height="30" Text="Hello World" 
Foreground="Red" SelectionBrush="Green" SelectionOpacity="1"/>

在这里插入图片描述

  1. 渐变选区效果:
        <TextBox
BorderBrush="Gray" BorderThickness="3"
Height="20" Text="Hello World"
Margin="247,321,247,79">

            <TextBox.SelectionBrush>

                <LinearGradientBrush
StartPoint="0,0" EndPoint="1,1">

                    <GradientStop
Color="Red" Offset="0" />

                    <GradientStop
Color="Yellow" Offset="0.2" />

                    <GradientStop
Color="Blue" Offset="0.4" />

                    <GradientStop
Color="Green" Offset="0.6" />

                    <GradientStop
Color="Orchid" Offset="0.8" />

                    <GradientStop
Color="Pink" Offset="1" />

                </LinearGradientBrush>

            </TextBox.SelectionBrush>

        </TextBox>

在这里插入图片描述

CaretBrush 属性

Caret笔刷可以用来修改光标颜色:

<TextBox
BorderBrush="Gray" BorderThickness="3"
Width="200" Height="30" Text="Hello World" CaretBrush="Red" />

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值