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") //带参数调用进程
System.Diagnostics.Process.Start("shutdown.exe",@"/a");xinxi.Text = xinxi.Text.ToUpper();//字符串转换成大写
string Password = User1.Substring(6 ,6) ;截取字符串指定长度
Application.StartupPath; 本地路径
存字符串
File.WriteAllText(@"C:\Users\asus\Desktop\" + textBox1.Text + ".txt", a);设置拖动改变位置,其实是在空间的点击和抬起时间里打开和关闭跟随的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");强制直接关机
System.Diagnostics.Process.Start("shutdown.exe", @"/r");重启
System.Diagnostics.Process.Start("shutdown.exe", @"/l"); 注销字符串和byte之间的转换
string tmp = Encoding.UTF8.GetString(result, 0, len);
Encoding.UTF8.GetBytes("aaaaa")this.TopMost = true;最前面
textbox1.Focus(); 获取交点if (File.Exists(@"C:\Users\Administrator\Desktop\批处理\常用总结\if.txt")) MessageBox.Show("ok");判断该文件是否存在string strHostName = Dns.GetHostName(); //得到本机的主机名
IPHostEntry ipEntry = Dns.GetHostByName(strHostName); //取得本机IP
string strAddr = ipEntry.AddressList[0].ToString(); //假设本地主机为单网卡指定路径的文件变成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 { }}
总结
- 上一篇: C#-MD5
- 下一篇: Intel汇编程序设计-高级过程(上)