1、先画出弹出对话框的windows窗体
代码如下:
1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Text;
7
using System.Windows.Forms;
8
9
namespace CustomControlSample
10
{
11
public partial class FrmSimpleCustomTypeDialogEditor : Form
12
{
13
private SimpleCustomType _simpleCustomType;
14
15
public SimpleCustomType SimpleCustomTypeProperty
16
{
17
get { return _simpleCustomType; }
18
set { _simpleCustomType = value; }
19
}
20
21
22
public FrmSimpleCustomTypeDialogEditor(SimpleCustomType sct)
23
{
24
InitializeComponent();
25
this._simpleCustomType = sct;
26
this.textBox1.Text = sct.Min.ToString();
27
this.textBox2.Text = sct.Max.ToString();
28
}
29
30
private void button1_Click(object sender, EventArgs e)
31
{
32
this.DialogResult = DialogResult.OK;
33
this._simpleCustomType.Min = int.Parse(this.textBox1.Text);
34
this._simpleCustomType.Max = int.Parse(this.textBox2.Text);
35
this.Close(); // 这句随便写不写?!!
36
}
37
38
private void button2_Click(object sender, EventArgs e)
39
{
40
this.Close();
41
}
42
43
private void textBox1_Validating(object sender, CancelEventArgs e)
44
{
45
try
46
{
47
int.Parse(textBox1.Text);
48
}
49
catch (FormatException)
50
{
51
e.Cancel = true;
52
MessageBox.Show("无效的值。", "验证错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
53
}
54
}
55
56
private void textBox2_Validating(object sender, CancelEventArgs e)
57
{
58
try
59
{
60
int.Parse(textBox2.Text);
61
}
62
catch (FormatException)
63
{
64
e.Cancel = true;
65
MessageBox.Show("无效的值。", "验证错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
66
}
67
}
68
69
}
70
}
using System;2
using System.Collections.Generic;3
using System.ComponentModel;4
using System.Data;5
using System.Drawing;6
using System.Text;7
using System.Windows.Forms;8

9
namespace CustomControlSample10
{11
public partial class FrmSimpleCustomTypeDialogEditor : Form12
{13
private SimpleCustomType _simpleCustomType;14

15
public SimpleCustomType SimpleCustomTypeProperty16
{17
get { return _simpleCustomType; }18
set { _simpleCustomType = value; }19
}20

21

22
public FrmSimpleCustomTypeDialogEditor(SimpleCustomType sct)23
{24
InitializeComponent();25
this._simpleCustomType = sct;26
this.textBox1.Text = sct.Min.ToString();27
this.textBox2.Text = sct.Max.ToString();28
}29

30
private void button1_Click(object sender, EventArgs e)31
{32
this.DialogResult = DialogResult.OK;33
this._simpleCustomType.Min = int.Parse(this.textBox1.Text);34
this._simpleCustomType.Max = int.Parse(this.textBox2.Text);35
this.Close(); // 这句随便写不写?!!36
}37

38
private void button2_Click(object sender, EventArgs e)39
{40
this.Close();41
}42

43
private void textBox1_Validating(object sender, CancelEventArgs e)44
{45
try46
{47
int.Parse(textBox1.Text);48
}49
catch (FormatException)50
{51
e.Cancel = true;52
MessageBox.Show("无效的值。", "验证错误", MessageBoxButtons.OK, MessageBoxIcon.Error);53
}54
}55

56
private void textBox2_Validating(object sender, CancelEventArgs e)57
{58
try59
{60
int.Parse(textBox2.Text);61
}62
catch (FormatException)63
{64
e.Cancel = true;65
MessageBox.Show("无效的值。", "验证错误", MessageBoxButtons.OK, MessageBoxIcon.Error);66
}67
}68

69
}70
}
2、再编写属性值编辑器类
1
SimpleCustomTypeDialogEdit
SimpleCustomTypeDialogEdit3、再添加一个属性,并用EditorAttribute 指定相应的编辑器类
1
弹出属性值编辑对话框的属性
弹出属性值编辑对话框的属性The end.

浙公网安备 33010602011771号