2014-09-06 22 views
0

我正在實現一個程序,在系統啓動時應打開表單,用戶應該在某些表單域中輸入數據,然後只有用戶可以訪問信息在系統中。我將此程序添加到任務計劃程序,以便程序在系統啓動時得到執行。 強制用戶在系統啓動時填寫表單域的任何幫助?即使在按下ALT + TAB的情況下如何強制設置表單焦點

回答

0

你不能這樣做。 Windows不會允許這種情況發生。如果這是允許的,並且兩個程序試圖同時做到這一點,則不知道它會如何影響您的系統。

0

其實你的問題不明確,這是更好地提供有關您的方案

的詳細信息,但我會盡量給一些信息。

1可以使應用程序能夠在運行的窗口,通過使用下面的代碼開始應用

RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)); 

      key.SetValue("My Program", "\"" + Application.ExecutablePath + "\""); 

2 - 然後你就可以通過

using System; 
using System.Runtime.InteropServices; 
using System.Windows.Forms; 

namespace LicenseManager { 

    public static class WinApi { 

    [DllImport("user32.dll")] 
    static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); 

    static private IntPtr HWND_TOPMOST = new IntPtr(-1); 

    private const uint SWP_NOSIZE = 0x0001; 
    private const uint SWP_NOMOVE = 0x0002; 

    static public void MakeTopMost(Form f) { 
     SetWindowPos(f.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); 
    } 

    } 
} 
使你的程序運行在頂部最

3-,並且您可以阻止用戶關閉應用程序,直到他通過在結束事件中檢查您的登錄信息輸入所需的數據爲止

private void Form2_FormClosed(object sender, FormClosedEventArgs e) 
    { 
     DialogResult userAnswer = MessageBox.Show ("Do you wish to close ALL " + counterLabel.Text + " of the 'Form2' forms?", "Close ALL Forms?", 
      MessageBoxButtons.YesNo, MessageBoxIcon.Question); 

     if (userAnswer == DialogResult.Yes) 
      this.Dispose(); 
    } 
相關問題