using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace ScriptDemoControlLibrary {
public partial class UserControl1:UserControl {
public UserControl1() {
InitializeComponent();
}
public int input_number {
get {
return int.Parse(textBox2.Text);
}
}
public int script_number {
set {
textBox1.Text = value.ToString();
}
}
}
}
接下来就是创建一个对话框,让用户输入一个数值,并返回计算结果:
设计窗口布局:
[c-sharp] view plain copy
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ScriptDemoControlLibrary {
public partial class InputNumberForm:Form {
public InputNumberForm() {
InitializeComponent();
}
private int script_value;
private int value;
public int result_value {
get {
return value;
}
}
public DialogResult addNum(int arg_iValue) {
script_value = arg_iValue;
userControl11.script_number = arg_iValue;
return ShowDialog();
}
private void ok_button_Click(object sender, EventArgs e) {
value = script_value + userControl11.input_number;
DialogResult = DialogResult.OK;
}
}
}
到现在为止我们已经完成了第一部分的工作