《窗体设计源代码》由会员分享,可在线阅读,更多相关《窗体设计源代码(11页珍藏版)》请在金锄头文库上搜索。
1、OpenFileDialog dlg = new OpenFileDialog();dlg.Filter = (*.mdb)|*.mdb;dlg.Multiselect = false;if (dlg.ShowDialog() = DialogResult.OK)fileName = dlg.FileName;MessageBox.Show(已连接上数据库!路径:+ fileName + ,” 提示:,MessageBoxButtons.OK, MessageBoxIcon.Information);string connString = Provider=Microsoft.Jet.OLED
2、B.4.0;Data source= + fileName;OleDbConnection conn = new OleDbConnection(connString);conn.Open();DataSet ds = new DataSet();/string sql = select * from + table;OleDbDataAdapter oda = new OleDbDataAdapter(Select * from 考勤记录, conn);oda.Fill(ds, 考勤记录);conn.Close();/ return ds;dataGridViewl.DataSource =
3、 ds.Tables考勤记录Applica tion.Exi t();/退出系统t his.Cursor = Cursors.Hand; /鼠标形状变化if (this.WindowState = FormWindowState.Maximized) this.WindowState = FormWindowState. Normal ; elsethis.WindowState = FormWindowState. Maximized; using System.Runtime.InteropServices;private const int WM_NCLBUTTONDOWN = OxAl
4、;/窗体拖拽 private const int HTCAPTION = 2;DllImport(user32.dll, EntryPoint = SendMessageA)private static extern int SendMessage(int hwnd, int wMsg, int wParam, int lParam);DllImport(user32.dll)private static extern int ReleaseCapture();private void panel1_MouseDown_1(object sender, MouseEventArgs e) /为
5、当前的应用程序释放鼠标捕获ReleaseCapture(); /发送消息,让系统误以为你在标题拦上按下鼠标SendMessage(int)this.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0); EventArgs e)/将数据表导入Excel中Using Excel /使用该命名空间 private void buttonl_Click(object sender, 的方法trystring toExcelFileName =竞聘+ comboBox1.SelectedItem.ToString() +综合成绩;System.Data. DataTable
6、toExcelDataTable = dsToExcel.Tables考生成绩; string toExcelName = 竞聘 + comboBox1.SelectedItem.ToString() + 综合 成绩;ExportToExcel(toExcelFileName, toExcelDataTable, toExcelName);catch MessageBox.Show(导出信息不能为空!,警告:, MessageBoxButtons.OK, MessageBoxIcon. Exclamation );private void pictureBox4_Click(object se
7、nder, EventArgs e) this.Close();this.Cursor = Cursors.Hand; pictureBox4.Image = pictureBox1.Image;private void pictureBox4_MouseLeave(object sender, EventArgs e) pictureBox4.Image = pictureBox2.Image; this.Cursor = Cursors.Default;Even tArgs e)/将数据导入记事本中using Sys tem.IO;/使用该命名空间private void btnRtoTx
8、t_Click(object sender, (listbox)SaveFileDialog saveDlg = new SaveFileDialog(); saveDlg.Filter = Txt files(*.txt)|*.txt|All files(*.*)|*.*;saveDlg.FilterIndex = 0;if (saveDlg.ShowDialog() = DialogResult.OK)StreamWriter sw = new StreamWriter(saveDlg.FileName); foreach (string s in listBox3.Items)sw.Wr
9、ite(s);sw. Write(System. Environment. NewLine);sw.Close();MessageBox.Show(导出到TXT成功!, 导出成功,MessageBoxButtons. OK, MessageBoxIcon. Information);StreamWriter outputStream = File.CreateText(d:zdh. txt); / 往记事本中与入文本 outputStream.WriteLine(textBox1 .Text ); outputStream.Close();StreamReader inputStream =
10、File.OpenText(C:/zdh. txt);/从记事本中读出文本 string line;line = inputStream.ReadLine();while (line != null)textBox1.AppendText(line + rn); line = inputStream.ReadLine(); inputStream.Close();e)/窗体2先显示然后窗体1再显using Sys tem.Threading;/要使用该名称空间 private void Forml_Load(object sender, EventArgs 示Form2 f2 = new Fo
11、rm2(); f2.Show();f2.Update();for (int i = 0; i = 100; i+)Thread.Sleep(15);/两窗体显示间隔的时间f2.Close();e) /工具箱显private void pictureBox10_MouseClick(object sender, MouseEventArgs示与隐藏(尺寸可以根据情况设定、窗体位置、窗体大小)if (tabControl1.Visible = true)panel4.Left=25; panel4.Width = (this.Width-25-12); /this.width 是FrMain窗体的
12、宽度, 25是t abCon trol 1离窗体左边界的距离,12是panel4离窗体右边界的距离 pictureBox10.Image = pictureBox12.Image;tabControl1.Hide();elsepanel4.Width = (this.Width - 25 - tabControl1.Width - 6 - 12);/6是 tabCon trol1的左边界离panel4的右边界的距离即两控件间的间距panel4.Left = 252;pictureBox10.Image = pictureBox11.Image;tabControl1.Show();/填充下拉列
13、表comboBox1.Items.Clear();string connstring=user id=user402;data source=gisdb;password=u402 ;OracleConnection conn = new OracleConnection(connstring); conn.Open();DataSet ds = new DataSet(); string sql = select * from 表三; OracleDataAdapter da = new OracleDataAdapter(sql ,conn);da.Fill(ds,表三“); conn.C
14、lose();Dat aRowCollec tion t ablesRow = ds.Tables表三.Rows;Dat aColumnCollec tion t ableCol = ds.Tables表三.Columns;for (int i = 0; i tablesRow.Count; i+)comboBox1. Items. Add (ds. Tables 表三 . Rows i 姓名 . ToString() ) ;TreeNode newNode = new TreeNode(Text for new node)/添加树子节点 treeView1.SelectedNode.Node
15、s.Add(newNode);treeViewl.Nodes.Remove(treeViewl.SelectedNode); /删除树节点ToolTip tp = new ToolTip();/将鼠标移到某控件上时显示相应的文本信息tp.SetToolTip(this.button1, dfdf);private string InputBox(string Caption, string Hint, string Default)/ Form InputForm = new Form(); InputForm.Icon = null;InputForm.MinimizeBox = false ;InputForm.MaximizeBox = false ; InputForm.StartPosition = FormStartPosition.CenterScreen; I