c#动态表单示例winform.docx

上传人:b****6 文档编号:6423564 上传时间:2023-01-06 格式:DOCX 页数:28 大小:87.08KB
下载 相关 举报
c#动态表单示例winform.docx_第1页
第1页 / 共28页
c#动态表单示例winform.docx_第2页
第2页 / 共28页
c#动态表单示例winform.docx_第3页
第3页 / 共28页
c#动态表单示例winform.docx_第4页
第4页 / 共28页
c#动态表单示例winform.docx_第5页
第5页 / 共28页
点击查看更多>>
下载资源
资源描述

c#动态表单示例winform.docx

《c#动态表单示例winform.docx》由会员分享,可在线阅读,更多相关《c#动态表单示例winform.docx(28页珍藏版)》请在冰豆网上搜索。

c#动态表单示例winform.docx

c#动态表单示例winform

c#动态表单示例(winform)

源代码打包下载

Form1.cs代码

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Data.SqlClient;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.Runtime.InteropServices;

namespace动¡¥态¬?

表À¨ª单Ì£¤

{

publicpartialclassForm1:

Form

{

publicForm1()

{

InitializeComponent();

fm1=this;

ShuaiXin();

}

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)

{

ShuaiXin();

}

privatevoidbutton4_Click(objectsender,EventArgse)

{

if(listBox1.SelectedItem==null)

{MessageBox.Show("您¨²未¡ä选?

中D任¨?

何?

表À¨ª单Ì£¤","温?

馨¹¡ã提¬¨¢示º?

");

return;

}

if(!

(MessageBox.Show("您¨²确¨¡¤定¡§要°a删¦?

除y选?

中D表À¨ª单Ì£¤?

ê?

","温?

馨¹¡ã提¬¨¢示º?

",MessageBoxButtons.OKCancel,MessageBoxIcon.Information)==DialogResult.OK))

return;

for(inti=listBox1.SelectedItems.Count-1;i>=0;i--)

{

try

{

conn.Open();

stringlinshi=string.Format("droptable[{0}]",listBox1.SelectedItems[i].ToString().Trim());

com=newSqlCommand(linshi,conn);

com.ExecuteNonQuery();

linshi=string.Format("deletefromtablenameswhere表À¨ª单Ì£¤名?

字Á?

='{0}'",listBox1.SelectedItems[i]);

com=newSqlCommand(linshi,conn);

com.ExecuteNonQuery();

conn.Close();

listBox1.Items.Remove(listBox1.SelectedItems[i]);

}

catch(Exceptionerr)

{

MessageBox.Show("操¨´作Á¡Â过y程¨¬出?

错䨪,ê?

错䨪误¨®提¬¨¢示º?

êo"+err.Message);

}

}

label5.Text=listBox1.Items.Count.ToString();

}

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.SelectedItem==null)

{

MessageBox.Show("您¨²未¡ä选?

中D任¨?

何?

表À¨ª单Ì£¤","温?

馨¹¡ã提¬¨¢示º?

");

return;

}

if(listBox1.SelectedItems.Count!

=1)

{

MessageBox.Show("您¨²只?

能¨¹对?

单Ì£¤一°?

表À¨ª单Ì£¤进?

行D操¨´作Á¡Â","温?

馨¹¡ã提¬¨¢示º?

");

return;

}

Form3fm=newForm3(listBox1.SelectedItem.ToString().Trim());

fm.Location=newPoint(this.Location.X+179,this.Location.Y+41);

Form1.fm1.Enabled=false;

fm.ShowDialog();

}

privatevoidbutton5_Click(objectsender,EventArgse)

{

if(listBox1.SelectedItems.Count==0)

{

MessageBox.Show("您¨²未¡ä选?

中D任¨?

何?

表À¨ª单Ì£¤","温?

馨¹¡ã提¬¨¢示º?

");

return;

}

if(!

(MessageBox.Show("您¨²确¨¡¤定¡§要°a清?

空?

选?

中D表À¨ª单Ì£¤的Ì?

数ºy据Y?

ê?

","温?

馨¹¡ã提¬¨¢示º?

",MessageBoxButtons.OKCancel,MessageBoxIcon.Information)==DialogResult.OK))

return;

for(inti=listBox1.SelectedItems.Count-1;i>=0;i--)

{

try

{

com=newSqlCommand("TRUNCATETABLE["+listBox1.SelectedItems[i].ToString()+"]",conn);//sql语®?

句?

清?

空?

表À¨ª

conn.Open();

com.ExecuteNonQuery();

conn.Close();

}

catch(Exceptionerr)

{

MessageBox.Show("操¨´作Á¡Â过y程¨¬出?

错䨪,ê?

错䨪误¨®提¬¨¢示º?

êo"+err.Message);

}

}

}

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)

{

if(e.Button==MouseButtons.Left)

{AA=newPoint(e.X,e.Y);}

}

privatevoidnotifyIcon1_MouseDown(objectsender,MouseEventArgse)

{

if(e.Button==MouseButtons.Left)

{

if(this.WindowState==FormWindowState.Normal)

{

this.WindowState=FormWindowState.Minimized;

this.ShowInTaskbar=false;

//this.Hide();

}

else

{

this.WindowState=FormWindowState.Normal;

this.ShowInTaskbar=true;

//this.Show();;

}

}

}

privatevoid显?

示º?

窗ä¡ã体¬?

ToolStripMenuItem_Click(objectsender,EventArgse)

{

this.WindowState=FormWindowState.Normal;

this.ShowInTaskbar=true;

}

privatevoid隐°t藏?

窗ä¡ã体¬?

ToolStripMenuItem_Click(objectsender,EventArgse)

{

this.WindowState=FormWindowState.Minimized;

this.ShowInTaskbar=false;

}

privatevoid关?

闭À?

ToolStripMenuItem_Click(objectsender,EventArgse)

{

Application.Exit();

}

privatevoidlabel6_Click(objectsender,EventArgse)

{

if(label6.Text=="△¡Â")

{

label6.Text="▽§?

";

this.Height=35;

this.ShowInTaskbar=false;

}

else

{

label6.Text="△¡Â";

this.Height=576;

this.ShowInTaskbar=true;

}

}

privatevoidlistBox1_MouseDoubleClick(objectsender,MouseEventArgse)

{

if(e.Button==MouseButtons.Left)

{

button2_Click(null,null);

}

}

}

}

Form2.cs代码

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Data.SqlClient;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows.Forms;

namespace动¡¥态¬?

表À¨ª单Ì£¤

{

publicpartialclassForm2:

Form

{

publicForm2()

{

InitializeComponent();

}

SqlCommandcom;

SqlConnectionconn;

stringlian=Properties.Settings.Default.dongtaiConnectionString;

intsm;

Label[]lab1;

Label[]lab2;

TextBox[]tex1;

ComboBox[]comb;

privatevoidlabel1_Click(objectsender,EventArgse)

{

this.Close();

}

privatevoidbutton1_Click(objectsender,EventArgse)

{

if(textBox1.Text==""||textBox2.Text==""||textBox2.Text=="0")

{

MessageBox.Show("请?

填¬?

写¡ä完ª¨º整?

信?

息¡é录?

入¨?

信?

息¡é数ºy目?

必À?

须?

大䨮于®¨²0","温?

馨¹¡ã提¬¨¢示º?

");

return;

}

try

{int.Parse(textBox2.Text);}

catch(Exceptionerr)

{

MessageBox.Show("输º?

入¨?

有®D误¨®!

ê?

录?

入¨?

信?

息¡é数ºy目?

必À?

须?

为a数ºy字Á?

ê?

系¦Ì统ª3错䨪误¨®提¬¨¢示º?

:

"+err.Message,"温?

馨¹¡ã提¬¨¢示º?

");

return;

}

conn=newSqlConnection(lian);

com=newSqlCommand("select*fromtablenames",conn);

conn.Open();

SqlDataReaderread=com.ExecuteReader();

boolflag=false;

while(read.Read())

{

if(read[0].ToString().Trim().ToLower()==textBox1.Text.Trim().ToLower())

{

MessageBox.Show("输º?

入¨?

有®D误¨®!

ê?

表À¨ª单Ì£¤名?

称?

有®D重?

复¡ä","温?

馨¹¡ã提¬¨¢示º?

");

flag=true;

break;

}

}

if(flag)

{

conn.Close();

return;

}

conn.Close();

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

{

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类¤¨¤型¨ª:

êo";

lab2[i].Location=poi[2];

string[]liexing=newstring[]{"int<整?

数ºy>","float<小?

数ºy>","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();

}

privatevoidbutton2_Click(objectsender,EventArgse)

{

try

{

intlishi=0;

stringformat1="createtable["+textBox1.Text.Trim()+"]([ID]intNOTNULLIDENTITY(1,1)PRIMARYKEY,";

for(inti=0;i

{

if(tex1[i].Text=="")

{

MessageBox.Show("表À¨ª单Ì£¤字Á?

段?

列¢D名?

不?

能¨¹为a空?

","温?

馨¹¡ã提¬¨¢示º?

");

return;

}

lishi=0;

for(intj=0;j

{

if(tex1[i].Text.Trim().ToLower()==tex1[j].Text.Trim().ToLower())

lishi++;

}

if(lishi>1)

{

MessageBox.Show("表À¨ª单Ì£¤字Á?

段?

列¢D名?

有®D重?

复¡ä","温?

馨¹¡ã提¬¨¢示º?

");

break;

}

format1=format1+"["+tex1[i].Text.Trim()+"]"+comb[i].Text.Remove(comb[i].Text.IndexOf('<')).Trim()+",";

}

if(lishi>1)

return;

format1=format1.Remove(format1.Length-1)+")";

conn.Open();

com=newSqlCommand(format1,conn);

com.ExecuteNonQuery();

com=newSqlCommand("insertintotablenamesvalues('"+textBox1.Text.Trim()+"')",conn);

com.ExecuteNonQuery();

conn.Close();

MessageBox.Show("表À¨ª单Ì£¤创ä¡ä建¡§成¨¦功|","温?

馨¹¡ã提¬¨¢示º?

");

Form1.fm1.ShuaiXin();

panel3.Enabled=false;

panel1.Enabled=true;

this.Close();

}

catch(Exceptionerr)

{

conn.Close();

MessageBox.Show("创ä¡ä建¡§表À¨ª单Ì£¤出?

错䨪,ê?

错䨪误¨®提¬¨¢示º?

êo"+err.Message,"温?

馨¹¡ã提¬¨¢示º?

");

}

}

privatevoidbutton3_Click(objectsender,EventArgse)

{

panel3.Enabled=false;

panel1.Enabled=true;

panel4.Controls.Clear();

}

privatevoidForm2_FormClosing(objectsender,FormClosingEventArgse)

{

Form1.fm1.Enabled=true;

}

}

}

Form3.cs

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Data.SqlClient;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows.Forms;

namespace动¡¥态¬?

表À¨ª单Ì£¤

{

publicpartialclassForm3:

Form

{

stringtable;

stringlian=Properties.Settings.Default.dongtaiConnectionString;

string[]lieM;

SqlDataAdapteradap;

SqlConnectionconn;

SqlCommandBuildercombu;

DataTabletable1

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试认证 > 其它考试

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1