VB.NET中怎么制作一個(gè)圖片按鈕,相信很多沒(méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。
成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供渾南企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站設(shè)計(jì)、做網(wǎng)站、H5場(chǎng)景定制、小程序制作等業(yè)務(wù)。10年已為渾南眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進(jìn)行中。
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 重寫(xiě) 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制作圖片按鈕的過(guò)程是 Windows 窗體設(shè)計(jì)器所必需的
可以使用 Windows 窗體設(shè)計(jì)器修改此過(guò)程。
不要使用代碼編輯器修改它。
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()>
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 <Description("picturebox圖片。")> _ 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.ClickRaiseEvent BtnClick(Me, e)
End Sub
控件改變大小時(shí),需重繪控件,以使子控件排位美觀
Private Sub FileTextBox_Resize(ByVal sender As Object,
ByVal e As System.EventArgs) Handles MyBase.ResizeRedrawControls()
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
看完上述內(nèi)容,你們掌握VB.NET中怎么制作一個(gè)圖片按鈕的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
網(wǎng)頁(yè)名稱:VB.NET中怎么制作一個(gè)圖片按鈕
文章來(lái)源:http://www.chinadenli.net/article32/joippc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、網(wǎng)站設(shè)計(jì)公司、外貿(mào)建站、網(wǎng)站營(yíng)銷(xiāo)、外貿(mào)網(wǎng)站建設(shè)、域名注冊(cè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)