C# 保存在拆分容器中的Replay按钮

C# 保存在拆分容器中的Replay按钮,c#,button,splitcontainer,replay,C#,Button,Splitcontainer,Replay,我有一个拆分容器,在这个拆分中添加了两个按钮。在将其保存到sqlserver数据库并在新的winform中重播后,但我没有成功 我需要你的帮助! 强文本强文本****强文本强文本 这是我的代码: 创建拆分容器的代码 private void DecoupageVerticalToolStripMenuItem_Click(object sender, EventArgs e) { con.Open(); splitterPanel1 = spltcnt.P

我有一个拆分容器,在这个拆分中添加了两个按钮。在将其保存到sqlserver数据库并在新的winform中重播后,但我没有成功

我需要你的帮助! 强文本强文本****强文本强文本 这是我的代码:

创建拆分容器的代码

private void DecoupageVerticalToolStripMenuItem_Click(object sender, EventArgs e)
    {
        con.Open();
        splitterPanel1 = spltcnt.Panel1;
        splitterPanel2 = spltcnt.Panel2;
        var panels = spltcnt.Controls.OfType<SplitterPanel>();
        //SplitContainer spltcnt = new SplitContainer();
        spltcnt.Dock = DockStyle.Left;
        spltcnt.Name = "spltcnt";
        spltcnt.Orientation = Orientation.Vertical;
        spltcnt.SplitterWidth = 4;
        spltcnt.Visible = true;
        spltcnt.Enabled = true;
        spltcnt.BackColor = Color.White;
        spltcnt.Size = new System.Drawing.Size(this.Width, this.Height);
        spltcnt.BorderStyle = BorderStyle.Fixed3D;

        spltcnt.SplitterDistance = (this.Width)/2;
        spltcnt.SplitterIncrement = 1;
        spltcnt.TabIndex = 0;
        //SplitContainer spltcnt = new SplitContainer();
        //var panels = spltcnt.Controls.OfType<SplitterPanel>();
        //var focusedPanel = panels.FirstOrDefault(p => p.Controls.OfType<Control>().
        //                          Any(c => c.Focused));
        ////SplitContainer sc = sp.Parent as SplitContainer;
        //MessageBox.Show(spltcnt.Name + " - " + panels.ToString());
        spltcnt.Panel1.MouseClick += Panel1OnMouseClick;
        spltcnt.Panel2.MouseClick += Panel2OnMouseClick;
        spltcnt1.Panel1.MouseClick += Panel11OnMouseClick;
        spltcnt1.Panel2.MouseClick += Panel12OnMouseClick;
        spltcnt2.Panel1.MouseClick += Panel21OnMouseClick;
        spltcnt2.Panel2.MouseClick += Panel22OnMouseClick;
        spltcnt.MouseClick += FormOnMouseClick;
        Controls.Add(spltcnt);
        //ContextMenuStrip cm = new ContextMenuStrip();
        //cm.Items.Add("Vertical");
        //cm.Items.Add("Horizontal");

        //spltcnt.ContextMenuStrip = cm;
        ContextMenuStrip myMenu1 = new ContextMenuStrip();
        this.ContextMenuStrip = myMenu1; //for this form, could be for a button etc.
        myMenu1.Items.Add("Découpage Vertical");
        myMenu1.Items[0].Click += new EventHandler(spltcnt1Panel1V_Click);
        myMenu1.Items.Add("Découpage Horizontal");
        myMenu1.Items[1].Click += new EventHandler(spltcnt1Panel1H_Click);
        myMenu1.Items.Add("Ajout Indicateur");
        myMenu1.Items[2].Click += new EventHandler(IndicateurPanel1H_Click);
        myMenu1.Items.Add("Supprimer Tout");
        myMenu1.Items[3].Click += new EventHandler(FormDelete_Click);
        //fourth item added so index here is 3
        ContextMenuStrip myMenu2 = new ContextMenuStrip();
        this.ContextMenuStrip = myMenu2; //for this form, could be for a button etc.

        myMenu2.Items.Add("Découpage Vertical");
        myMenu2.Items[0].Click += new EventHandler(spltcnt2Panel2V_Click);
        myMenu2.Items.Add("Découpage Horizontal");
        myMenu2.Items[1].Click += new EventHandler(spltcnt2Panel2H_Click);
        myMenu2.Items.Add("Ajout Indicateur");
        myMenu2.Items[2].Click += new EventHandler(IndicateurPanel2H_Click);
        myMenu2.Items.Add("Supprimer Tout");
        myMenu2.Items[3].Click += new EventHandler(FormDelete_Click);
        //fourth item added so index here is 3
        ContextMenuStrip myMenu3 = new ContextMenuStrip();
        this.ContextMenuStrip = myMenu3; //for this form, could be for a button etc.
        myMenu3.Items.Add("Vertical");
        myMenu3.Items[0].Click += new EventHandler(spltcnt3Panel1V_Click);
        myMenu3.Items.Add("Horizontal");
        myMenu3.Items[1].Click += new EventHandler(spltcnt3Panel1H_Click);
        myMenu3.Items.Add("Supprimer");
        myMenu3.Items[2].Click += new EventHandler(FormDelete2_Click);
        myMenu3.Items.Add("Supprimer Tout");
        myMenu3.Items[3].Click += new EventHandler(FormDelete_Click);
        //fourth item added so index here is 3
        ContextMenuStrip myMenu4 = new ContextMenuStrip();
        this.ContextMenuStrip = myMenu4; //for this form, could be for a button etc.
        myMenu4.Items.Add("Vertical");
        myMenu4.Items[0].Click += new EventHandler(spltcnt4Panel2V_Click);
        myMenu4.Items.Add("Horizontal");
        myMenu4.Items[1].Click += new EventHandler(spltcnt4Panel2H_Click);
        myMenu4.Items.Add("Supprimer");
        myMenu4.Items[2].Click += new EventHandler(FormDelete3_Click);
        myMenu4.Items.Add("Supprimer Tout");
        myMenu4.Items[3].Click += new EventHandler(FormDelete_Click);
        spltcnt.Panel2.ContextMenuStrip = myMenu2;
        spltcnt.Panel1.ContextMenuStrip = myMenu1;
        spltcnt1.Panel1.ContextMenuStrip = myMenu3;
        spltcnt1.Panel2.ContextMenuStrip = myMenu3;
        spltcnt2.Panel1.ContextMenuStrip = myMenu4;
        spltcnt2.Panel2.ContextMenuStrip = myMenu4;
        dt.Columns.Add("DATE", typeof(DateTime));
        dt.Columns.Add("NOM", typeof(String));
        dt.Columns.Add("PARENT", typeof(String));
        dt.Columns.Add("PANEL_DECOUPE_NOM", typeof(String));
        dt.Columns.Add("SPLIT_WIDTH", typeof(int));
        dt.Columns.Add("SPLIT_HEIGHT", typeof(int));
        dt.Columns.Add("SPLIT_POSITION", typeof(String));
        dt.Columns.Add("PANEL1_WIDTH", typeof(int));
        dt.Columns.Add("PANEL1_HEIGHT", typeof(int));
        dt.Columns.Add("PANEL2_WIDTH", typeof(int));
        dt.Columns.Add("PANEL2_HEIGHT", typeof(int));
        dt.Columns.Add("PANEL_DISTANCE", typeof(int));
        dt.Columns.Add("ORIENTATION_SPLIT", typeof(String));
        dt.Columns.Add("USERS", typeof(String));
        dt.Rows.Add(new Object[] { DateTime.Now.ToShortDateString(), spltcnt.Name.ToString(),null ,null , spltcnt.Width.ToString()
            , spltcnt.Height.ToString(), spltcnt.Location.ToString(), spltcnt.Panel1.Width.ToString(),spltcnt.Panel1.Height.ToString(),
            spltcnt.Panel2.Width.ToString(),spltcnt.Panel2.Height.ToString(),spltcnt.SplitterDistance.ToString(),spltcnt.Orientation.ToString(),user });
       DataView dtview_alerte = new DataView(dt);
        dataGridView1.DataSource = dtview_alerte;
         }
