新聞中心
VB.NET是目前應(yīng)用比較廣泛的編程語(yǔ)言。它在文件處理,移動(dòng)設(shè)備操作,圖形界面的處理方面都能夠體現(xiàn)強(qiáng)大的作用。那么今天我們就一起學(xué)習(xí)一個(gè)其中的應(yīng)用技巧,VB.NET制作圖片按鈕的實(shí)際操作方法。

公司主營(yíng)業(yè)務(wù):成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、移動(dòng)網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。創(chuàng)新互聯(lián)公司是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來(lái)驚喜。創(chuàng)新互聯(lián)公司推出潁上免費(fèi)做網(wǎng)站回饋大家。
VB.NET制作圖片按鈕思路:很簡(jiǎn)單,就是在一個(gè)picturebox控件上放置一個(gè)button控件,然后將這個(gè)button添加進(jìn)picturebox上(確保先拖拽picturebox,后拖拽button),設(shè)置這個(gè)button的背景色(這個(gè)時(shí)候是相對(duì)于picturebox)為透明。
- Imports System.ComponentModel
- Public Class picturebutton
- Inherits System.Windows.Forms.UserControl
- #Region " Windows 窗體設(shè)計(jì)器生成的代碼 "
- 'UserControl 重寫 dispose 以清理組件列表。
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- 'Windows 窗體設(shè)計(jì)器所必需的
- Private components As System.ComponentModel.IContainer
注意:以下VB.NET制作圖片按鈕的過程是 Windows 窗體設(shè)計(jì)器所必需的
可以使用 Windows 窗體設(shè)計(jì)器修改此過程。
不要使用代碼編輯器修改它。
- Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
- Friend WithEvents Button1 As System.Windows.Forms.Button
Private Sub InitializeComponent()- Me.PictureBox1 = New System.Windows.Forms.PictureBox()
- Me.Button1 = New System.Windows.Forms.Button()
- Me.SuspendLayout()
- 'PictureBox1
- Me.PictureBox1.Name = "PictureBox1"
- Me.PictureBox1.Size = New System.Drawing.Size(136, 40)
- Me.PictureBox1.TabIndex = 0
- Me.PictureBox1.TabStop = False
- 'Button1
- Me.Button1.Name = "Button1"
- Me.Button1.TabIndex = 1
- Me.Button1.Text = "Button1"
- 'picturebutton
- Me.Controls.AddRange(New System.Windows.Forms.Control()
{Me.Button1, Me.PictureBox1})- Me.Name = "picturebutton"
- Me.ResumeLayout(False)
- End Sub
- #End Region
- Public Sub New()
- MyBase.New()
該調(diào)用是 Windows 窗體設(shè)計(jì)器所必需的。
- InitializeComponent()
- '在 InitializeComponent() 調(diào)用之后添加任何初始化
- Me.Button1.Width = 100 ‘設(shè)置按鈕的初始大小
- Me.Button1.Height = 23
- Me.Button1.BackColor = Color.Transparent ‘背景色透明
- Me.Button1.ForeColor = Color.Black
- Me.PictureBox1.Controls.Add(Me.Button1)
- End Sub
- Private m_text As String ‘設(shè)置按鈕標(biāo)題
- Private a As Integer
- 'Private m_image As Image
_ - Public Property image() As image
- Get
- Return Me.PictureBox1.Image
- End Get
- Set(ByVal Value As image)
- Me.PictureBox1.Image = Value
- Invalidate()
- End Set
- End Property
- Shadows Property forecolor() As Color
- Get
- Return Me.Button1.ForeColor
- End Get
- Set(ByVal Value As Color)
- Me.Button1.ForeColor = Value
- Invalidate()
- End Set
- End Property
- Shadows Sub ResetForeColor()
- Me.Button1.ForeColor = SystemColors.ControlText
- End Sub
VB.NET制作圖片按鈕的單擊事件
- Event BtnClick(ByVal sender As Object, ByVal e As System.EventArgs)
- Private Sub Button1_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles Button1.Click- RaiseEvent BtnClick(Me, e)
- End Sub
控件改變大小時(shí),需重繪控件,以使子控件排位美觀
- Private Sub FileTextBox_Resize(ByVal sender As Object,
ByVal e As System.EventArgs) Handles MyBase.Resize- RedrawControls()
- End Sub
子控件會(huì)自動(dòng)繼續(xù)容器的Font屬性,所以改變?nèi)萜鞯腇ont屬性時(shí)也要重繪控件
- Protected Overrides Sub OnFontChanged(ByVal e As System.EventArgs)
- '讓基控件更新文本框
- MyBase.OnFontChanged(e)
- '重繪控件
- RedrawControls()
- End Sub
- '重繪控件
- Private Sub RedrawControls()
- '控件寬度
- Dim width As Integer = Me.ClientRectangle.Width '獲得工作區(qū)寬
以VB.NET制作圖片按鈕的高度來(lái)確定控件高度
- Dim btnSide As Integer = Button1.Height
- Dim btnwidth As Integer = Button1.Width
- If Me.ClientRectangle.Height <> btnSide Then
設(shè)置控件工作區(qū)的大小
- 'Me.SetClientSizeCore(btnwidth, btnSide)
- Me.SetClientSizeCore(width, btnSide)
- '這里使用工作區(qū)的寬是因?yàn)椋喊粹o和picturebox可以調(diào)整寬度
- '上面的語(yǔ)句激發(fā)了嵌套的Resize事件,因此需要立即退出,
如果不退出,就會(huì)反復(fù)調(diào)用進(jìn)入死循環(huán)- Exit Sub
- End If
調(diào)整子控件的大小
- 'Txt.SetBounds(0, 0, width, btnSide)
- 'Btn.SetBounds(width - 19, 2, 17, btnSide - 4)
- Me.PictureBox1.SetBounds(0, 0, width, btnSide)
- Me.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
- Me.Button1.SetBounds(0, 0, width, btnSide)
- End Sub
- End Class
VB.NET制作圖片按鈕的相關(guān)實(shí)現(xiàn)方法就為大家介紹到這里。
文章題目:VB.NET制作圖片按鈕實(shí)現(xiàn)步驟一一講解
文章地址:http://m.fisionsoft.com.cn/article/djpschj.html


咨詢
建站咨詢
