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;
}

c#常见操作的更多相关文章

  1. 动态单链表的传统存储方式和10种常见操作-C语言实现

    顺序线性表的优点:方便存取(随机的),特点是物理位置和逻辑为主都是连续的(相邻).但是也有不足,比如:前面的插入和删除算法,需要移动大量元素,浪费时间,那么链式线性表 (简称链表) 就能解决这个问题. ...

  2. C#路径/文件/目录/I/O常见操作汇总

    文件操作是程序中非常基础和重要的内容,而路径.文件.目录以及I/O都是在进行文件操作时的常见主题,这里想把这些常见的问题作个总结,对于每个问题,尽量提供一些解决方案,即使没有你想要的答案,也希望能提供 ...

  3. X-Cart 学习笔记(四)常见操作

    目录 X-Cart 学习笔记(一)了解和安装X-Cart X-Cart 学习笔记(二)X-Cart框架1 X-Cart 学习笔记(三)X-Cart框架2 X-Cart 学习笔记(四)常见操作 五.常见 ...

  4. 转:jQuery 常见操作实现方式

    http://www.cnblogs.com/guomingfeng/articles/2038707.html 一个优秀的 JavaScript 框架,一篇 jQuery 常用方法及函数的文章留存备 ...

  5. jQuery 常见操作实现方式

    一个优秀的 JavaScript 框架,一篇 jQuery 常用方法及函数的文章留存备忘. jQuery 常见操作实现方式 $("标签名") //取html元素 document. ...

  6. C#路径/文件/目录/I/O常见操作汇总<转载>

    文件操作是程序中非常基础和重要的内容,而路径.文件.目录以及I/O都是在进行文件操作时的常见主题,这里想把这些常见的问题作个总结,对于每个问题,尽量提供一些解决方案,即使没有你想要的答案,也希望能提供 ...

  7. [java学习笔记]java语言基础概述之数组的定义&常见操作(遍历、排序、查找)&二维数组

    1.数组基础 1.什么是数组:           同一类型数据的集合,就是一个容器. 2.数组的好处:           可以自动为数组中的元素从零开始编号,方便操作这些数据. 3.格式:  (一 ...

  8. 【转】C#路径/文件/目录/I/O常见操作汇总

    文件操作是程序中非常基础和重要的内容,而路径.文件.目录以及I/O都是在进行文件操作时的常见主题,这里想把这些常见的问题作个总结,对于每个问题,尽量提供一些解决方案,即使没有你想要的答案,也希望能提供 ...

  9. C#路径,文件,目录,I/O常见操作

         C#路径,文件,目录,I/O常见操作 文件操作是程序中非常基础和重要的内容,而路径.文件.目录以及I/O都是在进行文件操作时的常见主题,这里想把这些常见的问题作个总结,对于每个问题,尽量提供 ...

  10. 【代码学习】MYSQL数据库的常见操作

    ---恢复内容开始--- ============================== MYSQL数据库的常见操作 ============================== 一.mysql的连接与 ...

随机推荐

  1. 图片拉伸: stretchableImageWithLeftCapWidth

    - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight: (NSInteger)topCa ...

  2. C#版QQTea加密

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Wind ...

  3. plaidctf2015 ebp

    很容易看出是格式化字符串漏洞.这里的格式化字符串漏洞不像传统的那样,格式化字符串是放在bss段中,并没放在栈上,因此利用起来有些困难. 不过,我们可以利用ebp,可以修改函数的ebp,从而能控制函数的 ...

  4. CXF interceptor拦截顺序

    CXF Interceptor中Phase的先后顺序 org.apache.cxf.phase.PhaseManagerImpl中 final void createInPhases() { int  ...

  5. SqlHelper数据库访问类

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  6. 详解Linq to SQL

    第一部分,什么是Linq to sql Linq to sql(或者叫DLINQ)是LINQ(.NET语言集成查询)的一部分,全称基于关系数据的 .NET 语言集成查询,用于以对象形式管理关系数据,并 ...

  7. UIScrollView基本使用

    - (void)viewDidLoad { [super viewDidLoad]; scrollView = [[UIScrollView alloc] initWithFrame:CGRectMa ...

  8. C++中数字与字符串之间的转换,别人的,

    C++中数字与字符串之间的转换   1.字符串数字之间的转换 (1)string --> char *   string str("OK");   char * p = st ...

  9. 库函数strlen源码重现及注意问题

    首先直接上源码: size_t strlen (const char * str) { const char *eos = str; while(*eos++); return(eos - str - ...

  10. 如何对MySQL 对于大表(千万级)进行优化

    如何对Mysql中的大型表进行优化 @(mysql 笔记) 收集信息 1.数据的容量:1-3年内会大概多少条数据,每条数据大概多少字节: 2.数据项:是否有大字段,那些字段的值是否经常被更新: 3.数 ...