1.Button类
class="brush:csharp;collapse:true;;gutter:true;">using System; using System.Windows; using System.Windows.Media; using System.Windows.Input; using System.Windows.Controls; namespace LY.ClickTheButton { public class ClickTheButton:Window { [STAThread] public static void Main() { Application app = new Application(); app.Run(new ClickTheButton()); } public ClickTheButton() { Title = "Click the Butten!"; Button btn=new Button(); //下划线作用是按下Alt健时,C字母下会出现下划线 //表明Alt+C为此Button的快捷键 btn.Content = "_Click me,Please!"; //设置此按钮为焦点 btn.Focus(); //设置为默认按钮 btn.IsDefault = true; //设置为取消按钮 btn.IsCancel = true; //点击模式为悬停即触发事件 btn.ClickMode = ClickMode.Hover; //设置文字在按钮内的位置 btn.HorizontalContentAlignment = HorizontalAlignment.Left; btn.VerticalContentAlignment = VerticalAlignment.Bottom; //设置按钮在窗体中的位置 btn.HorizontalAlignment = HorizontalAlignment.Stretch; //默认为Stretch btn.VerticalAlignment = VerticalAlignment.Center; //设置外边缘大小 btn.Margin = new Thickness(48); //设置内边缘大小(即文字和边框大小) btn.Padding = new Thickness(48,48,96,96); btn.FontSize = 48; btn.FontFamily = new FontFamily("Times New Roman"); btn.Click += ButtonOnClick; Content = btn; } public void ButtonOnClick(object sender, RoutedEventArgs e) { MessageBox.Show("The button has been clicked!", Title); } } }