0

I'm currently trying to create a Properties Window which is opened after a Button on the Outlook Toolbar is pressed, i now have:

1) the Button on the Toolbar (currently if pressed nothing occurs)

2) i know how to create the method which would hold the action after the Button is Pressed -but, I am a beginner and i don't know how to create a window which would open after the button is pressed, the Window should be fairly big, and for now have nothing but a checkbox(which i later would like to apply some method to.

if you ever created a window which opens after a button is pressed, i would be really pleased to get your help. All help is appreciated, thank you

4

3 回答 3

3

Here's the recommended way of opening a dialog window when the user clicks a button:

Add a new form to your project (e.g. MyForm) and then you can use the following code in your button's click event handler:

private void OnMyButtonClicked(object sender, EventArgs e)
{
    MyForm myForm = new MyForm();
    if (myForm.ShowDialog() == DialogResult.OK)
    {
        // The code that should be executed when the dialog was closed
        // with an OK dialog result
    }
}

In case you do not want the new window to be modal (i.e. you want to allow the user use other parts of the application while the window is opened), the code gets even more simple:

private void OnMyButtonClicked(object sender, EventArgs e)
{
    MyForm myForm = new MyForm();
    myForm.Show();
}

You can also create your form on the fly without adding one to your project, which is a bit more complicated, but advanced developers prefer this approach instead of messing with the designer ;)

private void OnMyButtonClicked(object sender, EventArgs e)
{
    Form myForm = new Form();
    myForm.Text = "My Form Title";

    // Add a checkbox
    CheckBox checkBox = new CheckBox();
    checkBox.Text = "Check me";
    checkBox.Location = new Point(10, 10);
    myForm.Controls.Add(checkBox);

    // Show the form
    myForm.Show();
}
于 2013-04-11T07:30:10.470 回答
1

Here is a small tutorial for you to follow..

http://msdn.microsoft.com/en-us/library/ws1btzy8%28v=vs.90%29.aspx

EDIT: I would also recommend you remember the msdn website because it will prove invaluable for other programming issues you come across..

于 2013-04-11T07:28:30.237 回答
0

您必须在项目中添加一个新表单。然后调用要弹出窗口的构造函数。像这样

Form2 form2 = new Form2();
form2.showDialog();

编辑:其中 form2 不是您程序的“主要”形式。只要关闭新弹出的窗口,这会将您的主窗口设置为背景。

于 2013-04-11T07:26:28.273 回答