新聞中心
vb標(biāo)簽框和文本框的區(qū)別是什么?
標(biāo)簽框的作用:可以顯示(輸出)文本信息,但不能輸入文本。文本框的作用:可以輸入文本的顯示區(qū)域,既可以輸入也可以輸出文本,并可對(duì)文本進(jìn)行編輯。操作方法如下:
成都創(chuàng)新互聯(lián)公司服務(wù)項(xiàng)目包括德化網(wǎng)站建設(shè)、德化網(wǎng)站制作、德化網(wǎng)頁(yè)制作以及德化網(wǎng)絡(luò)營(yíng)銷策劃等。多年來(lái),我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,德化網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到德化省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
1、首先新建一個(gè)工程,新建一個(gè)標(biāo)準(zhǔn)Exe工程,如下圖。
2、找到工具箱中標(biāo)簽框,找到后可以直接雙擊控件,即可成功繪制。
3、或者可以使用鼠標(biāo)選中它,在頁(yè)面上繪制。
4、如果對(duì)它的外觀不滿意,可以在屬性窗口中
5、鼠標(biāo)找到并雙擊控件,即可進(jìn)入代碼窗口,就可以在這個(gè)根據(jù)自己的需要進(jìn)行添加修改了。
vb點(diǎn)虐 怎樣獲取同類控件名稱
Private?ctrName?As?String?'控件名稱
Private?isClick?As?Boolean?'鼠標(biāo)點(diǎn)擊狀態(tài)
'注:如果已知點(diǎn)擊目標(biāo)控件的父控件,ctrParent變量可以不要。
Private?WithEvents?ctrParent?As?Control?'父控件
Private?Sub?ControlAMouseDown(sender?As?Object,?e?As?MouseEventArgs)?_
Handles?Button1.MouseDown
isClick?=?(e.Button?=?MouseButtons.Left?_
Or?e.Button?=?MouseButtons.Right)?'左鍵或右鍵按下
If?isClick?Then
Dim?ctr?As?Control?=?CType(sender,?Control)?'轉(zhuǎn)換Object為控件類型
ctrName?=?ctr.Name?'獲取控件名稱
ctrParent?=?ctr.Parent?'獲取控件的父控件
End?If
End?Sub
'增加這個(gè)父控件事件,是為了正確判別鼠標(biāo)彈起時(shí)是否已進(jìn)入指定目標(biāo)
Private?Sub?ParentMouseMove(sender?As?Object,?e?As?EventArgs)?_
Handles?ctrParent.MouseMove?'如果已取消ctrParent變量,改為相應(yīng)的父控件
If?isClick?Then?isClick?=?False?'點(diǎn)擊狀態(tài)關(guān)閉
End?Sub
Private?Sub?ControlBMouseUp(sender?As?Object,?e?As?EventArgs)?_
Handles?Button2.MouseEnter
If?isClick?Then?'如果點(diǎn)擊狀態(tài)為打開(kāi)
Dim?ctr?As?Control?=?CType(sender,?Control)?'轉(zhuǎn)換Object為控件類型
MsgBox(ctrName??"?|?"??ctr.Name)?'彈出消息顯示結(jié)果
End?If
End?Sub
vb點(diǎn)虐 入門(mén)之分組控件:GroupBox控件
我們對(duì)控件進(jìn)行分組的原因不外乎三個(gè)
為了獲得清晰的用戶界面而將相關(guān)的窗體元素進(jìn)行可視化分組
編程分組 如對(duì)單選按鈕進(jìn)行分組
為了在設(shè)計(jì)時(shí)將多個(gè)控件作為一個(gè)單元來(lái)移動(dòng)
在中 有GroupBox Panel TabControl這三個(gè)控件可以實(shí)現(xiàn)上面所提到的三個(gè)分組目的 所以我們稱它們?yōu)榉纸M控件
這三個(gè)控件在功用上十分的相似 特別是GroupBox和Panel控件 只存在一點(diǎn)細(xì)微的差別而已(這個(gè)差別是 只有GroupBox控件可以顯示標(biāo)題 而只有Panel控件可以有滾動(dòng)條) 這里我們就先來(lái)了解GroupBox控件的使用
GroupBox(控件組)控件一般是作為其他控件的組的容器的形式存在的 這樣有利于用戶識(shí)別 使界面變得更加友好(GroupBox控件相當(dāng)于Visual Basic以前版本的Frame控件) 使用控件組控件可以將一個(gè)窗體中的各種功能進(jìn)一步進(jìn)行分類 例如 將各種選項(xiàng)按鈕控件分隔開(kāi)
當(dāng)移動(dòng)單個(gè)GroupBox控件時(shí) 它所包含的所有控件也將一起移動(dòng)
在大多數(shù)情況下 對(duì)控件組控件沒(méi)有實(shí)際的操作 我們用它對(duì)控件進(jìn)行分組 通常沒(méi)有必要響應(yīng)它的事件 不過(guò) 它的Name Text和Font等屬性可能會(huì)經(jīng)常被修改 以適應(yīng)應(yīng)用程序在不同階段的要求
GroupBox控件在工具箱中的圖標(biāo)如圖所示
一 GroupBox控件的常用屬性
Anchor和Dock 這兩個(gè)屬性是所有有用戶界面的控件都有的定位屬性 這里就不啰嗦了
Name屬性 標(biāo)識(shí)控件的對(duì)象名稱
Text屬性 顯示在GroupBox控件右上方的標(biāo)題文字 可以用來(lái)標(biāo)識(shí)該控件組的描述
Font和ForeColor屬性 用于改變GroupBox控件的文字大小以及文字的顏色 需要注意的時(shí)候 它不單改變GroupBox控件的Text屬性的文字外觀 同時(shí)也改變其內(nèi)部控件的顯示的Text屬性的文字外觀
二 創(chuàng)建一組控件
在窗體上放置GroupBox控件 從工具箱中拖放一個(gè)GroupBox控件到窗體上的合適位置 調(diào)整大小
在屬性窗口中改變GroupBox控件的Text屬性 作為它的標(biāo)題
在GroupBox控件內(nèi)拖放其它需要的控件 例如RadioButton控件
設(shè)置示例 如圖一所示
圖一 用控件組控件對(duì)單選按鈕分組
我們?cè)谕蟿?dòng)單個(gè)GroupBox控件的時(shí)候 它內(nèi)部的控件也會(huì)隨著移動(dòng) 以保持和GroupBox的相對(duì)位置不變 同理 刪除GroupBox控件時(shí) 它所包含的所有控件也會(huì)被刪除掉
當(dāng)我們調(diào)整GroupBox控件所包含的控件的Anchor和Dock屬性的時(shí)候 其參照物將不是Form窗體 而是GroupBox控件了
三 編程添加GroupBox控件以及它所包含的控件
雖然GroupBox控件是在設(shè)計(jì)時(shí)用視圖設(shè)計(jì)布局效果最好 但是無(wú)可避免地 很多特殊情況下也是需要在運(yùn)行做添加控件到控件組中的 這里我們就用代碼來(lái)完成上圖一界面的繪制
動(dòng)態(tài)添加控件一般需要經(jīng)過(guò)下面三個(gè)步驟
創(chuàng)建要添加的控件實(shí)例
設(shè)置新控件的屬性
將控件添加到父控件的 Controls 集合
在Form 代碼的任意位置增加初始化控件的過(guò)程InitializeControl() 代碼如下所示
Sub InitializeControl()
首先添加Label和TextBox控件
Dim Label As New System Windows Forms Label
Dim TextBox As New System Windows Forms TextBox
Label
Label Location = New System Drawing Point( )
Label Name = Label
Label Size = New System Drawing Size( )
Label TabIndex =
Label Text = 戶主姓名
TextBox
TextBox Location = New System Drawing Point( )
TextBox Name = TextBox
TextBox Size = New System Drawing Size( )
TextBox TabIndex =
TextBox Text =
把它們添加到父控件Form 的Controls集合中
Me Controls Add(TextBox )
Me Controls Add(Label )
添加三個(gè)GroupBox控件
Dim GroupBox As New System Windows Forms GroupBox
Dim GroupBox As New System Windows Forms GroupBox
Dim GroupBox As New System Windows Forms GroupBox
GroupBox
GroupBox BackColor = System Drawing SystemColors Control
GroupBox Location = New System Drawing Point( )
GroupBox Name = GroupBox
GroupBox Size = New System Drawing Size( )
GroupBox TabIndex =
GroupBox TabStop = False
GroupBox Text = 性別
GroupBox
GroupBox Location = New System Drawing Point( )
GroupBox Name = GroupBox
GroupBox Size = New System Drawing Size( )
GroupBox TabIndex =
GroupBox TabStop = False
GroupBox Text = 單元
GroupBox
GroupBox Location = New System Drawing Point( )
GroupBox Name = GroupBox
GroupBox Size = New System Drawing Size( )
GroupBox TabIndex =
GroupBox TabStop = False
GroupBox Text = 樓層
把它們添加到父控件Form 的Controls集合中
Me Controls Add(GroupBox )
Me Controls Add(GroupBox )
Me Controls Add(GroupBox )
添加RadioButton控件并分別繪制在GroupBox控件內(nèi)
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
Dim RadioButton As New System Windows Forms RadioButton
RadioButton
RadioButton Location = New System Drawing Point( )
RadioButton Name = RadioButton
RadioButton Size = New System Drawing Size( )
RadioButton TabIndex =
RadioButton Text = 男性
RadioButton
RadioButton Location = New System Drawing Point( )
RadioButton Name = RadioButton
RadioButton Size = New System Drawing Size( )
RadioButton TabIndex =
RadioButton Text = 女性
RadioButton
RadioButton Location = New System Drawing Point( )
RadioButton Name = RadioButton
RadioButton Size = New System Drawing Size( )
RadioButton TabIndex =
RadioButton Text = 二單元
RadioButton
RadioButton Location = New System Drawing Point( )
RadioButton Name = RadioButton
RadioButton Size = New System Drawing Size( )
RadioButton TabIndex =
RadioButton Text = 三單元
RadioButton
RadioButton Location = New System Drawing Point( )
RadioButton Name = RadioButton
RadioButton Size = New System Drawing Size( )
RadioButton TabIndex =
RadioButton Text = 一單元
RadioButton
RadioButton BackColor = System Drawing SystemColors Control
RadioButton Location = New System Drawing Point( )
RadioButton Name = RadioButton
RadioButton Size = New System Drawing Size( )
RadioButton TabIndex =
RadioButton Text = 四單元
RadioButton
RadioButton Location = New System Drawing Point( )
RadioButton Name = RadioButton
RadioButton Size = New System Drawing Size( )
RadioButton TabIndex =
RadioButton Text = 二樓
RadioButton
RadioButton Location = New System Drawing Point( )
RadioButton Name = RadioButton
RadioButton Size = New System Drawing Size( )
RadioButton TabIndex =
RadioButton Text = 三樓
RadioButton
RadioButton Location = New System Drawing Point( )
RadioButton Name = RadioButton
RadioButton Size = New System Drawing Size( )
RadioButton TabIndex =
RadioButton Text = 一樓
RadioButton
RadioButton BackColor = System Drawing SystemColors Control
RadioButton Location = New System Drawing Point( )
RadioButton Name = RadioButton
RadioButton Size = New System Drawing Size( )
RadioButton TabIndex =
RadioButton Text = 四樓
分別把它們添加到父控件GroupBox的Controls集合中
GroupBox Controls Add(RadioButton )
GroupBox Controls Add(RadioButton )
GroupBox Controls Add(RadioButton )
GroupBox Controls Add(RadioButton )
GroupBox Controls Add(RadioButton )
GroupBox Controls Add(RadioButton )
GroupBox Controls Add(RadioButton )
GroupBox Controls Add(RadioButton )
GroupBox Controls Add(RadioButton )
GroupBox Controls Add(RadioButton )
End Sub
把上一頁(yè)的代碼復(fù)制添加后 把控件初始化過(guò)程InitializeControl()過(guò)程添加到Form 的New構(gòu)造函數(shù)中 如下圖二所示
圖二 在New構(gòu)造函數(shù)中添加過(guò)程InitializeControl()
現(xiàn)在按F 運(yùn)行 Form 的窗體控件布局(如下圖三所示)是不是和我們手工布局的圖一的布局是一樣的呢?
lishixinzhi/Article/program/ASP/201311/21749
網(wǎng)頁(yè)名稱:vb點(diǎn)虐 控件前綴 vb各種控件
URL分享:http://fisionsoft.com.cn/article/ddiepoj.html