我们创建WinForms应用程序(我有Visual Studio 2008在
Windows Vista上运行,但似乎描述的情况几乎从Win98到Vista,本机或托管代码).
写这样的代码:
using System; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 { public class Form1 : Form { private readonly Button button1 = new Button(); private readonly ComboBox comboBox1 = new ComboBox(); private readonly TextBox textBox1 = new TextBox(); public Form1() { SuspendLayout(); textBox1.Location = new Point(21,51); button1.Location = new Point(146,49); button1.Text = "button1"; button1.Click += button1_Click; comboBox1.Items.AddRange(new[] {"1","2","3","4","5","6"}); comboBox1.Location = new Point(21,93); AcceptButton = button1; Controls.AddRange(new Control[] {textBox1,comboBox1,button1}); Text = "Form1"; ResumeLayout(false); PerformLayout(); } private void button1_Click(object sender,EventArgs e) { comboBox1.DroppedDown = true; } } }
然后,运行应用程序.将鼠标光标放在表单上,不要再触摸鼠标.开始在TextBox中键入一些东西 – 光标会隐藏起来.当您按Enter键 – 事件抛出和ComboBox将被删除.但现在光标不会出现,即使你移动它!只有当您点击某处时才会出现.
有什么想法吗? 原文链接:https://www.f2er.com/csharp/95020.html