<bdo id='Z0rpB'></bdo><ul id='Z0rpB'></ul>

  • <legend id='Z0rpB'><style id='Z0rpB'><dir id='Z0rpB'><q id='Z0rpB'></q></dir></style></legend>
  • <small id='Z0rpB'></small><noframes id='Z0rpB'>

  • <i id='Z0rpB'><tr id='Z0rpB'><dt id='Z0rpB'><q id='Z0rpB'><span id='Z0rpB'><b id='Z0rpB'><form id='Z0rpB'><ins id='Z0rpB'></ins><ul id='Z0rpB'></ul><sub id='Z0rpB'></sub></form><legend id='Z0rpB'></legend><bdo id='Z0rpB'><pre id='Z0rpB'><center id='Z0rpB'></center></pre></bdo></b><th id='Z0rpB'></th></span></q></dt></tr></i><div id='Z0rpB'><tfoot id='Z0rpB'></tfoot><dl id='Z0rpB'><fieldset id='Z0rpB'></fieldset></dl></div>

        <tfoot id='Z0rpB'></tfoot>

        如何将焦点设置到 Windows 窗体应用程序中的控件?

        How to set focus to a control in a Windows Forms application?(如何将焦点设置到 Windows 窗体应用程序中的控件?)
          • <bdo id='XWnh2'></bdo><ul id='XWnh2'></ul>
          • <tfoot id='XWnh2'></tfoot>
            <i id='XWnh2'><tr id='XWnh2'><dt id='XWnh2'><q id='XWnh2'><span id='XWnh2'><b id='XWnh2'><form id='XWnh2'><ins id='XWnh2'></ins><ul id='XWnh2'></ul><sub id='XWnh2'></sub></form><legend id='XWnh2'></legend><bdo id='XWnh2'><pre id='XWnh2'><center id='XWnh2'></center></pre></bdo></b><th id='XWnh2'></th></span></q></dt></tr></i><div id='XWnh2'><tfoot id='XWnh2'></tfoot><dl id='XWnh2'><fieldset id='XWnh2'></fieldset></dl></div>
                <tbody id='XWnh2'></tbody>

                <small id='XWnh2'></small><noframes id='XWnh2'>

                <legend id='XWnh2'><style id='XWnh2'><dir id='XWnh2'><q id='XWnh2'></q></dir></style></legend>

                1. 本文介绍了如何将焦点设置到 Windows 窗体应用程序中的控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 Windows 窗体应用程序中,何时我应该在应用程序启动时以及随后调用函数后编写代码以将焦点设置到控件?

                  In a Windows Forms application, when do I write the code to set the focus to a control both while the application is launched and subsequently after I call a function?

                  例如,如果我有一个 DropDownList、一个 TextBox 和四个按钮,并且我希望将焦点设置为 DropDownList,那么在哪里我要编写我的代码?

                  For instance, if I have a DropDownList, a TextBox and four buttons and I want the Focus to be set to the DropDownList, where do I write my code?

                  要在应用程序启动时将焦点设置到特定控件,我可以将选项卡索引设置为该 DropDown(具有最小值,假设 TabStop 属性设置为 True).

                  To set the focus to a particular control on application launch, I can set the tab index to that DropDown (with a minimum value, under the assumption TabStop property is set to True).

                  现在,如果用户完成了一项操作(例如,任何单击按钮事件),然后我更新 DropDown,然后如果我想设置焦点...我可以这样做

                  Now, if the user completes an operation (say, any of the Click Button Events) and then I update the DropDown and after that if I want to set the focus...I can do it as

                  MyDropDownList.Focus()
                  

                  问题

                  注意:问题更多是关于在哪里,而不是如何?

                  NB: The question is more about where, not how?

                  推荐答案

                  到目前为止,最简单的解决方案是正确设置 TabIndex 属性,以便您的MyDropDownList"控件具有最低索引.下一种方法是在构造函数中进行.但是您必须使用 Select(),Focus() 方法还不能工作,因为该控件直到稍后才会变得可见.

                  By far the simplest solution is to set the TabIndex property correctly so that your 'MyDropDownList' control has the lowest index. The next approach is to do it in the constructor. But you have to use Select(), the Focus() method cannot work yet because the control doesn't become visible until later.

                  Public Sub New()
                      InitializeComponent()
                      MyDropDownList.Select()
                  End Sub
                  

                  也适用于 Load 事件.Focus() 在 Shown 事件中开始工作.

                  Works in the Load event as well. Focus() starts working in the Shown event.

                  这篇关于如何将焦点设置到 Windows 窗体应用程序中的控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  How delegates work (in the background)?(代表如何工作(在后台)?)
                  C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                  <i id='lM7Dg'><tr id='lM7Dg'><dt id='lM7Dg'><q id='lM7Dg'><span id='lM7Dg'><b id='lM7Dg'><form id='lM7Dg'><ins id='lM7Dg'></ins><ul id='lM7Dg'></ul><sub id='lM7Dg'></sub></form><legend id='lM7Dg'></legend><bdo id='lM7Dg'><pre id='lM7Dg'><center id='lM7Dg'></center></pre></bdo></b><th id='lM7Dg'></th></span></q></dt></tr></i><div id='lM7Dg'><tfoot id='lM7Dg'></tfoot><dl id='lM7Dg'><fieldset id='lM7Dg'></fieldset></dl></div>
                    <bdo id='lM7Dg'></bdo><ul id='lM7Dg'></ul>

                    <small id='lM7Dg'></small><noframes id='lM7Dg'>

                            <tfoot id='lM7Dg'></tfoot>
                              <tbody id='lM7Dg'></tbody>

                            <legend id='lM7Dg'><style id='lM7Dg'><dir id='lM7Dg'><q id='lM7Dg'></q></dir></style></legend>