




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
開通黃鉆寒假總結(jié)(2)鼠標鍵盤系統(tǒng)的基本操作usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;namespace鼠標
{
publicpartialclassForm1:Form
{
MessageFiltermf=newMessageFilter();
publicForm1()
{
InitializeComponent();
}
privatevoidForm1_MouseDown(objectsender,MouseEventArgse)
{//獲取鼠標點擊時位置XY坐標
this.label1.Text=e.X.ToString();
this.label2.Text=e.Y.ToString();
}
privatevoidtextBox1_MouseDown(objectsender,MouseEventArgse)
{//獲取鼠標操作操作
stringstr=textBox1.Text;
if(e.Button==MouseButtons.Right)
{
textBox1.Text+="鼠標右擊點下";
}
if(e.Button==MouseButtons.Left)
{
textBox1.Text+="鼠標左擊點下";
}
if(e.Button==MouseButtons.Middle)
{
textBox1.Text+="鼠標中間點下";
}
if(e.Button==MouseButtons.None)
{
textBox1.Text+="未按鼠標";
}
}
privatevoidForm1_Load(objectsender,EventArgse)
{
//添加消息篩選器以便在向目標傳送Windows消息時監(jiān)視這些消息
Application.AddMessageFilter(mf);
}
//從窗體中移除一個消息篩選器
privatevoidFrm_Main_FormClosing(objectsender,FormClosingEventArgse)
{
//從應(yīng)用程序的消息泵移除一個消息篩選器
Application.RemoveMessageFilter(mf);
}
//方法一,重寫WndProc虛方法,與方法二不可同時存在
protectedoverridevoidWndProc(refMessagem)
{
switch(m.Msg)//判斷系統(tǒng)消息的ID號
{
case513:
MessageBox.Show("單擊了鼠標左鍵!","系統(tǒng)信息");
m.Result=(IntPtr)0;//為了響應(yīng)消息處理而向Windows返回的值
break;
case516:
MessageBox.Show("單擊了鼠標右鍵!","系統(tǒng)信息");
m.Result=(IntPtr)0;//為了響應(yīng)消息處理而向Windows返回的值
break;
default:
base.WndProc(refm);
break;
}
}
}
//方法二,實現(xiàn)IMessageFilter接口,從而獲得Windows消息,與方法一不可同時存在
publicclassMessageFilter:IMessageFilter
{
publicboolPreFilterMessage(refMessagemessage)
{
switch(message.Msg)//判斷系統(tǒng)消息的ID號
{
this.Cursor=newCursor(Cursor.Current.Handle);//創(chuàng)建cursor對象
Cursor.Position=newPoint(Cursor.Position.X,Cursor.Position.Y);//設(shè)置鼠標位置
Cursor.Clip=newRectangle(this.Location,this.Size);//設(shè)置鼠標的活動區(qū)域
}
privatevoidbutton2_Click(objectsender,EventArgse)
{
Screen[]screens=Screen.AllScreens;//獲取顯示的數(shù)組
this.Cursor=newCursor(Cursor.Current.Handle);//創(chuàng)建Cursor對象
Cursor.Clip=screens[0].Bounds;//接觸對鼠標活動區(qū)域的限制
}
publicboolG_OnMouseDown=false;//標識,用來控制畫圖
publicPointlastPoint=Point.Empty;//定義繪圖開始點
publicPenpen;//聲明畫筆
publicGraphicsgraphics;//聲明繪圖對象
privatevoidForm2_MouseMove(objectsender,MouseEventArgse)
{
if(lastPoint.Equals(Point.Empty))//判斷繪圖開始點是否為空
{
lastPoint=newPoint(e.X,e.Y);//記錄鼠標當前位置
}
if(G_OnMouseDown)//開始繪圖
{
PointcruuPoint=newPoint(e.X,e.Y);//獲取鼠標當前位置
graphics.DrawLine(pen,cruuPoint,lastPoint);//繪圖
}
lastPoint=newPoint(e.X,e.Y);//記錄鼠標當前位置
}
privatevoidForm2_MouseUp(objectsender,MouseEventArgse)
{
G_OnMouseDown=false;//開始繪圖標識設(shè)置為false
}
privatevoidForm2_MouseDown(objectsender,MouseEventArgse)
{
G_OnMouseDown=true;//開始繪圖標識設(shè)置為true````
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;namespace鍵盤
{
publicpartialclassForm1:Form
{
publicForm1()
{
InitializeComponent();
}
privatevoidtextBox1_KeyDown(objectsender,KeyEventArgse)
{
/*if((e.Control==true)&&(e.KeyCode==Keys.A))
{
MessageBox.Show("你按下了ctrl+A","系統(tǒng)",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
}*/
}
privatevoidForm1_Load(objectsender,EventArgse)
{
Form1f=newForm1();
f.KeyPreview=true;
}
///<summary>
///移動窗體
///</summary>
///<paramname="sender"></param>
///<paramname="e"></param>
privatevoidForm1_KeyDown(objectsender,KeyEventArgse)
{
Pointpoint=this.Location;
switch(e.KeyData)//判斷按鍵類型
{
caseKeys.Up:
point.Y-=2;
break;
case
Keys.Down:
point.Y+=2;
break;
caseKeys.Right:
point.X+=2;
break;
caseKeys.Left:
point.X-=2;
break;
caseKeys.Escape:
this.Close();
break;
default:break;
}
this.Location=point;
}
/*
privatevoidForm1_KeyDown(objectsender,KeyEventArgse)
{
if(e.Alt&&e.KeyCode==Keys.F4)//鍵值115
{
e.Handled=true;//不執(zhí)行操作
}
if(e.KeyCode==Keys.F1)
{
MessageBox.Show("王延領(lǐng)按下了f1","提示");
}
}
privatevoidForm1_KeyUp(objectsender,KeyEventArgse)
{
if(e.KeyData==Keys.Escape)//按下esc時
{
if(MessageBox.Show("是否關(guān)閉程序","提示信息",MessageBoxButtons.YesNo)==DialogResult.Yes)
{
Application.Exit();
}
}
}
privatevoidrichTextBox1_KeyDown(objectsender,KeyEventArgse)
{
if(e.Control&&e.KeyCode==Keys.V)
{
e.Handled=true;//屏蔽CRTRL+V
}
if(e.Control&&e.KeyCode==Keys.X||e.KeyCode==Keys.C)
{
e.Handled=true;
}
}
privatevoidtextBox1_KeyPress(objectsender,KeyPressEventArgse)
{//釋放后發(fā)生事件
if(e.KeyChar==13)
{
e.Handled=true;//關(guān)閉敲回車鍵嘀的聲音
}
}
///<summary>
///輸入法的打開與關(guān)閉
///</summary>
///<paramname="sender"></param>
///<paramname="e"></param>
privatevoidbutton1_Click(objectsender,EventArgse)
{
this.textBox1.ImeMode=ImeMode.Off;//關(guān)閉輸入法
}
privatevoidbutton2_Click(objectsender,EventArgse)
{
this.textBox1.ImeMode=ImeMode.On;
}
privatevoidForm1_Load(objectsender,EventArgse)
{
Form1f=newForm1();
f.KeyPreview=true;//接受案件控件
}
/*
[System.Runtime.InteropServices.DllImport("user32",EntryPoint="GetKeyState")]//重寫Api
publicstaticexternintGetKeyState(intintkey);
privatevoidbutton1_Click(objectsender,EventArgse)
{
stringstr="判斷numlockhrcapslock鍵是否鎖定:\n";
intintnumlock=GetKeyState(144);//判斷numlock鍵
if(intnumlock==0)
{
str+="numlock未鎖定\n";
}
else{
str+="numlock已鎖定\n";
}
intintcapslock=GetKeyState(20);
if(intcapslock==0)
{
str+="caplock未鎖定\n";
}
else
{
str+="caplock已鎖定\n";
}
MessageBox.Show(str,"判斷");
}
privatevoidtextBox1_KeyDown_1(objectsender,KeyEventArgse)
{
if(e.KeyValue==13)//如果鍵值為13(回車鍵)
{
SendKeys.Send("{TAB}");//發(fā)送TAB命令
}
}
privatevoidtextBox2_KeyDown(objectsender,KeyEventArgse)
{
if(e.KeyValue==13)
{
SendKeys.Send("{TAB}");
}
}*/
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;namespace系統(tǒng)
{
publicpartialclassForm1:Form
{
publicForm1()
{
InitializeComponent();
}
privatevoidForm1_Load(objectsender,EventArgse)
{
label1.Text="當前時間是:"+DateTime.Now.ToString();//獲取現(xiàn)在時間
label2.Text="當前系統(tǒng)目錄"+Environment.SystemDirectory;
label3.Text="計算機名稱:"+Environment.MachineName;
label4.Text="當前運行目錄:"+Environment.CurrentDirectory;
label5.Text="系統(tǒng)版本號:"+Environment.OSVersion.VersionString;
textBox1.Text=(Environment.TickCount/1000).ToString()+"秒";//獲取啟動后經(jīng)過的時間
}
privatevoidtimer1_Tick(objectsender,EventArgse)
{
textBox1.Text=(Environment.TickCount/1000).ToString()+"秒";
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Collections;
namespace獲取系統(tǒng)環(huán)境變量
{
publicpartialclassForm1:Form
{
publicForm1()
{
InitializeComponent();
}
privatevoidForm1_Load(objectsender,EventArgse)
{
listView1.View=View.Details;//設(shè)置控件顯示方式
listView1.GridLines=true;//是否顯示網(wǎng)格
listView1.Columns.Add("環(huán)境變量",150,HorizontalAlignment.Left);//添加列標頭
listView1.Columns.Add("變量值",150,HorizontalAlignment.Left);//添加列標頭
ListViewItemmyItem;//創(chuàng)建ListViewItem對象
//獲取系統(tǒng)環(huán)境變量及對應(yīng)的變量值,并顯示在ListView控件中
foreach(DictionaryEntryDEntryinEnvironment.GetEnvironmentVariables())
{
myItem=newListViewItem(DEntry.Key.ToString(),0);//創(chuàng)建ListViewItem對象
myItem.SubItems.Add(DEntry.Value.ToString());//添加子項集合
listView1.Items.Add(myItem);//將子項集合添加到控件中
}
}
}
}
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;namespace獲取所有邏輯分區(qū)
{
publicpartialclassForm1:Form
{
publicForm1()
{
InitializeComponent();
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
listFolders(comboBox1);
}
publicvoidlistFolders(ComboBoxtscb)//獲取本地磁盤目錄
{
string[]logicdrives=System.IO.Directory.GetLogicalDrives();//獲取本地邏輯分區(qū)的數(shù)組
for(inti=0;i<logicdrives.Length;i++)//遍歷數(shù)組
{
tscb.Items.Add(logicdrives[i]);//將數(shù)組中的項目添加到ComboBox控件中
tscb.SelectedIndex=0;//設(shè)置第一項被選中
}
}
privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse)
{
try
{
System.IO.DriveInfo[]drive=System.IO.DriveInfo.GetDrives();//獲取所有磁盤驅(qū)動
for(inti=0;i<drive.Length;i++)//遍歷數(shù)組
{
if(comboBox1.SelectedItem.ToString()==drive[i].Name)//判斷遍歷到的想是否與下拉框中的項相同
{
label1.Text="總空間"+drive[i].TotalSize/1024/1024/1024+"G";
label2.Text="剩余空間"+drive[i].TotalFreeSpace/1024/1024/1024+"G";
label3.Text="已用空間"+(drive[i].TotalSize-drive[i].TotalFreeSpace)/1024/1024/1024+"G";
}
if(comboBox1.SelectedItem.ToString()==drive[i].Name)
{
if(drive[i].IsReady)
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 南京大學金陵學院《商業(yè)大數(shù)據(jù)項目管理綜合實驗》2023-2024學年第二學期期末試卷
- 2025年物聯(lián)網(wǎng)是考試題及答案
- 2025年護心游戲測試題及答案
- 2025年金泉小學面試題及答案
- 2025年資展金融面試題及答案
- 2025年育嬰班結(jié)業(yè)考試題及答案
- 2025年五法普法考試試題及答案
- 醫(yī)生綜合復習試題附答案
- 2025年圖案簡筆畫考試題及答案
- 2025年教育資格面試試題及答案
- 瀝青基材料在石油化工設(shè)備熱絕緣中的開發(fā)
- 工業(yè)機器人編程語言:URScript(UniversalRobots):UR機器人安全編程與碰撞檢測
- 2024屆中考語文第一輪復習《綜合性學習》教學課件
- 5.1 實數(shù)指數(shù)冪-中職數(shù)學教學設(shè)計(高教版2021基礎(chǔ)模塊 下冊)
- 2024湖南株洲市天元區(qū)面向社會招聘社區(qū)專職工作者筆試歷年典型考題及考點剖析附答案帶詳解
- 煤層底板采動破裂深度壓水
- 新人教小學數(shù)學六年級下冊《成數(shù)》示范課教學課件
- JTS-304-2019水運工程水工建筑物檢測與評估技術(shù)規(guī)范
- 巖土工程領(lǐng)域的前沿技術(shù)與未來發(fā)展
- CAR-T細胞療法行業(yè)營銷策略方案
- 國家開放大學電大《現(xiàn)代漢語》形考任務(wù)參考答案
評論
0/150
提交評論