我知道這裏已經有幾條線了。我需要的是有一個窗口窗口始終集中意味着如果我點擊記事本或任何程序,它不會輸入任何數據,只在我的Windows窗體文本框中輸入數據。Windows窗體窗口總是聚焦?
我發現這個代碼,工作起來有些將更多地解釋
//Delegates for safe multi-threading.
delegate void DelegateGetFocus();
private DelegateGetFocus m_getFocus;
Thread newThread;
public MemberLogin()
{
m_getFocus = new DelegateGetFocus(this.getFocus);
InitializeComponent();
spawnThread(keepFocus);
toggleFocusButton.Text = "OFF";
timer1.Interval = 2000;
textBox1.Select();
}
//test focus stuff
//Spawns a new Thread.
private void spawnThread(ThreadStart ts)
{
try
{
newThread = new Thread(ts);
newThread.Start();
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Exception!", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
//Continuously call getFocus.
private void keepFocus()
{
while (true)
{
getFocus();
}
}
//Keeps Form on top and gives focus.
private void getFocus()
{
//If we need to invoke this call from another thread.
if (this.InvokeRequired)
{
this.Invoke(m_getFocus, new object[] { });
}
//Otherwise, we're safe.
else
{
//having this seemed to have kept my windows onTop at all times even when off
// this.TopMost = true;
this.TopMost = true;
this.Activate();
this.textBox1.Select();
this.textBox1.Focus();
}
}
此代碼似乎當我的Visual Studio項目在窗口關閉是最上面的,但並不能很好地只有當我打開項目意味着工作有焦點意思我可以鍵入其他程序。奇怪的是,我發現記事本和我的文本框都閃爍着線條,告訴你在哪裏寫文本。如果我從Visual Studio項目運行我的應用程序,那麼它應該可以正常工作,當我嘗試點擊其他窗口時,它不會讓我訪問這是我想要的內容。
所以我在爲項目打開那麼即使我做了工作的.exe和其他copys妥善我關閉該項目解決方案與項目,爲什麼它只能正確打開
而且只要注意有點混亂該程序做了我上面解釋的。
只做了一些更多的測試,並且它似乎只在該進程運行vhost.exe(這是Visual Studio託管進程)時才能正常工作。我禁用它的設置,當我從VS它工作正常開展,但是當我在bin文件夾只運行exe文件我仍然得到奇怪的結果
編輯
這裏有一個快速的視頻我做了我的結果http://www.youtube.com/watch?v=1ozpHSRGnMo
新的編輯
我沒有解決這個問題是什麼做這個設置我在全屏模式下的應用程序還挺這樣用戶可以去點擊其它窗口不關閉這一個第一
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
Windows有一個明確的應對措施到位,從這樣阻止你。程序員從不考慮明顯的失敗模式:如果*兩個*程序會這樣做會怎麼樣? – 2013-03-19 23:23:26
[保持應用程序在頂部和焦點 - 始終]可能的重複(http://stackoverflow.com/questions/2444842/keeping-an-application-on-top-and-in-focus-always) – 2013-03-20 04:57:58
退房我剛剛製作的這段視頻展示了http://www.youtube.com/watch?v=1ozpHSRGnMo的結果,並且不是重複的,因爲我聲明瞭代碼的工作原理,並且我從本網站的另一篇文章中獲得了它。但是代碼只有在從VS2012執行時纔有效,這意味着當我按F5按鈕來運行我的應用程序時。就像我甚至不能點擊其他窗口一樣,這就是我想要的!但後來我運行這個exe文件,我可以在其他windwows(如記事本)中編寫代碼。所以我在想什麼VS2012給我的應用程序更多優先於其他人。 – Steven 2013-03-20 06:44:48