C#-常用
去空格 str.Trim()最小化窗體 this.WindowState = FormWindowState.Minimized;鼠標拖動窗體
\\**********************************************
[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");//啟動指定文件
System.Diagnostics.Process.Start("iexplore.exe", "http://www.baidu.com");
System.Diagnostics.Process.Start(@"Notepad.exe");打開記事本
Help.ShowHelp(this, "D:\\虐肆\\工具\\新建文件夾\\Kugou7\\KuGou.exe");打開指定目錄文件
System.Diagnostics.Process.Start("shutdown.exe",@"s,r,a") //帶參數(shù)調(diào)用進程
System.Diagnostics.Process.Start("shutdown.exe",@"/a");xinxi.Text = xinxi.Text.ToUpper();//字符串轉(zhuǎn)換成大寫
string Password = User1.Substring(6 ,6) ;截取字符串指定長度
Application.StartupPath; 本地路徑
存字符串
File.WriteAllText(@"C:\Users\asus\Desktop\" + textBox1.Text + ".txt", a);設(shè)置拖動改變位置,其實是在空間的點擊和抬起時間里打開和關(guān)閉跟隨的timer
private void timer2_Tick(object sender, EventArgs e)
{int xx = Control.MousePosition.X;//獲得鼠標的xint yy = Control.MousePosition.Y;//獲得鼠標的ythis.Location = new Point(xx - 500, yy - 160);
}獲取當前時間
時間.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");強制直接關(guān)機
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(); 獲取交點if (File.Exists(@"C:\Users\Administrator\Desktop\批處理\常用總結(jié)\if.txt")) MessageBox.Show("ok");判斷該文件是否存在string strHostName = Dns.GetHostName(); //得到本機的主機名
IPHostEntry ipEntry = Dns.GetHostByName(strHostName); //取得本機IP
string strAddr = ipEntry.AddressList[0].ToString(); //假設(shè)本地主機為單網(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
- 下一篇: Intel汇编程序设计-高级过程(上)