源码:http://pan.baidu.com/s/1gdvg7jd
1、选择文件框
StreamReader reader; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { if(openFileDialog1.FileName!=null) { reader = new StreamReader(File.OpenRead(openFileDialog1.FileName), System.Text.Encoding.Default); string alldata=reader.ReadToEnd(); // byte[] tmp= Encoding.Convert(Encoding.Default, Encoding.GetEncoding("utf-8"), Encoding.Default.GetBytes(alldata)); // alldata= Encoding.Default.GetString(tmp); Debug.WriteLine(alldata); richTextBox1.Text = alldata; reader.Close(); } }2、定位指定文件
ProcessStartInfo psi = new ProcessStartInfo("Explorer.exe"); string file = @"c:\windows\notepad.exe"; psi.Arguments = " /select," + file; Process.Start(psi);3、加载图片和进制转换
pictureBox1.Image = Bitmap.FromFile("d:/tmp.png"); //十进制转二进制 Console.WriteLine(Convert.ToString(69, 2)); //十进制转八进制 Console.WriteLine(Convert.ToString(69, 8)); //十进制转十六进制 Console.WriteLine(Convert.ToString(69, 16)); //二进制转十进制 Console.WriteLine(Convert.ToInt32("100111101", 2)); //八进制转十进制 Console.WriteLine(Convert.ToInt32("76", 8)); //C# 16进制转换10进制 Console.WriteLine(Convert.ToInt32("FF", 16));
//获取进程 this.listBox1.Items.Clear(); foreach (System.Diagnostics.Process thisproc in System.Diagnostics.Process.GetProcesses()) { this.listBox1.Items.Add(thisproc.ProcessName); if (thisproc.ProcessName.ToString() == "cmd") { //关闭进程 thisproc.Kill(); } }5、调用api例子
[DllImport("user32.dll")] public static extern int MessageBox(int hWnd, String text, String caption, uint type); private void button9_Click(object sender, EventArgs e) { MessageBox(0, "Welcome to cf!", "C#调用API例子", 0); }
this.Close(); Application.Exit();