是的,C# 控件可以自定义样式。在 C# 中,你可以通过以下几种方式来自定义控件样式:
button1.BackColor = Color.Red;
button1.ForeColor = Color.White;
WPF 示例:
<Button>
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid>
<Border Background="Blue" BorderBrush="White">
<TextBlock Text="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
WinForms 示例:
button1.BackColor = Color.Blue;
button1.ForeColor = Color.White;
button1.FlatStyle = FlatStyle.Flat;
button1.FlatAppearance.BorderSize = 0;
public class CustomButton : Button
{
public CustomButton()
{
this.BackColor = Color.Red;
this.ForeColor = Color.White;
}
}