开始 -〉新建 -〉新建项目 -〉“Windows窗体控件库”
名称栏 里 改为: myControl1
注: 若要添加城市国家区县等记录,请关联着 Area 表一同进行
上代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace myControls1
{
public partial class UserControl1 : UserControl
{
private int LeftComboBox = 90;
private int TopComboBox = 50;
private int LeftRadioButton = 40;
private int TopRadioButton = 48;
private int Vertical = 45;
public int ctWidth = 270;// tabControl 控件 属性
public int ctHeight = 480;
private TabControl tc = new TabControl();
private TabPage tp层级 = new TabPage();
private TabPage tp树型 = new TabPage();
private TreeView tv = new TreeView();
private Button button确定 = new Button();
private RadioButton radioButtonTemp = new RadioButton();//临时的、不可见的
private string connStr = "";
private int _id_返回值 = 0;
public bool flag { get; set; }
public string tab表名1 { get; set; }
public string tab表名2 { get; set; }
public int id_返回值
{
get { return _id_返回值; }
}
private SqlConnection sqlconn;
private DataSet ds = new DataSet();
public UserControl1(string s)//s 系传进来的数据库连接字符串
{
connStr = s;
InitializeComponent();
sqlconn = new SqlConnection(connStr);
flag = false;
}
private void UserControl1_Load(object sender, EventArgs e)
{
setMainControls(tab表名1, tab表名2);
}
/// <summary>
/// tablename1 和 tablename2 系表名
/// </summary>
/// <param name="tablename1"></param>
/// <param name="tablename2"></param>
private void setMainControls(string tablename1, string tablename2)
{
tc.Location = new Point(40, 30);
tc.Width = ctWidth;
tc.Height = ctHeight;
tp层级.Text = "层级";
tp树型.Text = "树型";
tv.Dock = DockStyle.Fill;
tc.C