C# textBox1.Text=““与textBox1.Clear()的区别

一、区别

        textbox.Text = "" 和 textbox.Clear() 都可以用于清空文本框的内容,但它们之间有一些细微的区别。


        textbox.Text = "": 这种方式会将文本框的 Text 属性直接设置为空字符串。这样会立即清除文本框的内容,并将文本框显示为空。这个操作是同步的,不会引起延迟。但需要注意的是,如果使用绑定或者其他方式来设置文本框的值,这种方式可能不会触发相应的事件或绑定的更新。


        textbox.Clear(): 这种方式是使用 Clear() 方法来清空文本框的内容。Clear() 方法会将文本框中的所有文本清除,并将文本框显示为空。与 textbox.Text = "" 相比,Clear() 方法更为直观,并且在清除文本框内容时不会影响其他与文本框相关的属性或事件。


        如果只是简单地清空文本框的内容,两种方式都可以使用。如果想要一个更直观和简洁的方式来清空文本框,并且不需要考虑与其他属性或事件的影响,那么推荐使用 textbox.Clear() 方法。

        严格地说textbox.text=""比textbox.clear()更节省资源,因为它只管字符,而clear还有其它的复位工作。但这个差异微乎其微,就如你吃饭,吃一粒米和吃两粒米,对你的肚子(电脑)有影响有多大呢?

二、重影

        在线程异步中使用textBox1.text="",并不会一次性清除所有字符,特别是多行的情况下,如果另一个方法再次使用异步进行写入的话,会发现:好像只清除了前面几行,后面几行看似是字符不断进行覆盖写入的效果,有点重影效果。下面同步使用的txtbox.text="",其它用的是clear(),对比一下效果:

   

 

        在有结果时,使用同步(用的textbox1.text="")逐个追加字符时,好象有重影。原因就是延迟造成。

        延迟现象是由于UI线程和更新文本框的操作之间的异步处理导致的。
        在UI应用程序中,UI线程负责处理用户交互和界面更新。当使用txtInfo.Text = ""将文本框的Text属性设置为空字符串时,实际上是将更新文本框的操作加入到UI线程的消息队列中,等待UI线程处理。
        然而,UI线程在处理消息队列时,可能会有其他的任务或操作正在进行,例如更新其他控件、响应用户输入等。这些任务可能会占用UI线程的时间,导致更新文本框的操作被延迟执行。