private void DecoupageVerticalToolStripMenuItem\u单击(对象发送方,事件参数e)
{
con.Open();
splitterPanel1=spltcnt.Panel1;
splitterPanel2=spltcnt.Panel2;
var panels=spltcnt.Controls.OfType();
//SplitContainer spltcnt=新的SplitContainer();
spltcnt.Dock=DockStyle.Left;
spltcnt.Name=“spltcnt”;
spltcnt.Orientation=Orientation.Vertical;
spltcnt.SplitterWidth=4;
spltcnt.Visible=true;
spltcnt.Enabled=true;
spltcnt.BackColor=Color.White;
spltcnt.Size=新系统.Drawing.Size(this.Width,this.Height);
spltcnt.BorderStyle=BorderStyle.Fixed3D;
spltcnt.SplitterDistance=(this.Width)/2;
spltcnt.SplitterIncrement=1;
spltcnt.TabIndex=0;
//SplitContainer spltcnt=新的SplitContainer();
//var panels=spltcnt.Controls.OfType();
//var focusedPanel=panels.FirstOrDefault(p=>p.Controls.OfType()。
//任何(c=>c.Focused));
////SplitContainer sc=sp.父对象作为SplitContainer;
//Show(spltcnt.Name+“-”+panels.ToString());
spltcnt.Panel1.MouseClick+=Panel1OnMouseClick;
spltcnt.Panel2.MouseClick+=Panel2OnMouseClick;
spltcnt1.Panel1.MouseClick+=Panel11OnMouseClick;
spltcnt1.Panel2.MouseClick+=Panel12OnMouseClick;
spltcnt2.Panel1.MouseClick+=Panel21OnMouseClick;
spltcnt2.Panel2.MouseClick+=Panel22OnMouseClick;
spltcnt.MouseClick+=FormOnMouseClick;
控件。添加(spltcnt);
//ContextMenuStrip cm=新的ContextMenuStrip();
//cm.项目。添加(“垂直”);
//cm.项目。添加(“水平”);
//spltcnt.ContextMenuStrip=cm;
ContextMenuStrip myMenu1=新建ContextMenuStrip();
this.ContextMenuStrip=myMenu1;//对于此表单,可以是按钮等。
myMenu1.Items.Add(“Découpage垂直”);
myMenu1.Items[0]。单击+=新建事件处理程序(spltcnt1Panel1V\u单击);
myMenu1.Items.Add(“Découpage横向”);
myMenu1.Items[1]。单击+=新建事件处理程序(spltcnt1Panel1H\u单击);
myMenu1.项目。添加(“Ajout指示符”);
myMenu1.Items[2]。单击+=新建事件处理程序(指示UrPanel1h\u单击);
myMenu1.Items.Add(“供应商兜售”);
myMenu1.Items[3]。单击+=新建事件处理程序(FormDelete\u单击);
//增加了第四项,所以这里的索引是3
ContextMenuStrip myMenu2=新建ContextMenuStrip();
this.ContextMenuStrip=myMenu2;//对于此表单,可以是按钮等。
myMenu2.Items.Add(“Découpage垂直”);
myMenu2.Items[0]。单击+=新建事件处理程序(spltcnt2Panel2V\u单击);
myMenu2.Items.Add(“Découpage横向”);
myMenu2.Items[1]。单击+=新建事件处理程序(spltcnt2Panel2H\u单击);
myMenu2.Items.Add(“Ajout指示符”);
myMenu2.Items[2]。单击+=新建事件处理程序(指示UrPanel2H\u单击);
myMenu2.Items.Add(“供应商兜售”);
myMenu2.Items[3]。单击+=新建事件处理程序(FormDelete\u单击);
//增加了第四项,所以这里的索引是3
ContextMenuStrip myMenu3=新建ContextMenuStrip();
this.ContextMenuStrip=myMenu3;//对于此表单,可以是按钮等。
myMenu3.项目。添加(“垂直”);
myMenu3.Items[0]。单击+=新建事件处理程序(spltcnt3Panel1V\u单击);
myMenu3.项目。添加(“水平”);
myMenu3.Items[1]。单击+=新建事件处理程序(spltcnt3Panel1H\u单击);
myMenu3.项目。添加(“供应商”);
myMenu3.Items[2]。单击+=新建事件处理程序(FormDelete2\u单击);
myMenu3.Items.Add(“供应商兜售”);
myMenu3.Items[3]。单击+=新建事件处理程序(FormDelete\u单击);
//增加了第四项,所以这里的索引是3
ContextMenuStrip myMenu4=新建ContextMenuStrip();
this.ContextMenuStrip=myMenu4;//对于此表单,可以是按钮等。
myMenu4.项目。添加(“垂直”);
myMenu4.Items[0]。单击+=新建事件处理程序(spltcnt4Panel2V\u单击);
myMenu4.项目。添加(“水平”);
myMenu4.Items[1]。单击+=新建事件处理程序(spltcnt4Panel2H\u单击);
myMenu4.项目。添加(“供应商”);
myMenu4.Items[2]。单击+=新建事件处理程序(FormDelete3\u单击);
myMenu4.项目。添加(“供应商兜售”);
myMenu4.Items[3]。单击+=新建事件处理程序(FormDelete\u单击);
spltcnt.Panel2.ContextMenuStrip=myMenu2;
spltcnt.Panel1.ContextMenuStrip=myMenu1;
spltcnt1.Panel1.ContextMenuStrip=myMenu3;
spltcnt1.Panel2.ContextMenuStrip=myMenu3;
spltcnt2.Panel1.ContextMenuStrip=myMenu4;
spltcnt2.Panel2.ContextMenuStrip=myMenu4;
添加(“日期”,类型(日期时间));
添加(“名称”,类型(字符串));
添加(“父”,类型(字符串));
添加(“面板名称”,类型(字符串));
添加(“拆分宽度”,类型(int));
添加(“拆分高度”,类型(int));
dt.Columns.Add(“拆分位置”,类型(字符串));
添加(“面板1_宽度”,类型(int));
dt.列。添加(“面板1_高度”,类型(int));
添加(“面板2_宽度”,类型(int));
dt.列。添加(“面板2_高度”,类型(int));
添加(“面板距离”,类型(int));
dt.Columns.Add(“方向分割”,类型(字符串));
添加(“用户”,类型(字符串));
添加(新对象[]{DateTime.Now.ToSortDateString(),spltcnt.Name.ToString(),null,null,spltcnt.Width.ToString())
,spltcn
private void btnDecouper_Click(object sender, EventArgs e)
    {
        con.Open();
        int rad1 = 0;
        if (radioButton1.Checked == true)
        {
            rad1 = 1;
        }
        else
        {
            rad1 = 0;
        }
        SqlCommand cd = new SqlCommand(" INSERT INTO TDB_COBFIG (NOM,UTILISATEUR,ECRAN_DEFAUT) VALUES (@name,'"+user+"',@ecran)", con);
        cd.Parameters.Clear();
        cd.Parameters.AddWithValue("@name", textBox1.Text);
        cd.Parameters.AddWithValue("@ecran", rad1);
        cd.ExecuteNonQuery();

        int id_tdb = 0;
        SqlDataAdapter tdb = new SqlDataAdapter("SELECT MAX(ID) FROM TDB_COBFIG", con);
        DataSet ds1 = new DataSet();
        tdb.Fill(ds1);
        for (i = 0; i < ds1.Tables[0].Rows.Count; i++)
        {
            int a = Convert.ToInt32(ds1.Tables[0].Rows[i][0].ToString());
            id_tdb = a;
        }
        for (int i = 0; i < dataGridView1.Rows.Count; i++)
        {

        cmd = new SqlCommand(@"INSERT INTO DECOUPAGE (ID_TBD,DATE, NOM, PARENT, PANEL_DECOUPE_NOM, SPLIT_WIDTH, SPLIT_HEIGHT,SPLIT_POSITION,PANEL1_WIDTH,PANEL1_HEIGHT,
            PANEL2_WIDTH,PANEL2_HEIGHT,PANEL_DISTANCE,ORIENTATION_SPLIT,USERS) values( '" + id_tdb+ "','" + DateTime.Now.ToShortDateString() +
            "',@nom,@parent,@paneldec,@splitlong,@splitlarg,@splitp,@panel1w,@panel1h,@panel2w,@panel2h,@splitD,@orientation,@user)", con);
        cmd.Parameters.Clear();
        cmd.Parameters.AddWithValue("@nom", dataGridView1.Rows[i].Cells[1].Value.ToString());
        cmd.Parameters.AddWithValue("@parent", dataGridView1.Rows[i].Cells[2].Value.ToString());
        cmd.Parameters.AddWithValue("@paneldec", dataGridView1.Rows[i].Cells[3].Value.ToString());
        cmd.Parameters.AddWithValue("@splitlong", dataGridView1.Rows[i].Cells[4].Value.ToString());
        cmd.Parameters.AddWithValue("@splitlarg", dataGridView1.Rows[i].Cells[5].Value.ToString());
        cmd.Parameters.AddWithValue("@splitp", dataGridView1.Rows[i].Cells[6].Value.ToString());
        cmd.Parameters.AddWithValue("@panel1w", dataGridView1.Rows[i].Cells[7].Value.ToString());
        cmd.Parameters.AddWithValue("@panel1h", dataGridView1.Rows[i].Cells[8].Value.ToString());
        cmd.Parameters.AddWithValue("@panel2w", dataGridView1.Rows[i].Cells[9].Value.ToString());
        cmd.Parameters.AddWithValue("@panel2h", dataGridView1.Rows[i].Cells[10].Value.ToString());
        cmd.Parameters.AddWithValue("@splitD", dataGridView1.Rows[i].Cells[11].Value.ToString());
         cmd.Parameters.AddWithValue("@orientation", dataGridView1.Rows[i].Cells[12].Value.ToString());
         cmd.Parameters.AddWithValue("@user", dataGridView1.Rows[i].Cells[13].Value.ToString());
        cmd.ExecuteNonQuery();

        }
        MessageBox.Show("Ecran d'accueil Bien Enregistré", "Ajout d'ecran Réussi", MessageBoxButtons.OK, MessageBoxIcon.Information);
        for (int j = 0; j < dataGridView2.Rows.Count; j++)
        {
            SqlCommand cs = new SqlCommand(@"insert into ELEMENT(ID_TBD,NOM,PARENT,LARG,HAUT,PANEL_CONCERNE) VALUES('" + id_tdb + "',@nom,@parent,@larg,@haut,@panel)", con);
            cs.Parameters.Clear();
            cs.Parameters.AddWithValue("@nom", dataGridView2.Rows[j].Cells[0].Value.ToString());
            cs.Parameters.AddWithValue("@parent", dataGridView2.Rows[j].Cells[1].Value.ToString());
            cs.Parameters.AddWithValue("@larg", dataGridView2.Rows[j].Cells[2].Value.ToString());
            cs.Parameters.AddWithValue("@haut", dataGridView2.Rows[j].Cells[3].Value.ToString());
            cs.Parameters.AddWithValue("@panel", dataGridView2.Rows[j].Cells[4].Value.ToString());
            cs.ExecuteNonQuery();
        }
        con.Close();
        Form fm = new Form4(id, user);
        fm.Show();
    }