1. StreamWriter - 文件写入类
StreamWriter s = new StreamWriter(address + "/Menu.ini", true);
s.WriteLine(openFileDialog1.FileName);
s.Flush();
s.Close();

2. StreamReader - 文件读取类
StreamReader sr = new StreamReader(address + "/Menu.ini");
while (sr.Peek()>=0)
{
string str = sr.ReadLine();
}
sr.Close();

3. Image - 图像类
Image p = Image.FromFile("/背景图片.jpg");
Form f = new Form(); // 创建MID窗口
f.MdiParent = this; // 设置父窗口
f.BackgroundImage = p; // 设置MDI窗口的背景图
f.Show(); // 显示MDI窗口

4. Bitmap - 位图类
// 创建位图, Bitmap类继承于Image类
Bitmap bit;
bit = new Bitmap("heart.bmp");
bit.MakeTransparent(Color.White); // 设置透明色

protected override void OnPaint(PaintEventArgs e)
{
// 在窗口上画图
e.Graphics.DrawImage((Image)bit, new Point(0, 0));
}

5. this.Opacity - 控件的不透明度
// 控制控件透明程度,很有用。

6. C#中导入Dll文件中的API
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
public static extern bool FlashWindow(IntPtr handle, bool bInvert);

7. 隐藏标题栏
this.ControlBox = false;

8. 窗口始终处于最上面
this.TopMost = ture;

9. Screen - 桌面类
Screen.PrimaryScreen.WorkingArea.Height // 桌面的高
Screen.PrimaryScreen.WorkingArea.Width // 桌面的宽
Screen.PrimaryScreen.BitsPerPixel // 桌面的位深

10. 基本绘图
Graphics graphics;
Pen myPen = new Pen(Color.Blue, 2);

// 画线
graphics = this.CreateGraphics();
graphics.DrawLine(myPen, 30, 60, 150, 60);

// 画矩形
graphics = this.CreateGraphics();
graphics.DrawRectangle(myPen, 30, 80, 120, 50);

// 画椭圆
graphics = this.CreateGraphics();
Rectangle myRectangle = new Rectangle(160, 70, 100, 60);
graphics.DrawEllipse(myPen, myRectangle);

11. 获得鼠标在窗口中的坐标
Cursor.Clip = new Rectangle(this.Location, this.Size);
label1.Text = "当前鼠标的位置为:" + Cursor.Position;

12. 判断键盘
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;
string strInfo = string.Empty;
if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
switch (keyData)
{
case Keys.Down:
strInfo = "Down Key";
break;
case Keys.Up:
strInfo = "Up Key";
break;
case Keys.Left:
strInfo = "Left Key";
break;
case Keys.Right:
strInfo = "Right Key";
break;
case Keys.Home:
strInfo = "Home Key";
break;
case Keys.End:
strInfo = "End Key";
break;
}
MessageBox.Show(strInfo, "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
return base.ProcessCmdKey(ref msg, keyData);
}

13. 控制远程计算机
//首先添加对 System.Management的引用
private void CloseComputer(string strname,string strpwd,string ip,string doinfo)
{
ConnectionOptions op = new ConnectionOptions ( ) ;
op.Username =strname;//''或者你的帐号(注意要有管理员的权限)
op.Password = strpwd; //''你的密码
ManagementScope scope = new ManagementScope("////" + ip + "//root//cimv2:Win32_Service", op);
try
{
scope.Connect ( ) ;
System.Management.ObjectQuery oq = new System.Management.ObjectQuery ( "SELECT * FROM Win32_OperatingSystem" ) ;
ManagementObjectSearcher query1 = new ManagementObjectSearcher (scope,oq) ;
//得到WMI控制
ManagementObjectCollection queryCollection1 = query1.Get ( ) ;
foreach ( ManagementObject mobj in queryCollection1 )
{
string [ ] str= {""} ;
mobj.InvokeMethod(doinfo, str);
}
MessageBox.Show("操作成功");
}
catch(Exception ey)
{
MessageBox.Show(ey.Message);
//this.button1.PerformClick();
}
}

// 重启远程计算机
CloseComputer(this.textBox2.Text, this.textBox3.Text, this.textBox1.Text, "Reboot");

// 关闭远程计算机
CloseComputer(this.textBox2.Text, this.textBox3.Text, this.textBox1.Text, "Shutdown");

14. ping的使用
Ping PingInfo = new Ping();
PingOptions PingOpt = new PingOptions();
PingOpt.DontFragment = true;
string myInfo = "hyworkhyworkhyworkhyworkhyworkhywork";
byte[] bufferInfo = Encoding.ASCII.GetBytes(myInfo);
int TimeOut = 120;
PingReply reply = PingInfo.Send(this.textBox1.Text, TimeOut, bufferInfo, PingOpt);
if (reply.Status == IPStatus.Success)
{
this.textBox2.Text = reply.RoundtripTime.ToString();
this.textBox3.Text = reply.Options.Ttl.ToString();
this.textBox4.Text = (reply.Options.DontFragment ? "发生分段" : "没有发生分段");
this.textBox5.Text = reply.Buffer.Length.ToString();
}
else
{
MessageBox.Show("无法Ping通");
}

15. 检查文件是否存在
public int CheckFileExit(string ObjFilePath)
{
if (File.Exists(ObjFilePath))
return 0;
else
return -1;
}

最新文章

  1. 用CS的思维可以指导BS的项目吗?
  2. Android真机调试 Android.Util.AndroidRuntimeException: You cannot combine custom titles with other title features
  3. TensorFlow中权重的随机初始化
  4. [fortify] open redirect漏洞
  5. Python 学习笔记二
  6. 让ecshop用户名、手机号、email登陆方法
  7. FLTK 1.3.3 MinGW 4.9.1 Configuration 配置
  8. IDEA UML类图插件
  9. IIS Shared Configuration
  10. 移动平台中 meta 标签的使用
  11. Hbuilder开发移动App(1)
  12. iOS 懒加载模式
  13. ElasticSearch6学习(1)-安装Elasticsearch
  14. ES6之Object.assign()详解
  15. 【做题】agc008f - Black Radius——计数&讨论&思维
  16. C# iframe session 丢失
  17. 使用TCP协议的NAT穿透技术(转)
  18. idea常用设置(持续更新)
  19. 【转】Hibernate的getSQLQuery方法对char类型的解析问题
  20. Oracle的启动与关闭

热门文章

  1. NODE.JS安装配置
  2. hdu 2222 Keywords_ac自动机模板
  3. Android Studio Build选项的功能
  4. js/jquery中实现图片轮播
  5. Oracle 存储过程之通用分页查询
  6. Android学习自定义Dialog
  7. 图的广度优先/层次 遍历(BFS) c++ 队列实现
  8. eclipse 和myEclipse 项目导入
  9. java中等于和equals的区别
  10. Oracle EBS-SQL (WIP-10):检查车间任务状态“完成”但未发料数据.sql