我正在C#中創建一個Windows窗體應用程序,我正在執行密碼保護。 對於可憐的頭銜和解釋,我很抱歉,因爲你可以告訴我是一個業餘愛好者。從對象C調用初始類#
加載登錄後的形式是被從內部Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace POS
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
}
}
}
該類被簡單地稱爲登錄稱爲類。一旦用戶成功通過身份驗證,我將創建一個新類的對象,隱藏登錄表單並打開一個新類。
namespace POS
{
public partial class Login : Form
{
RiverbankTeaRooms main = new RiverbankTeaRooms();
private void Enter_Click(object sender, EventArgs e)
{
bool found = false;
try
{
// Search through database through dr[1] (Table 2) for matching string.
foreach (DataRow dr in dra)
{
if (dr[1].ToString() == Code.Text)
{
found = true;
// Open main form.
main.SignedIn = true;
main.Show();
this.Hide();
break;
}
}
if (found == false)
{
// Incorrect password.
Code.Text = "Incor";
}
}
catch
{
// Error, most likely with Database.
Code.Text = "Error";
}
}
}
}
這工作完全正常......要打開該程序,但驗證用戶我希望能夠從RiverbankTeaRooms
類中再次註銷,並打開登錄窗體。我不知道如何能夠重新打開表單登錄,因爲它只被隱藏,但我不知道如何去做Login.Show();
我無法在裏面創建一個新的登錄實例主窗體,因爲RiverbankTeaRooms
窗體將無法關閉。
這讓我瘋狂,對不起的解釋感到抱歉!
我想反轉邏輯,以便調用Application.Run(新的RiverbankTeaRooms()),並在啓動時隱藏並顯示登錄。 –
我並不意味着要成爲一個混蛋,但如果你正在寫一個生產POS系統,並且你的團隊中沒有高級人員,那麼你就會頭腦發熱。 – Yaur
這只是一個簡單的計算機項目,它只是一個考試。我只在A2。 我也嘗試了倒邏輯,我不記得我是如何做到的,但不知何故,我認爲使用登錄表單會更好。 – alfers