c#动态表单示例winform文档格式.docx
- 文档编号:19436176
- 上传时间:2023-01-06
- 格式:DOCX
- 页数:28
- 大小:87.08KB
c#动态表单示例winform文档格式.docx
《c#动态表单示例winform文档格式.docx》由会员分享,可在线阅读,更多相关《c#动态表单示例winform文档格式.docx(28页珍藏版)》请在冰豆网上搜索。
publicstaticForm1fm1;
SqlCommandcom;
SqlConnectionconn;
stringlian=Properties.Settings.Default.dongtaiConnectionString;
publicvoidShuaiXin()
try
listBox1.Items.Clear();
conn=newSqlConnection(lian);
com=newSqlCommand("
select*fromtablenames"
conn);
conn.Open();
SqlDataReaderread=com.ExecuteReader();
while(read.Read())
listBox1.Items.Add(read[0]);
label5.Text=listBox1.Items.Count.ToString();
conn.Close();
catch(Exceptionerr)
MessageBox.Show("
操¨
´
作Á
¡
Â
过y程¨
¬
出?
错ä
,ê
误¨
®
提¬
¢
示º
:
ê
o"
+err.Message);
privatevoidlabel1_Click(objectsender,EventArgse)
Application.Exit();
privatevoidlabel2_Click(objectsender,EventArgse)
//this.Hide();
this.WindowState=FormWindowState.Minimized;
this.ShowInTaskbar=false;
privatevoidbutton3_Click(objectsender,EventArgse)
privatevoidbutton4_Click(objectsender,EventArgse)
if(listBox1.SelectedItem==null)
{MessageBox.Show("
您¨
²
未¡
ä
选?
中D任¨
何?
"
"
温?
馨¹
ã
);
return;
if(!
(MessageBox.Show("
确¨
定¡
§
要°
a删¦
除y选?
中D表À
?
"
MessageBoxButtons.OKCancel,MessageBoxIcon.Information)==DialogResult.OK))
for(inti=listBox1.SelectedItems.Count-1;
i>
=0;
i--)
stringlinshi=string.Format("
droptable[{0}]"
listBox1.SelectedItems[i].ToString().Trim());
com=newSqlCommand(linshi,conn);
com.ExecuteNonQuery();
linshi=string.Format("
deletefromtablenameswhere表À
名?
字Á
='
{0}'
listBox1.SelectedItems[i]);
listBox1.Items.Remove(listBox1.SelectedItems[i]);
privatevoidbutton1_Click(objectsender,EventArgse)
Form2fm=newForm2();
fm.Location=newPoint(this.Location.X+179,this.Location.Y+41);
Form1.fm1.Enabled=false;
fm.ShowDialog();
privatevoidbutton2_Click(objectsender,EventArgse)
if(listBox1.SelectedItems.Count!
=1)
只?
能¨
¹
对?
一°
进?
行D操¨
Form3fm=newForm3(listBox1.SelectedItem.ToString().Trim());
fm.Location=newPoint(this.Location.X+179,this.Location.Y+41);
privatevoidbutton5_Click(objectsender,EventArgse)
if(listBox1.SelectedItems.Count==0)
a清?
空?
的Ì
数º
y据Y?
com=newSqlCommand("
TRUNCATETABLE["
+listBox1.SelectedItems[i].ToString()+"
]"
//sql语®
句?
清?
PointAA=newPoint();
privatevoidpanel1_MouseMove(objectsender,MouseEventArgse)
if(e.Button==MouseButtons.Left)
this.Location=newPoint(MousePosition.X-AA.X,MousePosition.Y-AA.Y);
privatevoidpanel1_MouseDown(objectsender,MouseEventArgse)
{AA=newPoint(e.X,e.Y);
privatevoidnotifyIcon1_MouseDown(objectsender,MouseEventArgse)
if(this.WindowState==FormWindowState.Normal)
//this.Hide();
else
this.WindowState=FormWindowState.Normal;
this.ShowInTaskbar=true;
//this.Show();
;
privatevoid显?
窗ä
体¬
ToolStripMenuItem_Click(objectsender,EventArgse)
privatevoid隐°
t藏?
privatevoid关?
闭À
privatevoidlabel6_Click(objectsender,EventArgse)
if(label6.Text=="
△¡
"
)
label6.Text="
▽§
;
this.Height=35;
this.Height=576;
privatevoidlistBox1_MouseDoubleClick(objectsender,MouseEventArgse)
button2_Click(null,null);
}
Form2.cs代码
publicpartialclassForm2:
publicForm2()
intsm;
Label[]lab1;
Label[]lab2;
TextBox[]tex1;
ComboBox[]comb;
this.Close();
if(textBox1.Text=="
||textBox2.Text=="
0"
请?
填¬
写¡
完ª
º
整?
信?
息¡
é
录?
入¨
y目?
必À
须?
大ä
于®
{int.Parse(textBox2.Text);
catch(Exceptionerr)
输º
有®
D误¨
!
为a数º
y字Á
系¦
Ì
统ª
3错ä
:
+err.Message,"
conn=newSqlConnection(lian);
boolflag=false;
if(read[0].ToString().Trim().ToLower()==textBox1.Text.Trim().ToLower())
称?
D重?
复¡
flag=true;
break;
if(flag)
sm=Convert.ToInt32(textBox2.Text.Trim());
lab1=newLabel[sm];
lab2=newLabel[sm];
tex1=newTextBox[sm];
comb=newComboBox[sm];
Point[]poi=newPoint[4]{newPoint(21,9),newPoint(128,9),newPoint(263,9),newPoint(351,9),};
panel4.Controls.Clear();
for(inti=0;
i<
sm;
i++)
lab1[i]=newLabel();
lab1[i].Text="
列¢
D名?
+(i+1).ToString()+"
lab1[i].Location=poi[0];
tex1[i]=newTextBox();
tex1[i].Location=poi[1];
lab2[i]=newLabel();
lab2[i].Text="
y据Y类¤
型¨
lab2[i].Location=poi[2];
string[]liexing=newstring[]{"
int<
y>
float<
小?
datetime<
日¨
期¨
>
nvarchar(MAX)<
任¨
意°
a字Á
符¤
};
comb[i]=newComboBox();
comb[i].Location=poi[3];
comb[i].Items.AddRange(liexing);
comb[i].SelectedIndex=0;
comb[i].Size=newSize(150,20);
comb[i].DropDownStyle=ComboBoxStyle.DropDownList;
poi[0]=newPoint(21,poi[0].Y+36);
poi[1]=newPoint(128,poi[1].Y+36);
poi[2]=newPoint(263,poi[2].Y+36);
poi[3]=newPoint(351,poi[3].Y+36);
panel4.Controls.Add(comb[i]);
panel4.Controls.Add(lab1[i]);
panel4.Controls.Add(tex1[i]);
panel4.Controls.Add(lab2[i]);
panel3.Enabled=true;
panel1.Enabled=false;
tex1[0].Focus();
intlishi=0;
stringformat1="
createtable["
+textBox1.Text.Trim()+"
]([ID]intNOTNULLIDENTITY(1,1)PRIMARYKEY,"
if(tex1[i].Text=="
段?
不?
为a空?
lishi=0;
for(intj=0;
j<
j++)
if(tex1[i].Text.Trim().ToLower()==tex1[j].Text.Trim().ToLower())
lishi++;
if(lishi>
1)
format1=format1+"
["
+tex1[i].Text.Trim()+"
]"
+comb[i].Text.Remove(comb[i].Text.IndexOf('
<
'
)).Trim()+"
format1=format1.Remove(format1.Length-1)+"
)"
com=newSqlCommand(format1,conn);
insertintotablenamesvalues('
创ä
建¡
成¨
¦
功|"
Form1.fm1.ShuaiXin();
panel3.Enabled=false;
panel1.Enabled=true;
+err.Message,"
}
privatevoidForm2_FormClosing(objectsender,FormClosingEventArgse)
Form1.fm1.Enabled=true;
Form3.cs
publicpartialclassForm3:
stringtable;
string[]lieM;
SqlDataAdapteradap;
SqlCommandBuildercombu;
DataTabletable1
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- c# 动态 表单 示例 winform