女士们先生们,不幸的是,我再次用新手的东西来打扰你们。我已经搜索了几个小时的信息,所以如果有一个我想要的线程,它的埋藏比我能找到的更深。
这是我在这里的第一个问题,Mark Hall 很友好地让我直截了当。从那时起,我创建了一个新项目,并将我的前三个屏幕重新创建为用户控件——一个容器/登录、一个选择屏幕和一个主屏幕(当前为空)。如果用户拥有多个集合,则会弹出选择屏幕并允许他们选择一个集合。
我确实遇到了参数问题,但我通过重载表单声明来解决这个问题(解决方案在这里找到)——是的,我知道通过调用发送参数要好得多,但我不想必须创建一个调用对于每个参数(我是吗?)和......好吧,好吧,我比{get,set}更擅长这个。伙计,我讨厌成为新手。
无论如何,我在选择表单时遇到了问题——我似乎无法调用它,关闭它,然后转到主表单。我直接进入主表单没有问题(如果只有一个集合),那就是该死的选择表单。是的,我知道我可以选择 datagridview,但我们的一些最终用户不是工具棚中最锋利的灯泡,需要手持。无论如何,这是代码。
容器/登录屏幕
namespace DeleteThis
{
public partial class ContainerForm : Form
{
Main Main = new Main();
LoginCollectionChoice LoginChoice = new LoginCollectionChoice();
DataTable dtPermissions = new DataTable();
public ContainerForm()
{
InitializeComponent();
Main.ExitEvent += new Main.ExitEventHandler(Main_ExitEvent);
LoginChoice.ExitEvent += new
LoginCollectionChoice.ExitEventHandler(LoginChoice_ExitEvent);
}
void LoginChoice_ExitEvent(object sender, EventArgs e)
{
pnlcontainer.Controls.Remove(LoginChoice);
}
void Main_ExitEvent(object sender, EventArgs e)
{
pnlcontainer.Controls.Remove(Main);
}
private void btnLogin_Click(object sender, EventArgs e)
{
LoginProcedure();
}
private void LoginProcedure()
{
DataTable dtPermissions = AdminClass.GetCollectionsForUser(int.Parse(txtbxUserName.Text));
if (dtPermissions.Rows.Count == 1)
{
//Valid user, one collection. Head right in.
pnlcontainer.Controls.Add(Main);
Main.BringToFront();
}
else
{
//More than one collection found. Giving user choice
LoginCollectionChoice LoginChoice = new LoginCollectionChoice(dtPermissions);
pnlcontainer.Controls.Add(LoginChoice);
LoginChoice.BringToFront();
}
}
private void btnExitProgram_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
我希望我没有在剪断中杀死任何东西。现在是选择屏幕……</p>
public partial class LoginCollectionChoice : UserControl
{
public delegate void ExitEventHandler(object sender, EventArgs e);
public event ExitEventHandler ExitEvent;
private static DataTable dtPermit;
DataTable dtPermissions = new DataTable();
public LoginCollectionChoice()
{
}
public LoginCollectionChoice(DataTable dtPermissions)
{
InitializeComponent();
GrdCollection.DataSource = dtPermissions;
dtPermit = dtPermissions;
}
private void btnChoose_Click(object sender, EventArgs e)
{
//Code for the user to choose a collection
ExitEvent(this, new EventArgs());
}
}
我已经剪掉了所有不相关的代码,希望各位先生女士们可以帮助这个新手走上正确的道路。求你了,温柔点,你不会想看到我哭吧?:) 哦!如果你知道任何很棒的教程网站,请发邮件给我。我宁愿花一周的时间在教程上,也不愿花一周的时间在这里磕磕绊绊和提问。非常感谢大家。