C#起步:WinForm当中的&字符
简例:
1 [assembly: System.Reflection.AssemblyVersion("1.2")] 2 namespace MyNamespace 3 { 4 using System; 5 using System.Windows.Forms; 6 7 8 public class MyForm :Form 9 { 10 private Button btnLoad; 11 private PictureBox pboxPhoto; 12 public MyForm() 13 { 14 this.Text="Hello Form 1.2"; 15 16 //Create and Configure the Button 17 btnLoad=new Button(); 18 btnLoad.Text="&Load"; 19 Console.WriteLine(btnLoad.Text); 20 btnLoad.Left=10; 21 btnLoad.Top=10; 22 23 //Create and configure the PictureBox 24 pboxPhoto=new PictureBox(); 25 pboxPhoto.BorderStyle=System.Windows.Forms.BorderStyle.Fixed3D; 26 pboxPhoto.Width=this.Width/2; 27 pboxPhoto.Height=this.Height/2; 28 pboxPhoto.Left=(this.Width-pboxPhoto.Width)/2; 29 Console.WriteLine(this.Width.ToString()); 30 pboxPhoto.Top=(this.Height-pboxPhoto.Height)/2; 31 Console.WriteLine(this.Height.ToString()); 32 33 //Add our new controls to the Form 34 this.Controls.Add(btnLoad); 35 this.Controls.Add(pboxPhoto); 36 } 37 public static void Main() 38 { 39 Application.Run(new MyForm()); 40 } 41 } 42 43 }
&字符在winForm当中表示用来为使用的按钮指明一个热键
例如上面的案例,Alt+L就表明按下了Button
浙公网安备 33010602011771号