如何編寫創建代碼的應用程序。我希望如果用戶打開應用程序,其他用戶不能使用該應用程序,並獲得使用該應用程序的用戶名的MessageBox
。爲此,我使用帶有try catch的事件並且它可以工作。第二個用戶收到帶有其他用戶名稱的消息,但在此之後打開表單。我希望表單在此消息後不能打開。我如何取消Form_Load?
我的代碼:
private void Form1_Load(object sender, EventArgs e)
{
try
{
var stream = File.Open("lock", FileMode.OpenOrCreate,FileAccess.Read);
global_stream = stream;
string username = User.GetUsername();
string machine = Computer.GetMachineName();
TextDatei datei = new TextFile();
datei.WriteFile("user_log", "Username: " + username + " Invoicennumber: "
+ machine);
CreateCode();
}
catch (Exception)
{
TextFile file = new TextFile();
string info = datei.ReadFile("user_log");
MessageBox.Show(info);
Application.Exit();
}
}