SetFocus在动态创建的控件上. [英] SetFocus on dunamically created controls.
本文介绍了SetFocus在动态创建的控件上.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用C#.net Windows应用程序将重点放在动态创建的控件上
How to set focus on dynamically created controls using C#.net windows application
txtsrno = new TextBox();
txtsrno.Name = "a1" + nn.ToString();
txtsrno.Location = new Point(6, y);
txtsrno.Size = new Size(59, 20);
txtsrno.Text = sno.ToString();
txtsrno.TabIndex = txt_amount.TabIndex + 1; // this is not working.
panel1.Controls.Add(txtsrno);
推荐答案
将控件添加到panel1后,请尝试调用Focus方法.
Once added the control to the panel1, try calling the Focus method.
txtsrno.Focus();
应该有帮助!
干杯!
Should help!
Cheers!
简短说明一下Mario的正确答案,只是为了结束这一话题:所有控件总是始终创建并动态添加.如果您认为设计器做了一些不同的事情,请再考虑一下.设计器仅帮助您在设计时创建代码.运行时发生的事情恰好是您在应用程序中所做的事情.查看设计器自动生成的C#代码以查看它.
—SA
A short note to the correct answer by Mario, just to close the topic: all controls are always created and added dynamically. If you think the Designer does something different, think again. The designer only helps you to create the code during design-time. What happens during runtime is exactly what you do in your application. Look at the C# code auto-generated by the Designer to see it.
—SA
这篇关于SetFocus在动态创建的控件上.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文