是的,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;
}
}