C#中的自定义对话框

C#中的自定义对话框

本文介绍了C#中的自定义对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮,当点击时,会打开一个对话框,其上有各种各样的控件,如单选按钮和文本框。如果确定,则该对话框中的值将传回该按钮,其余的代码将使用这些值进行处理。如果取消,则不做任何操作。



我该怎么做?我正在考虑用这些控件制作另一个表单,并且该按钮调用新表单,但是我希望其余的控件停止,直到窗体完成为一个对话框。

解决方案

1。)创建您正在谈论的所有必需UI元素的表单。还可以添加一个确定和取消按钮。



2。)在确定和取消按钮的属性窗格中,将DialogResult值分别设置为确定和取消。此外,您还可以将表单的CancelButton属性设置为您创建的取消按钮的属性。



3。)向对应的对话框添加其他属性



4。)要显示对话框,请按照

  using(MyDialog dialog = new MyDialog())
{
DialogResult result = dialog.ShowDialog();

开关(结果)
{
//放入如何处理各种结果
//如果可以,那么就像var x = dialog .MyX;
}

}


I have a button that when clicked, a dialog box opens up with various controls on it such as radio buttons and text boxes. If OK then the values in that dialog box is passed back to the button and the rest of the code is processed with those values. If Cancel then do nothing.

How can I do this? I was thinking of making another form with those controls and have that button call the new form but I want the rest of the controls to stop until the form is completed like a dialog box.

解决方案

1.) Create the form you were talking about with all of the neccessary UI elements. Also add an OK and Cancel button to it.

2.) In the property pane for the OK and Cancel button, set the DialogResult values to OK and Cancel, respectively. Additionally, you can also set the Form's CancelButton property to be that of the Cancel button you've created.

3.) Add additional properties to the dialog that correspond to the values you'd like to return.

4.) To display the dialog, do something along the lines of

using( MyDialog dialog = new MyDialog() )
{
   DialogResult result = dialog.ShowDialog();

   switch (result)
   {
    // put in how you want the various results to be handled
    // if ok, then something like var x = dialog.MyX;
   }

}

这篇关于C#中的自定义对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 10:10