首页 > 代码库 > 制作圆角文本框、圆角按钮(读者们以此作为基础再去扩展)
制作圆角文本框、圆角按钮(读者们以此作为基础再去扩展)
<Window.Resources>
//对按钮的重写
<ControlTemplate x:Key="CornerButton" TargetType="{x:Type Button}">
<Border BorderBrush="Green" BorderThickness="1" CornerRadius="10" Background="Red">
<ContentPresenter Content="{TemplateBinding ContentControl.Content}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border> </ControlTemplate>
//此段代码是对按钮的重写
//对文本框的重写
<ControlTemplate x:Key="CornerTextBox" TargetType="{x:Type TextBox}">
<Border BorderBrush="#00ff00" BorderThickness="1" CornerRadius="10" Background="#fff">
<ScrollViewer x:Name="PART_ContentHost" VerticalAlignment="Center"/>
</Border></ControlTemplate>
//此段代码是对文本框的重写
</Window.Resources>
<Canvas> //Canvas为WPF的面板控件
//写一个按钮为例,文本框写法类似
<Button x:Name="btnJS" Content="接收" Template="{StaticResource CornerButton}" Height="26" Canvas.Top="175" Width="61" Canvas.Left="218"></Button></Canvas>
制作圆角文本框、圆角按钮(读者们以此作为基础再去扩展)