展示
窗体控件属性要更改的有:
ModalDialog:
窗体属性中的FormBorderStyle 改为FixedDialog 不显示标题框
MaximizeBox 改为 False 不显示最大化按钮
MinimizeBox 改为 False 没显示最小化按钮
ControlBox 改为 False 不显示关闭按钮
ShowInTask 改为 False 窗体不显示到任务栏中
button1的dialogResult 属性改为 OK 或 Yes
button2的dialogResualt 属性改为 cancel 或 No
附上代码
Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _10_3
{
public partial class Form1 : Form
{
/// <summary>
/// 父窗体
/// </summary>
public Form1()
{
InitializeComponent();
}
int[] diaocha = new int[3];
private void button1_Click(object sender, EventArgs e)
{
DialogData dd = new DialogData();
ModalDialog md = new ModalDialog()
{
DataDialog = dd // 赋值
};
md.ShowDialog();
if (md.DialogResult == DialogResult.OK)
{
diaocha[0] += md.DataDialog.DataH;
this.textBox1.Text = diaocha[0].ToString();
diaocha[1] += md.DataDialog.DataY;
this.textBox2.Text = diaocha[1].ToString();
diaocha[2] += md.DataDialog.DataB;
this.textBox3.Text = diaocha[2].ToString();
int count = 0;
foreach (int i in diaocha)
count += i;
this.textBox4.Text = count.ToString();
}
}
}
}
ModalDialog
注意:单选按钮绑定的是CheckedChanged事件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _10_3
{
public partial class ModalDialog : Form
{
/// <summary>
/// 模态对话框窗体
/// </summary>
public ModalDialog()
{
InitializeComponent();
}
private int henrenke;
private int yibanrenke;
private int burenke;
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
henrenke += 1;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked)
yibanrenke += 1;
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (radioButton3.Checked)
burenke += 1;
}
public DialogData DataDialog
{
get
{
DialogData dd = new DialogData()
{
// 赋值
DataH = henrenke,
//类似参数,用','隔开
DataY = yibanrenke,
DataB = burenke
};
return dd;
}
set
{
henrenke = value.DataH;
yibanrenke = value.DataY;
burenke = value.DataB;
}
}
}
}
DialogData
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _10_3
{
/// <summary>
/// 数据存储类
/// </summary>
public class DialogData
{
private int _henrenke;
private int _yibanrenke;
private int _burenke;
public int DataH
{
get
{
return _henrenke;
}
set
{
_henrenke = value;
}
}
public int DataY
{
get
{
return _yibanrenke;
}
set
{
_yibanrenke = value;
}
}
public int DataB
{
get
{
return _burenke;
}
set
{
_burenke = value;
}
}
}
}