标题:按钮更改背景色
button1.BackColor = Color.Green;
//控件背景色为控件默认的背景色:
button1.BackColor = Control.DefaultBackColor;
标题:winform使用 elementhost 控件构建触摸屏电脑的按钮
//使用 elementhost 控件构建触摸屏电脑的按钮
System.Windows.Controls.Button btnHOM = new System.Windows.Controls.Button()
{
Name = “HOM”
};
eleHOM.Child = btnHOM;
btnHOM.AddHandler(System.Windows.Controls.Button.MouseDownEvent, new System.Windows.RoutedEventHandler(BtnHOM_MouseDown), true);
btnHOM.AddHandler(System.Windows.Controls.Button.MouseUpEvent, new System.Windows.RoutedEventHandler(BtnHOM_MouseUp), true);
btnHOM.Content = “原点回归”;
private void BtnHOM_MouseDown(object sender, System.Windows.RoutedEventArgs e)
{
(sender as System.Windows.Controls.Button).Content = “原点回归已按下”;
TM218.HMI_DI = 9;
}
private void BtnHOM_MouseUp(object sender, System.Windows.RoutedEventArgs e)
{
(sender as System.Windows.Controls.Button).Content = “原点回归”;
TM218.HMI_DI = 0;
}