我有一个拆分容器,我在这个拆分中添加了 2 个按钮。将其保存在 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 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();
}