中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

C#常用操作

2018-07-20    來源:open-open

容器云強(qiáng)勢上線!快速搭建集群,上萬Linux鏡像隨意使用
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(); // 創(chuàng)建MID窗口
f.MdiParent = this; // 設(shè)置父窗口
f.BackgroundImage = p; // 設(shè)置MDI窗口的背景圖
f.Show(); // 顯示MDI窗口
 
4. Bitmap - 位圖類
// 創(chuàng)建位圖, Bitmap類繼承于Image類
Bitmap bit;
bit = new Bitmap("heart.bmp");
bit.MakeTransparent(Color.White); // 設(shè)置透明色
 
protected override void OnPaint(PaintEventArgs e)
{
// 在窗口上畫圖
e.Graphics.DrawImage((Image)bit, new Point(0, 0));
}
 
5. this.Opacity - 控件的不透明度
// 控制控件透明程度,很有用。
 
6. C#中導(dǎo)入Dll文件中的API
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
public static extern bool FlashWindow(IntPtr handle, bool bInvert);
 
7. 隱藏標(biāo)題欄
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. 獲得鼠標(biāo)在窗口中的坐標(biāo)
Cursor.Clip = new Rectangle(this.Location, this.Size);
label1.Text = "當(dāng)前鼠標(biāo)的位置為:" + 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. 控制遠(yuǎn)程計算機(jī)
//首先添加對 System.Management的引用
private void CloseComputer(string strname,string strpwd,string ip,string doinfo)
{
ConnectionOptions op = new ConnectionOptions ( ) ;
op.Username =strname;//''或者你的帳號(注意要有管理員的權(quán)限)
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();
}
}
 
// 重啟遠(yuǎn)程計算機(jī)
CloseComputer(this.textBox2.Text, this.textBox3.Text, this.textBox1.Text, "Reboot");
 
// 關(guān)閉遠(yuǎn)程計算機(jī)
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 ? "發(fā)生分段" : "沒有發(fā)生分段");
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;
}

標(biāo)簽: 權(quán)限

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:C#檢測網(wǎng)絡(luò)驅(qū)動器的剩余磁盤空間

下一篇:C# 獲取內(nèi)存和CPU信息的代碼