因此,在延迟期间,可能会看到文本框逐个覆盖掉字符串的效果,因为部分文本被清除,然后新的文本逐渐填充进去。这是因为清除文本和显示新的文本是分开的操作,它们在UI线程中按顺序执行。
        为了避免延迟现象,可以使用txtInfo.Clear()方法,它会直接清除文本框的内容,而不需要等待UI线程处理消息队列。这样可以立即清除所有文本内容,而不会出现逐个覆盖的效果。
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
什么好玩做什么 namespace WindowsFormsApplication1 { public partial class Form1 : Form { Double first = 0; String second = null; int code = 0; String result = null; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button(String sender) { if (result != null) { textBox1.Clear(); } if (code != 0 && second == null) { textBox1.Clear(); } String b = sender; if (textBox1.Text == null || textBox1.Text == "") { textBox1.Text = b; } else { textBox1.Text = textBox1.Text + b; } if (code != 0) { second = textBox1.Text; } result = null; label1.Focus(); } private void button1_Click(object sender, EventArgs e) { button("1"); } private void button2_Click(object sender, EventArgs e) { button("2"); } private void button3_Click(object sender, EventArgs e) { button("3"); } private void button4_Click(object sender, EventArgs e) { button("4"); } private void button5_Click(object sender, EventArgs e) { button("5"); } private void button6_Click(object sender, EventArgs e) { button("6"); } private void button7_Click(object sender, EventArgs e) { button("7"); } private void button8_Click(object sender, EventArgs e) { button("8"); } private void button9_Click(object sender, EventArgs e) { button("9"); } private void button10_Click(object sender, EventArgs e) { if (textBox1.Text == null || textBox1.Text == "") { button("0"); }else if (Convert.ToDouble(textBox1.Text) != 0) { button("0"); }else if (textBox1.Text.IndexOf(".") == 1) { button("0"); } label1.Focus(); } private void button11_Click(object sender, EventArgs e) { if (second == null) { MessageBox.Show("哥们你要算什么啊?麻烦再输入数!"); } else if (Convert.ToDouble(second) == 0 && first != 0 && code == 4) { textBox1.Text = "除数不能为零!"; } else { switch (code) { case 1: textBox1.Text = Convert.ToString(first + Convert.ToDouble(textBox1.Text)); break; case 2: textBox1.Text = Convert.ToString(first - Convert.ToDouble(textBox1.Text)); break; case 3: textBox1.Text = Convert.ToString(first * Convert.ToDouble(textBox1.Text)); break; case 4: textBox1.Text = Convert.ToString(first / Convert.ToDouble(textBox1.Text)); break; } } first = 0; second = null; code = 0; result = textBox1.Text; label1.Focus(); } private void button12_Click(object sender, EventArgs e) { if (Convert.ToDouble(textBox1.Text) != 0 || textBox1.Text == null || textBox1.Text == "") { button("00"); } else if (textBox1.Text.IndexOf(".") == 1) { button("00"); } label1.Focus(); } private void button17_Click(object sender, EventArgs e) { if (textBox1.Text.IndexOf(".") < 1) { button("."); } label1.Focus(); } private void button_2() { if (textBox1.Text == null || textBox1.Text == "") { first = 0; } else if (first == 0) { first = Convert.ToDouble(textBox1.Text); } } private void button18_Click(object sender, EventArgs e) { button_2(); code = 4; label1.Focus(); } private void button13_Click(object sender, EventArgs e) { button_2(); code = 2; label1.Focus(); } private void button14_Click(object sender, EventArgs e) { button_2(); code = 3; label1.Focus(); } private void button15_Click(object sender, EventArgs e) { button_2(); code = 1; label1.Focus(); } private void button16_Click(object sender, EventArgs e) { textBox1.Clear(); label1.Focus(); } private void Form1_KeyUp(object sender, KeyEventArgs e) { //MessageBox.Show(Convert.ToString(e.KeyCode)); if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Oemplus) { button11_Click(null, null); } else if (e.KeyCode == Keys.Divide || e.KeyCode == Keys.OemQuestion) { button18_Click(null, null); } else if (e.KeyCode == Keys.Add || e.KeyCode == Keys.Oemplus) { button15_Click(null, null); } else if (e.KeyCode == Keys.Multiply) { button14_Click(null, null); } else if (e.KeyCode == Keys.Subtract || e.KeyCode == Keys.OemMinus) { button13_Click(null, null); } else if (e.KeyCode == Keys.OemPeriod || e.KeyCode == Keys.Delete) { button17_Click(null, null); } else if (e.KeyCode == Keys.Oemtilde) { button12_Click(null, null); } else if (e.KeyCode == Keys.D1 || e.KeyCode == Keys.NumPad1) { button1_Click(null, null); } else if (e.KeyCode == Keys.D2 || e.KeyCode == Keys.NumPad2) { button2_Click(null, null); } else if (e.KeyCode == Keys.D3 || e.KeyCode == Keys.NumPad3) { button3_Click(null, null); } else if (e.KeyCode == Keys.D4 || e.KeyCode == Keys.NumPad4) { button4_Click(null, null); } else if (e.KeyCode == Keys.D5 || e.KeyCode == Keys.NumPad5) { button5_Click(null, null); } else if (e.KeyCode == Keys.D6 || e.KeyCode == Keys.NumPad6) { button6_Click(null, null); } else if (e.KeyCode == Keys.D7 || e.KeyCode == Keys.NumPad7) { button7_Click(null, null); } else if (e.KeyCode == Keys.D8 || e.KeyCode == Keys.NumPad8) { button8_Click(null, null); } else if (e.KeyCode == Keys.D9 || e.KeyCode == Keys.NumPad9) { button9_Click(null, null); } else if (e.KeyCode == Keys.D0 || e.KeyCode == Keys.NumPad0) { button10_Click(null, null); } } private void textBox1_Enter(object sender, EventArgs e) { label1.Focus(); } } }
namespace StopWatch { public partial class Form2 : Form { DateTime examtime; DateTime nowtime; DateTime t = DateTime.Now; int add = 0; public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { timer1.Enabled = false; examtime = new DateTime(1, 1, 1, 0,0, 0); labTime.Text = "0" + examtime.ToLongTimeString(); if (t.Hour < 10) labT.Text = "0" + DateTime.Now.ToLongTimeString(); else labT.Text = DateTime.Now.ToLongTimeString(); } private void button2_Click(object sender, EventArgs e) { if (add < 1 ) { starttime(); } else { MessageBox.Show("记录已满,请清除记录后再开始记录!"); } } private void button1_Click(object sender, EventArgs e) { if (timer1.Enabled != false) { Add(); } if (add >= 5) { MessageBox.Show("对不起!最多只能记录4条!!"); timer1.Enabled = false; } } private void button3_Click(object sender, EventArgs e) { ClearTime(); add = 0 - 1; Add(); stoptime(); } private void button4_Click(object sender, EventArgs e) { Application.Exit(); } private void timer1_Tick(object sender, EventArgs e) { examtime = examtime.AddSeconds(1); if (examtime.Hour < 10) labTime.Text = "0" + examtime.ToLongTimeString(); else labTime.Text = examtime.ToLongTimeString(); } private void timer2_Tick(object sender, EventArgs e) { if(t.Hour<10) labT.Text = "0"+DateTime.Now.ToLongTimeString(); else labT.Text = DateTime.Now.ToLongTimeString();nowtime = nowtime.AddSeconds(1); } private void Add() { add = add + 1; switch (add) { case 1: textBox1.Text = "0" + examtime.ToLongTimeString(); timer1.Enabled = true; break; case 2: textBox2.Text = "0" + examtime.ToLongTimeString(); timer1.Enabled = true; break; case 3: textBox3.Text = "0" + examtime.ToLongTimeString(); timer1.Enabled = true; break; case 4: textBox4.Text = "0" + examtime.ToLongTimeString(); Program.hash.add(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text); timer1.Enabled = true; timer1.Enabled = false; break; case 5: default: break; } } private void ClearTime() { examtime = new DateTime(1, 1, 1, 0, 0, 0); labTime.Text = "0" + examtime.ToLongTimeString(); textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); textBox1.Text = "0" + examtime.ToLongTimeString(); textBox2.Text = "0" + examtime.ToLongTimeString(); textBox3.Text = "0" + examtime.ToLongTimeString(); textBox4.Text = "0" + examtime.ToLongTimeString(); timer1.Enabled = false; } private void starttime() { timer1.Enabled = true; } private void stoptime() { timer1.Enabled = false; } private void textBox1_TextChanged(object sender, EventArgs e) { } private void textBox2_TextChanged(object sender, EventArgs e) { } private void textBox3_TextChanged(object sender, EventArgs e) { } private void textBox4_TextChanged(object sender, EventArgs e) { } private void pictureBox1_Click(object sender, EventArgs e) { } private void textBox5_TextChanged(object sender, EventArgs e) { } private void labTime_Click(object sender, EventArgs e) { } private void timeshow_Click(object sender, EventArgs e) { Form3 frm = new Form3(); frm.Show(); } } }
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Xml; using System.Text.RegularExpressions; using System.Security.Cryptography; using System.Security.Cryptography.Xml; using System.Xml.Serialization; namespace PinTu { public partial class Form1 : Form { #region 全局变量 Image im; Bitmap bm; Bitmap empt; ArrayList arrrect = new ArrayList(); //ArrayList emptpt = new ArrayList(); ArrayList arrpic = new ArrayList(); //ArrayList change = new ArrayList(); PictureBox[] pb; Random rand = new Random(); int Picsize; int gzs; int bushu = 0; int bu = 0; int[] a; int[] b; bool isfirst = true; bool canclick = true; string filename = ""; string juhao = ""; string change = ""; Bitmap bmpg; #endregion public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { button4.Enabled = false; label2.Text = ""; label4.Text = ""; filename = "Autumn.jpg"; int tempi = rand.Next(1, 1001); Readinfo(tempi.ToString()); textBox1.Text = tempi.ToString(); } private void Creatpic(int[] inta) { panel1.Controls.Clear(); im = Image.FromFile(filename); bm = new Bitmap(320, 320); Graphics gg = Graphics.FromImage(bm); gg.DrawImage(im, new Rectangle(0, 0, 320, 320)); panel2.BackgroundImage = im; pb = new PictureBox[gzs * gzs]; for (int i = 0; i < gzs * gzs; i++) { pb[i] = new PictureBox(); pb[i].Parent = panel1; pb[i].Size = new Size(Picsize, Picsize); pb[i].Location = new Point((i % gzs) * Picsize, (i / gzs) * Picsize); pb[i].BorderStyle = BorderStyle.FixedSingle; pb[i].Name = a[i].ToString(); pb[i].SizeMode = PictureBoxSizeMode.CenterImage; Bitmap bmp = new Bitmap(Picsize, Picsize); Graphics g = Graphics.FromImage(bmp); g.DrawImage(bm, new Rectangle(0, 0, Picsize, Picsize), (Rectangle)arrrect[inta[i]], GraphicsUnit.Pixel); pb[i].Image = bmp; pb[i].Click += new EventHandler(Picture_Click); if (a[i] == gzs * gzs - 1) { empt = bmp; //pb[i].Image = null; //pb[i].BackColor = Color.Blue; Image img = pb[i].Image; bmpg = new Bitmap(img); for (int k = 0; k < bmpg.Width; k++) { for (int j = 0; j < bmpg.Height; j++) { Color bmpcolor = bmpg.GetPixel(k, j); byte A = bmpcolor.A; byte R = bmpcolor.R; byte G = bmpcolor.G; byte B = bmpcolor.B; bmpcolor = Color.FromArgb(128, R, G, B); bmpg.SetPixel(k, j, bmpcolor); } } pb[i].Image = bmpg; } } } private void Picture_Click(object sender, EventArgs e) { if (canclick == false) return; PictureBox pbox = (PictureBox)sender; if (pbox.Image == null) return; Point opt = pbox.Location; Point ptleft = new Point(opt.X - Picsize, opt.Y); Point ptright = new Point(opt.X + Picsize, opt.Y); Point ptup = new Point(opt.X, opt.Y - Picsize); Point ptdown = new Point(opt.X, opt.Y + Picsize); foreach (PictureBox p in panel1.Controls) { if (p.Location == ptleft && p.Image == bmpg) { change += pbox.Name + "$" + p.Name + "|"; pbox.Location = ptleft; p.Location = opt; bushu++; textBox1.Enabled = false; button1.Enabled = false; } if (p.Location == ptright && p.Image == bmpg) { change += pbox.Name + "$" + p.Name + "|"; pbox.Location = ptright; p.Location = opt; bushu++; textBox1.Enabled = false; button1.Enabled = false; } if (p.Location == ptup && p.Image == bmpg) { change += pbox.Name + "$" + p.Name + "|"; pbox.Location = ptup; p.Location = opt; bushu++; textBox1.Enabled = false; button1.Enabled = false; } if (p.Location == ptdown && p.Image == bmpg) { change += pbox.Name + "$" + p.Name + "|"; pbox.Location = ptdown; p.Location = opt; bushu++; textBox1.Enabled = false; button1.Enabled = false; } } label2.Text = "已走的步数:" + bushu.ToString(); if (IsWin()) { foreach (PictureBox p in panel1.Controls) { if (p.Image == bmpg) { p.Image = empt; break; } } Updatainfo(textBox1.Text.Trim()); int tempi = rand.Next(1, 1001); Readinfo(tempi.ToString()); textBox1.Enabled = true; textBox1.Text = tempi.ToString(); bushu = 0; label2.Text = ""; button1.Enabled = true; } } private void Creatrect() { Picsize = 320 / gzs; arrrect.Clear(); Rectangle[] rect = new Rectangle[gzs * gzs]; for (int i = 0; i < gzs * gzs; i++) { rect[i] = new Rectangle((i % gzs) * Picsize, (i / gzs) * Picsize, Picsize, Picsize); arrrect.Add(rect[i]); } } private void button1_Click(object sender, EventArgs e) { try { OpenFileDialog dial = new OpenFileDialog(); dial.Title = "open the file"; dial.Filter = "Image File(*.jpg)|*.jpg"; dial.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory; if (dial.ShowDialog() == DialogResult.OK) { filename = dial.FileName; Creatpic(a); } } catch(Exception ex) { MessageBox.Show(ex.Message); } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex == 0) gzs = 2; if (comboBox1.SelectedIndex == 1) gzs = 3; if (comboBox1.SelectedIndex == 2) gzs = 4; if (comboBox1.SelectedIndex == 3) gzs = 5; if (!isfirst) { Creatrect(); DaluanPic(); Creatpic(a); } } private void DaluanPic() { //a = new int[gzs * gzs]; int rpt = gzs * gzs - 1; for (int i = 0; i < gzs * gzs; i++) a[i] = i; for (int i = 0; i < 200; i++) { int p = rand.Next(0, 4); switch (p) { case 0: if (rpt % gzs < gzs - 1) { int temp1 = a[rpt + 1]; a[rpt + 1] = a[rpt]; a[rpt] = temp1; rpt = rpt + 1; } break; case 1: if (rpt % gzs > 0) { int temp2 = a[rpt - 1]; a[rpt - 1] = a[rpt]; a[rpt] = temp2; rpt = rpt - 1; } break; case 2: if (rpt > gzs - 1) { int temp3 = a[rpt - gzs]; a[rpt - gzs] = a[rpt]; a[rpt] = temp3; rpt = rpt - gzs; } break; case 3: if (rpt < gzs * (gzs - 1)) { int temp4 = a[rpt + gzs]; a[rpt + gzs] = a[rpt]; a[rpt] = temp4; rpt = rpt + gzs; } break; } } //b = new int[a.Length]; } private bool IsWin() { b = new int[a.Length]; for (int i = 0; i < gzs * gzs; i++) { Point pt = new Point((i % gzs) * Picsize, (i / gzs) * Picsize); foreach (PictureBox picbox in panel1.Controls) { if (picbox.Location == pt) b[i] = Convert.ToInt32(picbox.Name); } } for (int i = 0; i < b.Length; i++) { if (i != b[i]) return false; } return true; } private void button3_Click(object sender, EventArgs e) { change = ""; arrpic.Clear(); bushu = 0; label2.Text = ""; Creatpic(a); //CrRect(); } private void CrRect() { ArrayList alist = new ArrayList(); gzs = 4; a = new int[16]; for (int m = 0; m < 1050; m++) { DaluanPic(); string s = ""; for (int i = 0; i < a.Length; i++) s += a[i].ToString() + "$"; if (!alist.Contains(s)) alist.Add(s); } Saveinfo(alist); MessageBox.Show("ok"); } private void ReadFile(string s) { StreamReader sr = new StreamReader("abc.txt"); string ss = sr.ReadLine(); while (ss != null) { string[] splitstr = ss.Split('#'); string ps = ""; if (splitstr[0] == s) { juhao = ss; ps = splitstr[1]; string[] split = ps.Split('$'); if (Convert.ToInt32(s) > 1000) { gzs = 4; a = new int[16]; } if (Convert.ToInt32(s) <= 1000) { gzs = 3; a = new int[9]; } for (int w = 0; w < split.Length - 1; w++) a[w] = Convert.ToInt32(split[w]); Creatrect(); Creatpic(a); break; } ss = sr.ReadLine(); } sr.Dispose(); } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { Regex regex = new Regex("^[0-9]*[1-9][0-9]*$"); if (e.KeyChar == 13) { if (textBox1.Text == "") { MessageBox.Show("请选择局号!"); return; } if (!regex.IsMatch(textBox1.Text.Trim())) { MessageBox.Show("您输入的不是整数!"); return; } if (textBox1.Text.Trim().Substring(0, 1) == "0") { MessageBox.Show("第一位数字不能为零!"); return; } if (int.Parse(textBox1.Text.Trim()) > 2000) { MessageBox.Show("输入的局号超出了范围!"); return; } button4.Enabled = false; Readinfo(textBox1.Text.Trim()); textBox1.Enabled = false; button1.Enabled = false; change = ""; arrpic.Clear(); } } private void button2_Click(object sender, EventArgs e) { label2.Text = ""; bushu = 0; textBox1.Enabled = true; button1.Enabled = true; } private void Saveinfo(ArrayList a) { XmlDocument xmldoc = new XmlDocument(); try { XmlElement root = null, pic = null, theElme = null; xmldoc.Load("abc.xml"); root = xmldoc.DocumentElement; for (int i = 0; i < a.Count; i++) { pic = xmldoc.CreateElement("Pictrue"); theElme = xmldoc.CreateElement("JS"); theElme.InnerText = (i + 1001).ToString(); pic.AppendChild(theElme); theElme = xmldoc.CreateElement("ID"); theElme.InnerText = a[i].ToString(); pic.AppendChild(theElme); theElme = xmldoc.CreateElement("Scores"); theElme.InnerText = "初次"; pic.AppendChild(theElme); theElme = xmldoc.CreateElement("Author"); theElme.InnerText = "WBJ"; pic.AppendChild(theElme); theElme = xmldoc.CreateElement("Date"); theElme.InnerText = DateTime.Now.ToString("yyyy-MM-dd"); pic.AppendChild(theElme); root.AppendChild(pic); } xmldoc.Save("abc.xml"); } catch(Exception e) { MessageBox.Show(e.Message); } } private void Readinfo(string s) { bu = 0; change = ""; arrpic.Clear(); XmlDocument xmldoc = new XmlDocument(); try { string[] ppl; XmlElement root=null; xmldoc.Load("abc.xml"); root = xmldoc.DocumentElement; XmlNodeList nodeList = root.ChildNodes; foreach (XmlNode xn in nodeList) { if (xn.SelectSingleNode("JS").InnerText == s) { ppl = xn.SelectSingleNode("ID").InnerText.Split('$'); XmlNode ff = xn.SelectSingleNode("Scores"); if (ff.InnerText == "初次") label4.Text = "目前本局最少步数:" + ff.InnerText; else { XmlNode kk = xn.SelectSingleNode("Author"); XmlNode date = xn.SelectSingleNode("Date"); XmlNode ys = xn.SelectSingleNode("Yanshi"); label4.Text = "目前本局最少步数:" + ff.InnerText; label4.Text += "\n纪录创造者:" + kk.InnerText; label4.Text += "\n记录创造日期:" + date.InnerText; if (ys.InnerText != "xyz") button4.Enabled = true; } if (Convert.ToInt32(s) <= 1000) { gzs = 3; a = new int[9]; } else { gzs = 4; a = new int[16]; } for (int w = 0; w < ppl.Length - 1; w++) a[w] = Convert.ToInt32(ppl[w]); Creatrect(); Creatpic(a); break; } } } catch (Exception e) { MessageBox.Show(e.Message); } } private void Updatainfo(string s) { XmlDocument xmldoc = new XmlDocument(); try { XmlElement root = null; xmldoc.Load("abc.xml"); root = xmldoc.DocumentElement; XmlNodeList nodeList = root.ChildNodes; foreach (XmlNode xn in nodeList) { if (xn.SelectSingleNode("JS").InnerText == s) { XmlNode xx = xn.SelectSingleNode("Scores"); XmlNode author = xn.SelectSingleNode("Author"); XmlNode date = xn.SelectSingleNode("Date"); XmlNode yanshn = xn.SelectSingleNode("Yanshi"); if (xx.InnerText != "初次") { int zxbs = Convert.ToInt32(xx.InnerText); if (zxbs > bushu) { Form2 f2 = new Form2(); f2.Text = "您创造了记录,请输入您的名字"; if (f2.ShowDialog() == DialogResult.OK) { author.InnerText = f2.textBox1.Text.Trim(); xx.InnerText = bushu.ToString(); date.InnerText = DateTime.Now.ToString("yyyy-MM-dd"); yanshn.InnerText = change; f2.Close(); } } } else { Form2 f2 = new Form2(); f2.Text = "您创造了记录,请输入您的名字"; if (f2.ShowDialog() == DialogResult.OK) { author.InnerText = f2.textBox1.Text.Trim(); xx.InnerText = bushu.ToString(); date.InnerText = DateTime.Now.ToString("yyyy-MM-dd"); yanshn.InnerText = change; f2.Close(); } } break; } } xmldoc.Save("abc.xml"); } catch (Exception e) { MessageBox.Show(e.Message); } } private void button4_Click(object sender, EventArgs e) { timer1.Start(); canclick = false; button2.Enabled = false; button3.Enabled = false; button4.Enabled = false; XmlDocument xmldoc = new XmlDocument(); XmlElement root = null; xmldoc.Load("abc.xml"); root = xmldoc.DocumentElement; XmlNodeList nodeList = root.ChildNodes; foreach (XmlNode xn in nodeList) { if (xn.SelectSingleNode("JS").InnerText == textBox1.Text.Trim()) { string yshpic = xn.SelectSingleNode("Yanshi").InnerText; string[] picstr = yshpic.Split('|'); for (int j = 0; j < picstr.Length; j++) arrpic.Add(picstr[j]); break; } } } private void FileEncryption() { //RijndaelManaged key = new RijndaelManaged(); //byte[] bytekey=Encoding.Unicode.GetBytes("我心飞扬穿越时空"); //key.Key = bytekey; //XmlDocument xmlDoc = new XmlDocument(); //xmlDoc.PreserveWhitespace = true; //xmlDoc.Load("abc.xml"); //Encrypt } private void timer1_Tick(object sender, EventArgs e) { if (bu < arrpic.Count) { string[] picname = arrpic[bu].ToString().Split('$'); foreach (PictureBox p in panel1.Controls) { if (p.Name == picname[0]) { Point ppt = p.Location; foreach (PictureBox pp in panel1.Controls) { if (pp.Name == picname[1]) { p.Location = pp.Location; pp.Location = ppt; } } } } bu++; } else { timer1.Stop(); button2.Enabled = true; button3.Enabled = true; canclick = true; } } } }
namespace 串口实例 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnSend_Click(object sender, EventArgs e) { //手动发送 SendMsg(); } private void SendMsg() { this.serialPort1.Write(this.txtSend.Text); } #region 控制输入数字 private void ComboBox_TextUpdate(object sender, EventArgs e) { ComboBox cbo = sender as ComboBox; int n; if (!int.TryParse(cbo.Text, out n)) { cbo.Text = cbo.Text.Substring(0, cbo.Text.Length - 1); } else { if (n <= 0) { cbo.Text = cbo.Text.Substring(0, cbo.Text.Length - 1); } } } private void txtTime_TextChanged(object sender, EventArgs e) { TextBox text = sender as TextBox; int n; if (!int.TryParse(text.Text, out n)) { text.Text = text.Text.Substring(0, text.Text.Length - 1); } else { if (n <= 0) { text.Text = text.Text.Substring(0, text.Text.Length - 1); } else { this.timer1.Interval = n; } } } #endregion /// <summary> /// 清空显示文本框 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnClear_Click(object sender, EventArgs e) { this.txtRecive.Clear(); } private void timer1_Tick(object sender, EventArgs e) { SendMsg(); } private void cbtSend_CheckedChanged(object sender, EventArgs e) { CheckBox check = sender as CheckBox; if (check.Checked) { this.timer1.Start(); } else { this.timer1.Stop(); } } /// <summary> /// 接收返回的数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { string a=""; if (this.cbkShow16.Checked) { //十六进制显示 a = this.serialPort1.ReadExisting(); } else { //字符串显示 byte[] by = new byte[this.serialPort1.BytesToRead]; this.serialPort1.Read(by, 0, this.serialPort1.BytesToRead); a = Encoding.ASCII.GetString(by); } this.txtRecive.AppendText(a); this.txtRecive.ScrollToCaret(); } private void Form1_Load(object sender, EventArgs e) { //加载 this.serialPort1.RtsEnable = true; button1_Click(this.btnOpen, null); } private void button1_Click(object sender, EventArgs e) { Button btn = sender as Button; if (btn.Text == "打开端口") { try { this.serialPort1.PortName = this.cboPortName.Text; this.serialPort1.BaudRate = Convert.ToInt32(this.cboRaudRate.Text); this.serialPort1.DataBits = Convert.ToInt32(this.cboDataBits.Text); this.serialPort1.ReceivedBytesThreshold = Convert.ToInt32(this.cboReceivedBytesThreshold.Text); this.serialPort1.Open(); btn.Text = "关闭端口"; } catch { MessageBox.Show("打开端口失败,请检查端口是否被占用."); } } else { this.serialPort1.Close(); btn.Text = "打开端口"; } } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { try { this.serialPort1.Close(); } catch { } } } }
/* API精灵 FOR C# 开始设计日期 2004.03.06 设计目的:简单快速对C#中使用的API函数进行查询,并给出调用代码 设计进度: 2004.03.09 完成对的查询功能,包括 代码调用,中文注释,所需的DLL库,与C#中函数对应关系 2004.03.10 0:48:52 完成了用StringBuilder数组对原ComboBox的替换,可以使程序不用从新读取数据库就可以刷新修改后的信息! 2004.03.10 18:00:00 完成了用ArrayList对StringBuilder数组的替换节省2M内存 2004.03.11 21:10:15 完成滚动字幕的设置,启用了一个TIMER控件,然后设置时间,删除字符串的第一个字母已达到滚动效果! 2004.03.11 22:02:00 改正更新时出现空值出错问题,新填函数isnull 2004.03.12 13:22:08 完成关键字高亮显示 高亮显示函数 mykeywords 2004.03.12 22:08:20 加强了高亮显示函数 mykeywords的功能,使其能识别不同的关键字并显示不同的颜色 2004.03.14 01:40:00 完成对CONST的查询,并且增加了 mykeywords1函数,使其关键字显示性能提高 2004.03.14 13:12:00 添加了提示信息,提示信息设置在函数 mytips() 中 2004.03.15 21:51:20 更改数据库和WINAPI.TXT路径为程序运行路径 2004.03.15 22:31:50 添加了鼠标右键信息 2004.03.15 23.23:30 添加了数据库密码 2004.03.16 23:24:30 添加了版权信息以及相应提示 */ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Data.OleDb; using System.Runtime.InteropServices; using System.IO; namespace API精灵 { /// /// Form1 的摘要说明。 /// 这个版本没有使用oleDbDataAdapter+DataSet对数据进行存取,而是使用的OleDbCommand +OleDbDataReader 的形式。 /// 主要是想试验一下不用oleDbDataAdapter+DataSet的数据存取速度。 /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.Button button4; private System.Windows.Forms.TextBox mysearch; private System.Windows.Forms.ListBox tiplist; private System.Windows.Forms.ComboBox select_type; private System.Windows.Forms.TextBox dlltext; /// /// 必需的设计器变量。 /// //自定义变量 private ArrayList fundll = new ArrayList();//保存读取出来的DLL内容 private ArrayList funtips = new ArrayList();//保存读取出来的中文提示信息 private ArrayList funcode = new ArrayList();//保存读取出来的C#调用代码 private ArrayList funmat = new ArrayList();//保存读取出来的C#对应函数 private ArrayList funwin9x = new ArrayList();//保存读取出来的WIN9X private ArrayList funwin2k = new ArrayList();//保存读取出来的WIN2K private int nowselect = 0; private string oldscoll_text; private int nowtypeselect = 0; private string nowpath = @System.Environment.CurrentDirectory+@"\"; private string dbpassword = "ling_feng_work"; public string myConnstr; public OleDbConnection myconn ;//创建一个新连接 private string mysql ;//查询语句 private string sql_update; private System.Windows.Forms.RichTextBox tipsmemo; private System.Windows.Forms.TextBox mat_text; private OleDbCommand mycommand = new OleDbCommand(); private System.Windows.Forms.RichTextBox codememo; private System.Windows.Forms.GroupBox groupBox4; private System.Windows.Forms.CheckBox win9x; private System.Windows.Forms.GroupBox groupBox5; private System.Windows.Forms.CheckBox win2k; private System.Windows.Forms.CheckBox e_add; private System.Windows.Forms.CheckBox e_modify; private System.Windows.Forms.Button b_modify; private System.Windows.Forms.Button b_add; private System.Windows.Forms.Timer timer1; private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.ContextMenu mypop; private System.Windows.Forms.MenuItem menuItem1; private System.ComponentModel.IContainer components; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// /// 清理所有正在使用的资源。 /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1)); this.button1 = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.tiplist = new System.Windows.Forms.ListBox(); this.select_type = new System.Windows.Forms.ComboBox(); this.mat_text = new System.Windows.Forms.TextBox(); this.mysearch = new System.Windows.Forms.TextBox(); this.dlltext = new System.Windows.Forms.TextBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.tipsmemo = new System.Windows.Forms.RichTextBox(); this.mypop = new System.Windows.Forms.ContextMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.codememo = new System.Windows.Forms.RichTextBox(); this.b_modify = new System.Windows.Forms.Button(); this.b_add = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.win2k = new System.Windows.Forms.CheckBox(); this.win9x = new System.Windows.Forms.CheckBox(); this.groupBox5 = new System.Windows.Forms.GroupBox(); this.e_add = new System.Windows.Forms.CheckBox(); this.e_modify = new System.Windows.Forms.CheckBox(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); this.groupBox4.SuspendLayout(); this.groupBox5.SuspendLayout(); this.SuspendLayout(); // // button1 // this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button1.Location = new System.Drawing.Point(224, 395); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 24); this.button1.TabIndex = 10; this.button1.Text = "关 于"; this.button1.Click += new System.EventHandler(this.button1_Click); // // groupBox1 // this.groupBox1.Controls.Add(this.tiplist); this.groupBox1.Controls.Add(this.select_type); this.groupBox1.Controls.Add(this.mat_text); this.groupBox1.Controls.Add(this.mysearch); this.groupBox1.Controls.Add(this.dlltext); this.groupBox1.Location = new System.Drawing.Point(8, 8); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(200, 168); this.groupBox1.TabIndex = 1; this.groupBox1.TabStop = false; this.groupBox1.Text = "API查询"; // // tiplist // this.tiplist.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tiplist.ItemHeight = 12; this.tiplist.Location = new System.Drawing.Point(8, 43); this.tiplist.Name = "tiplist"; this.tiplist.Size = new System.Drawing.Size(184, 110); this.tiplist.TabIndex = 1; this.tiplist.Visible = false; this.tiplist.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tiplist_KeyDown); this.tiplist.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tiplist_KeyPress); this.tiplist.DoubleClick += new System.EventHandler(this.tiplist_DoubleClick); this.tiplist.MouseUp += new System.Windows.Forms.MouseEventHandler(this.tiplist_MouseUp); this.tiplist.MouseLeave += new System.EventHandler(this.tiplist_MouseLeave); this.tiplist.SelectedIndexChanged += new System.EventHandler(this.tiplist_SelectedIndexChanged); // // select_type // this.select_type.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.select_type.Items.AddRange(new object[] { "API函数查询", "常量定义查询"}); this.select_type.Location = new System.Drawing.Point(8, 61); this.select_type.Name = "select_type"; this.select_type.Size = new System.Drawing.Size(184, 20); this.select_type.TabIndex = 2; this.select_type.SelectedIndexChanged += new System.EventHandler(this.select_type_SelectedIndexChanged); // // mat_text // this.mat_text.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.mat_text.Location = new System.Drawing.Point(8, 134); this.mat_text.Name = "mat_text"; this.mat_text.Size = new System.Drawing.Size(184, 21); this.mat_text.TabIndex = 4; this.mat_text.Text = "C#对应函数:"; this.mat_text.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mat_text_MouseDown); // // mysearch // this.mysearch.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.mysearch.Location = new System.Drawing.Point(8, 24); this.mysearch.Name = "mysearch"; this.mysearch.Size = new System.Drawing.Size(184, 21); this.mysearch.TabIndex = 0; this.mysearch.Text = ""; this.mysearch.KeyDown += new System.Windows.Forms.KeyEventHandler(this.mysearch_KeyDown); this.mysearch.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mysearch_MouseDown); this.mysearch.TextChanged += new System.EventHandler(this.mysearch_TextChanged); // // dlltext // this.dlltext.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.dlltext.Location = new System.Drawing.Point(8, 97); this.dlltext.Name = "dlltext"; this.dlltext.Size = new System.Drawing.Size(184, 21); this.dlltext.TabIndex = 3; this.dlltext.Text = ""; this.dlltext.TextChanged += new System.EventHandler(this.dlltext_TextChanged); // // groupBox2 // this.groupBox2.Controls.Add(this.tipsmemo); this.groupBox2.Location = new System.Drawing.Point(216, 8); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(200, 168); this.groupBox2.TabIndex = 2; this.groupBox2.TabStop = false; this.groupBox2.Text = "函数注释"; // // tipsmemo // this.tipsmemo.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tipsmemo.ContextMenu = this.mypop; this.tipsmemo.Location = new System.Drawing.Point(8, 16); this.tipsmemo.Name = "tipsmemo"; this.tipsmemo.Size = new System.Drawing.Size(184, 144); this.tipsmemo.TabIndex = 0; this.tipsmemo.Text = ""; this.tipsmemo.MouseEnter += new System.EventHandler(this.richTextBox1_MouseEnter); // // mypop // this.mypop.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.Text = "复制信息"; this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click); // // groupBox3 // this.groupBox3.Controls.Add(this.codememo); this.groupBox3.Location = new System.Drawing.Point(8, 221); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(408, 168); this.groupBox3.TabIndex = 3; this.groupBox3.TabStop = false; this.groupBox3.Text = "代码调用"; // // codememo // this.codememo.ContextMenu = this.mypop; this.codememo.Location = new System.Drawing.Point(8, 16); this.codememo.Name = "codememo"; this.codememo.Size = new System.Drawing.Size(392, 144); this.codememo.TabIndex = 0; this.codememo.Text = ""; this.codememo.TextChanged += new System.EventHandler(this.codememo_TextChanged); // // b_modify // this.b_modify.Enabled = false; this.b_modify.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.b_modify.Location = new System.Drawing.Point(120, 395); this.b_modify.Name = "b_modify"; this.b_modify.Size = new System.Drawing.Size(75, 24); this.b_modify.TabIndex = 4; this.b_modify.Text = "修改信息"; this.b_modify.Click += new System.EventHandler(this.button2_Click); // // b_add // this.b_add.Enabled = false; this.b_add.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.b_add.Location = new System.Drawing.Point(16, 395); this.b_add.Name = "b_add"; this.b_add.Size = new System.Drawing.Size(75, 24); this.b_add.TabIndex = 5; this.b_add.Text = "添加新项"; // // button4 // this.button4.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button4.Location = new System.Drawing.Point(328, 395); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(75, 24); this.button4.TabIndex = 6; this.button4.Text = "退 出"; this.button4.Click += new System.EventHandler(this.button4_Click); // // groupBox4 // this.groupBox4.Controls.Add(this.win2k); this.groupBox4.Controls.Add(this.win9x); this.groupBox4.Location = new System.Drawing.Point(8, 176); this.groupBox4.Name = "groupBox4"; this.groupBox4.Size = new System.Drawing.Size(200, 40); this.groupBox4.TabIndex = 11; this.groupBox4.TabStop = false; // // win2k // this.win2k.Location = new System.Drawing.Point(104, 11); this.win2k.Name = "win2k"; this.win2k.Size = new System.Drawing.Size(80, 24); this.win2k.TabIndex = 1; this.win2k.Text = "支持win2k"; // // win9x // this.win9x.Location = new System.Drawing.Point(16, 11); this.win9x.Name = "win9x"; this.win9x.TabIndex = 0; this.win9x.Text = "支持win9x"; // // groupBox5 // this.groupBox5.Controls.Add(this.e_add); this.groupBox5.Controls.Add(this.e_modify); this.groupBox5.Location = new System.Drawing.Point(216, 176); this.groupBox5.Name = "groupBox5"; this.groupBox5.Size = new System.Drawing.Size(200, 40); this.groupBox5.TabIndex = 12; this.groupBox5.TabStop = false; // // e_add // this.e_add.Location = new System.Drawing.Point(112, 10); this.e_add.Name = "e_add"; this.e_add.Size = new System.Drawing.Size(80, 24); this.e_add.TabIndex = 5; this.e_add.Text = "允许添加"; this.e_add.CheckedChanged += new System.EventHandler(this.e_add_CheckedChanged); // // e_modify // this.e_modify.Location = new System.Drawing.Point(16, 10); this.e_modify.Name = "e_modify"; this.e_modify.Size = new System.Drawing.Size(76, 24); this.e_modify.TabIndex = 4; this.e_modify.Text = "允许修改"; this.e_modify.CheckedChanged += new System.EventHandler(this.e_modify_CheckedChanged); // // timer1 // this.timer1.Interval = 500; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(424, 429); this.Controls.Add(this.groupBox5); this.Controls.Add(this.groupBox4); this.Controls.Add(this.button4); this.Controls.Add(this.b_add); this.Controls.Add(this.b_modify); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox1); this.Controls.Add(this.button1); this.Controls.Add(this.groupBox2); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "API精灵FOR C#"; this.Load += new System.EventHandler(this.Form1_Load); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox3.ResumeLayout(false); this.groupBox4.ResumeLayout(false); this.groupBox5.ResumeLayout(false); this.ResumeLayout(false); } #endregion /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { Application.Run(new Form1()); } [DllImport("user32.dll", EntryPoint="ShowWindow")] public static extern int ShowWindow ( int hwnd, int nCmdShow ); private void button1_Click(object sender, System.EventArgs e) { AboutForm myabout = new AboutForm(); myabout.ShowDialog(); } /// /// 填写mysearch中的内容。 /// private void search_comp() { if (tiplist.SelectedIndex>-1) mysearch.Text = tiplist.SelectedItem.ToString(); tiplist.Visible = false ; mysearch.Select(); } /// /// 自动填写提示内容。 /// private void autocomp() { if (tiplist.SelectedIndex>-1) try { if (this.nowtypeselect==0) //================查询函数 { this.nowselect = tiplist.SelectedIndex; dlltext.Text = fundll[tiplist.SelectedIndex].ToString();//else tipsmemo.Text = funtips[tiplist.SelectedIndex].ToString(); codememo.Text = funcode[tiplist.SelectedIndex].ToString(); mat_text.Text = funmat[tiplist.SelectedIndex].ToString(); this.oldscoll_text = mat_text.Text; if (funwin9x[tiplist.SelectedIndex].ToString()==("Yes")) win9x.Checked=true; else win9x.Checked=false; if (funwin2k[tiplist.SelectedIndex].ToString()==("Yes")) win2k.Checked=true; else win2k.Checked=false; //滚动文字 if (mat_text.TextLength>30) timer1.Enabled = true; else timer1.Enabled = false; } else { dlltext.Text = ""; tipsmemo.Text = ""; codememo.Text = ""; win9x.Checked = false; win2k.Checked = false; } //******************** if (this.nowtypeselect==1) { this.nowselect = tiplist.SelectedIndex; codememo.Text = funcode[tiplist.SelectedIndex].ToString(); } //******************** //================= } catch { dlltext.Text = "没有找到相应连接库"; tipsmemo.Text = "没有找到相应提示"; codememo.Text = "没有找到相应调用代码"; mat_text.Text = "没有找到相应C#函数"; } } // /// /// 手动释放一些内存。 /// private void mydisp() { tipsmemo.Clear(); codememo.Clear(); tiplist.Items.Clear(); // ===== fundll.Clear();//保存读取出来的DLL内容 funtips.Clear();//保存读取出来的中文提示信息 funcode.Clear();//保存读取出来的C#调用代码 funmat.Clear();//保存读取出来的C#对应函数 funwin9x.Clear();//保存读取出来的WIN9X funwin2k.Clear();//保存读取出来的WIN2K } private void mysearch_TextChanged(object sender, System.EventArgs e) { tiplist.Visible = true ; //自动完成功能。 tiplist.SelectedIndex = (tiplist.FindString(mysearch.Text,-1)) ;//加上这句,保证TIPLIST跟着自动变化 nowselect = tiplist.SelectedIndex; autocomp(); //设置提示信息 mytips(); } private void mysearch_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if ((e.KeyCode == Keys.Down) || (e.KeyCode == Keys.Up)) tiplist.Focus(); if (e.KeyCode == Keys.Enter) { search_comp(); if (this.nowtypeselect==0) mykeyword(); if (this.nowtypeselect==1) mykeyword1(); } if (e.KeyCode == Keys.Escape) { tiplist.Visible = false ; } } private void tiplist_MouseLeave(object sender, System.EventArgs e) { } private void tiplist_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { } private void tiplist_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this.search_comp(); if (this.nowtypeselect==0) mykeyword(); else mykeyword1(); } if (e.KeyCode == Keys.Escape) { tiplist.Visible = false ; } } private void tiplist_DoubleClick(object sender, System.EventArgs e) { this.search_comp(); if (this.nowtypeselect==0) mykeyword(); else mykeyword1(); } private void Form1_Load(object sender, System.EventArgs e) { //初始化数据库 initdatabase(); //MessageBox.Show(this,"欢迎使用 共享版\n 本版对使用功能上略有限制\n 且不提供数据库更新!\n 如想获得更多信息请与我联系。\n [email protected]","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); select_type.SelectedIndex = 0; AboutForm myabout = new AboutForm(); myabout.ShowDialog(); } // private void mytips() { //设置提示信息 if ((this.nowselect>-1)&(this.nowtypeselect==0)) { toolTip1.SetToolTip(this.dlltext,"所在动态连接库: "+this.fundll[this.nowselect].ToString()); toolTip1.SetToolTip(this.mat_text,"在C#中对应的函数: "+this.funmat[this.nowselect].ToString()); toolTip1.SetToolTip(this.codememo,"函数 "+this.tiplist.SelectedItem.ToString()+" 在C#中的调用代码,可以手动修改"); toolTip1.SetToolTip(this.tipsmemo,"函数 "+this.tiplist.SelectedItem.ToString()+" 的注释信息,可以手动修改"); } else if ((this.nowselect>-1)&(this.nowtypeselect==1)) { toolTip1.SetToolTip(this.codememo,"常量 "+this.tiplist.SelectedItem.ToString()+" 在C#中的调用代码"); toolTip1.SetToolTip(this.dlltext,"没有相关信息"); toolTip1.SetToolTip(this.mat_text,"没有相关信息"); toolTip1.SetToolTip(this.tipsmemo,"没有相关信息"); } } // private void initdatabase() { string dbpath = @nowpath+"winapi.mdb"; tiplist.Items.Clear(); //@"Provider=Microsoft.Jet.OleDB.4.0;Data Source="+dbpath+";User Id=admin;Password="+this.dbpassword ; //"Provider=Microsoft.Jet.OleDB.4.0;Data Source=your mdb filename;Jet OLEDB:Database Password='pass'" ; this.myConnstr = @"Provider=Microsoft.Jet.OleDB.4.0;Data Source="+dbpath+";User Id=admin;Jet OLEDB:Database Password="+this.dbpassword ; this.myconn= new OleDbConnection(myConnstr); mysql= @"select Fun_name,Fun_dll,Fun_tips,Fun_code,Fun_com,win9x,win2k from winapi"; using(myconn) { myconn.Open(); // if (myconn.State.ToString() == "Open") MessageBox.Show("打开成功!"); //数据处理 // OleDbCommand mycommand = new OleDbCommand(mysql,myconn); mycommand.CommandText = mysql; mycommand.Connection = myconn; OleDbDataReader myreader = mycommand.ExecuteReader(); int i=0; while (myreader.Read()) { tiplist.Items.Add(myreader["Fun_name"]); fundll.Add(myreader["fun_dll"].ToString()); funtips.Add(myreader["fun_tips"].ToString()); funcode.Add(myreader["fun_code"].ToString()); funmat.Add(myreader["fun_com"].ToString()); funwin9x.Add(myreader["win9x"].ToString()); funwin2k.Add(myreader["win2k"].ToString()); i++; } myconn.Close(); myreader.Close(); } } //更新缓存 private void memo_update() { fundll[nowselect] = dlltext.Text; funtips[nowselect] = this.tipsmemo.Text; funcode[nowselect] = this.codememo.Text; funmat[nowselect] = this.mat_text.Text; if (win9x.Checked) funwin9x[nowselect]="Yes" ;else funwin9x[nowselect]="No"; if (win2k.Checked) funwin2k[nowselect]="Yes" ;else funwin2k[nowselect]="No"; } // private void oleDbConnection1_InfoMessage(object sender, System.Data.OleDb.OleDbInfoMessageEventArgs e) { } //==============从WINAPI.TXT读取CONST并拆分 private void mysplip() { //string dbpath = @System.Environment.CurrentDirectory+@"\winapi.mdb"; string filename =@nowpath +"winapi.txt"; string nextline; tiplist.Items.Clear(); StreamReader sr = new StreamReader(filename); while ((nextline = sr.ReadLine())!=null) { if (nextline.StartsWith("public const")) { string[] ss = nextline.Split('='); tiplist.Items.Add(ss[0].Substring(16).Trim()); funcode.Add(nextline); } } sr.Close(); } //============================== private void select_type_SelectedIndexChanged(object sender, System.EventArgs e) { if (select_type.SelectedIndex != this.nowtypeselect) { this.mydisp(); switch (select_type.SelectedIndex) { case 0:initdatabase();this.nowtypeselect=select_type.SelectedIndex;break; case 1:mysplip();this.nowtypeselect=select_type.SelectedIndex;this.dlltext.Clear();this.mat_text.Clear();break; } isenable(this.nowtypeselect); } } private void dlltext_TextChanged(object sender, System.EventArgs e) { } private void richTextBox1_MouseEnter(object sender, System.EventArgs e) { tiplist.Visible = false ; } private void mysearch_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { tiplist.Visible = false ; mysearch.Focus(); } private void tiplist_SelectedIndexChanged(object sender, System.EventArgs e) { autocomp(); } /// /// 修改内容。 /// private void fun_update() { using(myconn) { myconn.ConnectionString = myConnstr; myconn.Open(); try { //if (myconn.State.ToString() == "Open") MessageBox.Show("打开成功!"); isnull();//判断是否有无效值 string str_win9x,str_win2k; if (win9x.Checked) str_win9x = "Yes" ; else str_win9x = "No"; if (win2k.Checked) str_win2k = "Yes" ; else str_win2k = "No"; sql_update = "update winapi set Fun_dll = '"+dlltext.Text+"'"+" , Fun_tips = '"+tipsmemo.Text+"'"+" , Fun_code = '"+codememo.Text+"'"+" , Fun_com ='"+mat_text.Text+"' "; sql_update +=" , win9x = '" + str_win9x +"' " + ", win2k = '" + str_win2k+"' "; sql_update +=" where Fun_name ='"+ mysearch.Text+"'"; mycommand.Connection = myconn; mycommand.CommandText = sql_update; mycommand.ExecuteNonQuery(); myconn.Close(); memo_update(); MessageBox.Show(this,"恭喜!更新成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); } catch { // tipsmemo.Text = sql_update; MessageBox.Show("没有找到相应记录,更新失败!"); } } } //判断是更新的部分是否有效(不能为空) private void isnull() { if (this.mat_text.Text=="") this.mat_text.Text="没有相关信息"; if (this.codememo.Text=="") this.codememo.Text="没有相关信息"; if (this.tipsmemo.Text=="") this.tipsmemo.Text="没有相关信息"; if (this.dlltext.Text=="") this.dlltext.Text="没有相关信息"; } //关键字高亮显示 private void mykeyword() { string[] keywords = new string[5]; keywords[0]=mysearch.Text; keywords[1]="string"; keywords[2]="ref"; keywords[3]="int"; keywords[4]="static extern"; for(int i=0;i0) { index++; switch(i) { case 0: codememo.SelectionColor = Color.Red;break; case 1: codememo.SelectionColor = Color.Green;break; case 2: codememo.SelectionColor = Color.Brown;break; case 3: codememo.SelectionColor = Color.Blue;break; case 4: codememo.SelectionColor = Color.Green;break; //default:codememo.SelectionColor = Color.Blue;break; } } } } // //CONST中关键字高亮显示 private void mykeyword1() { string[] keywords = new string[5]; keywords[0]=mysearch.Text; keywords[1]="="; keywords[2]="0"; keywords[3]="int"; keywords[4]="const"; for(int i=0;i0) { index++; switch(i) { case 0: codememo.SelectionColor = Color.Red;break; case 1: codememo.SelectionColor = Color.Blue;break; case 2: codememo.SelectionColor = Color.Green;break; case 3: codememo.SelectionColor = Color.Blue;break; case 4: codememo.SelectionColor = Color.Green;break; //default:codememo.SelectionColor = Color.Blue;break; } if (index>codememo.TextLength) break; } } } // private void button2_Click(object sender, System.EventArgs e) { this.fun_update(); } private void isenable(int i_temp) { if (i_temp==0) { win9x.Enabled=true; win2k.Enabled=true; e_modify.Enabled=true; e_add.Enabled=true; b_modify.Enabled=true; b_add.Enabled=true; } else { win9x.Enabled=false; win2k.Enabled=false; e_modify.Enabled=false; e_add.Enabled=false; b_modify.Enabled=false; b_add.Enabled=false; } } private void button4_Click(object sender, System.EventArgs e) { Application.Exit(); } private void e_modify_CheckedChanged(object sender, System.EventArgs e) { if (e_modify.Checked) b_modify.Enabled = true; else b_modify.Enabled = false; } private void e_add_CheckedChanged(object sender, System.EventArgs e) { if (e_add.Checked) b_add.Enabled = true; else b_add.Enabled = false; } private void timer1_Tick(object sender, System.EventArgs e) { if (this.mat_text.TextLength>0) mat_text.Text = mat_text.Text.Remove(0,1); else mat_text.Text = oldscoll_text; } private void mat_text_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { timer1.Enabled = false ; mat_text.Text = oldscoll_text; } private void codememo_TextChanged(object sender, System.EventArgs e) { } private void tiplist_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { } private void menuItem1_Click(object sender, System.EventArgs e) { Control ct = this.ActiveControl; string temp = ct.Text; Clipboard.SetDataObject(temp); } private void menuItem2_Click(object sender, System.EventArgs e) { } } }
可以机选福利彩票和体育彩票 public partial class 福利彩票 : Form { public 福利彩票(彩票机选 newFrom) { InitializeComponent(); MdiParent = newFrom; } static Random rd = new Random(); static List<shuzi> myshuzi = new List<shuzi>();//定义一个泛型集合类 static bool myBool; static void ShuangSeQiuFangFa() { myBool = true; while (myBool) { myBool = false; myshuzi.Clear(); for (int i = 0; i < 6; i++) { myshuzi.Add(new shuzi(rd.Next(1, 34))); } for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 6; j++) { if (myshuzi[j].x == myshuzi[i].x ) { myBool = true; } } } } Comparison<shuzi> sorter = new Comparison<shuzi> (paixu.Compare); myshuzi.Sort(sorter); } static void QiLeCaiFangFa() { myBool = true; while (myBool) { myBool = false; myshuzi.Clear(); for (int i = 0; i < 7; i++) { myshuzi.Add(new shuzi(rd.Next(1, 31))); } for (int i = 0; i < 6; i++) { for (int j = i + 1; j < 7; j++) { if (myshuzi[j].x == myshuzi[i].x) { myBool = true; } } } } Comparison<shuzi> sorter = new Comparison<shuzi> (paixu.Compare); myshuzi.Sort(sorter); } private void button3D_Click(object sender, EventArgs e) { textBox1.Text = rd.Next(0, 10).ToString(); textBox2.Text = rd.Next(0, 10).ToString(); textBox3.Text = rd.Next(0, 10).ToString(); } private void buttonshuangseqiu_Click(object sender, EventArgs e) { ShuangSeQiuFangFa(); textBox4.Text = myshuzi[0].x .ToString (); textBox5.Text = myshuzi[1].x.ToString(); textBox6.Text = myshuzi[2].x.ToString(); textBox7.Text = myshuzi[3].x.ToString(); textBox8.Text = myshuzi[4].x.ToString(); textBox9.Text = myshuzi[5].x.ToString(); textBox10.Text = rd.Next(1, 17).ToString(); } private void buttonqilecai_Click(object sender, EventArgs e) { QiLeCaiFangFa(); textBox17.Text = myshuzi[0].x.ToString(); textBox16.Text = myshuzi[1].x.ToString(); textBox15.Text = myshuzi[2].x.ToString(); textBox14.Text = myshuzi[3].x.ToString(); textBox13.Text = myshuzi[4].x.ToString(); textBox12.Text = myshuzi[5].x.ToString(); textBox11.Text = myshuzi[6].x.ToString(); textBox18.Text = rd.Next(1, 31).ToString(); } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值