自定義控件
創(chuàng)新互聯(lián)建站為您提適合企業(yè)的網(wǎng)站設(shè)計(jì)?讓您的網(wǎng)站在搜索引擎具有高度排名,讓您的網(wǎng)站具備超強(qiáng)的網(wǎng)絡(luò)競(jìng)爭(zhēng)力!結(jié)合企業(yè)自身,進(jìn)行網(wǎng)站設(shè)計(jì)及把握,最后結(jié)合企業(yè)文化和具體宗旨等,才能創(chuàng)作出一份性化解決方案。從網(wǎng)站策劃到成都網(wǎng)站建設(shè)、網(wǎng)站制作, 我們的網(wǎng)頁(yè)設(shè)計(jì)師為您提供的解決方案。
Public?Class?m_richtextbox
Inherits?RichtextBox
Protected?Overrides?Function?ProcessCmdKey(ByRef?msg?As?System.Windows.Forms.Message,?ByVal?keyData?As?System.Windows.Forms.Keys)?As?Boolean
If?msg.WParam.ToInt32()?=?CInt(Keys.Up)?Then
'這里屏蔽的是UP鍵
Return?True
End?If
Return?MyBase.ProcessCmdKey(msg,?keyData)
End?Function
End?Class
最簡(jiǎn)單的加速運(yùn)動(dòng)示例,直接拷貝代碼,即可用方向鍵控制控件移動(dòng)
Public?Class?最簡(jiǎn)單的加速運(yùn)動(dòng)
Dim?左右,?上下?As?Integer
Dim?X,?Y,?VX,?VY,?VA?As?Double
Dim?WithEvents?時(shí)鐘?As?New?Timer
Dim?WithEvents?移動(dòng)控件?As?New?Label
Private?Sub?Form1_Load(sender?As?Object,?e?As?EventArgs)?Handles?MyBase.Load
Me.KeyPreview?=?True
VA?=?0.5
X?=?300.0
Y?=?300.0
移動(dòng)控件.BackColor?=?Color.MediumPurple
移動(dòng)控件.Size?=?New?Size(60,?60)
Controls.Add(移動(dòng)控件)
時(shí)鐘.Interval?=?25
時(shí)鐘.Enabled?=?True
End?Sub
Private?Sub?Form1_KeyDown(sender?As?Object,?e?As?KeyEventArgs)?Handles?MyBase.KeyDown
If?e.KeyCode?=?Keys.Up?Then?上下?=?-1
If?e.KeyCode?=?Keys.Down?Then?上下?=?1
If?e.KeyCode?=?Keys.Left?Then?左右?=?-1
If?e.KeyCode?=?Keys.Right?Then?左右?=?1
End?Sub
Private?Sub?Form1_KeyUp(sender?As?Object,?e?As?KeyEventArgs)?Handles?MyBase.KeyUp
If?e.KeyCode?=?Keys.Up?Then?上下?=?0
If?e.KeyCode?=?Keys.Down?Then?上下?=?0
If?e.KeyCode?=?Keys.Left?Then?左右?=?0
If?e.KeyCode?=?Keys.Right?Then?左右?=?0
End?Sub
Private?Sub?時(shí)鐘_Tick(sender?As?Object,?e?As?EventArgs)?Handles?時(shí)鐘.Tick
VX?=?Math.Min(VX?+?左右?*?VA,?10)
VY?=?Math.Min(VY?+?上下?*?VA,?10)
X?+=?VX
Y?+=?VY
If?X??0?Then?X?=?2?:?VX?=?-VX
If?Y??0?Then?Y?=?2?:?VY?=?-VY
If?X??Width?-?移動(dòng)控件.Width?Then?X?=?Width?-?移動(dòng)控件.Width?-?2?:?VX?=?-VX
If?Y??Height?-?移動(dòng)控件.Height?Then?Y?=?Height?-?移動(dòng)控件.Height?-?2?:?VY?=?-VY
移動(dòng)控件.Location?=?New?Point(X,?Y)
End?Sub
End?Class
1. F12:轉(zhuǎn)到定義;Shift+F12:轉(zhuǎn)到引用
2. F5:?jiǎn)?dòng);Ctrl+F5:開(kāi)始執(zhí)行(不調(diào)試);Shift+F5:停止調(diào)試
3. F7:查看代碼;Shift+F7:查看視圖設(shè)計(jì)器
4. Ctrl+Alt+L:解決方案資源管理器
5. Ctrl+Alt+J:對(duì)象瀏覽器
6. F4:顯示屬性窗口
7. Ctrl+Alt+X:工具箱
8. Ctrl+Alt+C類視圖
9. Alt+Enter:查看屬性
10.F10:逐過(guò)程調(diào)試
11.F11:逐語(yǔ)句調(diào)試
12.Ctrl+B:新斷點(diǎn)
13.Ctrl+Shift+F9:清除所有斷點(diǎn)
14.Ctrl+Shift+B生成解決方案
15.Shift+Alt+Enter:全屏
16.大綱顯示:Ctrl+M, Ctrl+M:切換大綱顯示展開(kāi);Ctrl+M, Ctrl+L:切換所有大綱顯示;Ctrl+M,Crtl+P停止大綱顯示;Ctrl+M, Ctrl+O:折疊到定義
17.智能感知:Ctrl+J:列出成員;Ctrl+Shift+空格:參數(shù)信息; Ctrl+K,Ctrl+I:快速信息;Alt+右箭頭鍵:完成單詞
某些鍵,如 Tab、Return、Esc 和箭頭鍵,由控件自動(dòng)處理。所以當(dāng)你的窗體添加了其它控件如按鈕,checkbox等,form的keydown事件就觸發(fā)不了,為使這些鍵引發(fā)窗體的KeyDown事件,你需要重寫(xiě)form.ProcessDialogKey函數(shù),這個(gè)函數(shù)可以在消息預(yù)處理期間 處理對(duì)話字符,例如TAB、RETURN、ESCAPE和箭頭鍵等,以下是我重寫(xiě)了這個(gè)事件來(lái)處理方向鍵,你需要把它放到你的代碼里:
Protected Overrides Function ProcessDialogKey(ByVal keyData As Keys) As Boolean
If keyData = Keys.Left Or keyData = Keys.Right Or keyData = Keys.Up Or keyData = Keys.Down Then
Return False'如果是方向鍵返回FALSE,意思是繼續(xù)執(zhí)行form的keydown事件.
Else
Return MyBase.ProcessDialogKey(keyData)
End If
End Function