C#-常用
去空格 str.Trim()最小化窗體 this.WindowState = FormWindowState.Minimized;鼠標(biāo)拖動(dòng)窗體
\\**********************************************
[DllImport("user32.dll")]
public static extern bool ReleaseCapture(); [DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); private void frmMain_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, 0x0112, 0xF012, 0);
}
\\**********************************************獲取自己的名字
Process processes = Process.GetCurrentProcess();
string name =processes.ProcessName;
自己的路徑
string now = Application.StartupPath + @"\" + name + ".exe";獲取桌面路徑
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)System.Diagnostics.Process.Start("cmd.exe");//啟動(dòng)指定文件
System.Diagnostics.Process.Start("iexplore.exe", "http://www.baidu.com");
System.Diagnostics.Process.Start(@"Notepad.exe");打開(kāi)記事本
Help.ShowHelp(this, "D:\\虐肆\\工具\(yùn)\新建文件夾\\Kugou7\\KuGou.exe");打開(kāi)指定目錄文件
System.Diagnostics.Process.Start("shutdown.exe",@"s,r,a") //帶參數(shù)調(diào)用進(jìn)程
System.Diagnostics.Process.Start("shutdown.exe",@"/a");xinxi.Text = xinxi.Text.ToUpper();//字符串轉(zhuǎn)換成大寫(xiě)
string Password = User1.Substring(6 ,6) ;截取字符串指定長(zhǎng)度
Application.StartupPath; 本地路徑
存字符串
File.WriteAllText(@"C:\Users\asus\Desktop\" + textBox1.Text + ".txt", a);設(shè)置拖動(dòng)改變位置,其實(shí)是在空間的點(diǎn)擊和抬起時(shí)間里打開(kāi)和關(guān)閉跟隨的timer
private void timer2_Tick(object sender, EventArgs e)
{int xx = Control.MousePosition.X;//獲得鼠標(biāo)的xint yy = Control.MousePosition.Y;//獲得鼠標(biāo)的ythis.Location = new Point(xx - 500, yy - 160);
}獲取當(dāng)前時(shí)間
時(shí)間.Text = DateTime.Now.ToString();
n = DateTime.Now.Year;
y = DateTime.Now.Month;
r = DateTime.Now.Day;
s = DateTime.Now.Hour;
f = DateTime.Now.Minute;
m = DateTime.Now.Second;
time = DateTime.Now.DayOfWeek.ToString();//星期
if (time == "Monday") time = "星期一";
if (time == "Tuesday") time = "星期二";
if (time == "Wednesday") time = "星期三";
if (time == "Thursday") time = "星期四";
if (time == "Friday") time = "星期五";
if (time == "Saturday") time = "星期六";
if (time == "Sunday") time = "星期日";System.Diagnostics.Process.Start("shutdown.exe", @"/p");強(qiáng)制直接關(guān)機(jī)
System.Diagnostics.Process.Start("shutdown.exe", @"/r");重啟
System.Diagnostics.Process.Start("shutdown.exe", @"/l"); 注銷字符串和byte之間的轉(zhuǎn)換
string tmp = Encoding.UTF8.GetString(result, 0, len);
Encoding.UTF8.GetBytes("aaaaa")this.TopMost = true;最前面
textbox1.Focus(); 獲取交點(diǎn)if (File.Exists(@"C:\Users\Administrator\Desktop\批處理\常用總結(jié)\if.txt")) MessageBox.Show("ok");判斷該文件是否存在string strHostName = Dns.GetHostName(); //得到本機(jī)的主機(jī)名
IPHostEntry ipEntry = Dns.GetHostByName(strHostName); //取得本機(jī)IP
string strAddr = ipEntry.AddressList[0].ToString(); //假設(shè)本地主機(jī)為單網(wǎng)卡指定路徑的文件變成byte
byte[] img = System.IO.File.ReadAllBytes(Application .StartupPath +"\\Picture\\"+id +".jpg");獲取本地IPprivate void GetLocalIpAddress(){try{string strHostName = Dns.GetHostName();IPHostEntry ipEntry = Dns.GetHostByName(strHostName);string strAddr = ipEntry.AddressList[0].ToString();rtIpaddress.Text = strAddr;rtIpaddress.Items.Clear();rtIpaddress.Items.Add("127.0.0.1");for (int i = 0; i < 10; i++){strAddr = ipEntry.AddressList[i].ToString();rtIpaddress.Items.Add(strAddr);}}catch { }}
總結(jié)
- 上一篇: C#-MD5
- 下一篇: Effective C# 原则16:垃圾