简体   繁体   English

将焦点设置为表格

[英]Set Focus to Form

My c# console application opens a login form in which user enters login information, the problem is that when this login form opens focus is still set to console application even though focus should be set on login form . 我的c# console application打开一个login form ,用户在其中输入登录信息,问题是当这个login form打开时, focus仍然设置为console application即使focus应该在login form上设置。 I've tried using both the Focus() & Activate() functions with out any luck. 我尝试过使用Focus()Activate()函数,但没有运气。 Here is an example of how I've tried to set focus away from my console application and set focus to my login form : 这是一个例子,说明我如何设置focus远离我的console application并将focus设置为我的login form

static void StartLoginForm()
{
        Form frm = new Form();
        frm.ShowDialog();
        frm.Focus();//Didn't work for me
        frm.Activate();//Also didn't work for me
}

What am i doing wrong? 我究竟做错了什么? Any help would greatly be appreciated! 任何帮助将不胜感激!


Thank you for your time. 感谢您的时间。

Try this : 尝试这个 :

static void StartLoginForm()
{
    Form frm = new Form();
    frm.Show();
    frm.Activate();
    Application.Run(frm);
}

Have you tried to focus first then show the form ? 您是否尝试过先关注然后显示表单

static void StartLoginForm()
{
        Form frm = new Form();
        frm.Focus();
        frm.ShowDialog();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM