日期:2012-12-03  浏览次数:20448 次

图片按钮:

思路:很简单,就是在一个picturebox控件上放置一个button控件,然后将这个button添加进picturebox上(确保先拖拽picturebox,后拖拽button),设置这个button的背景色(这个时候是相对于picturebox)为透明。







Imports System.ComponentModel



Public Class picturebutton



Inherits System.Windows.Forms.UserControl







#Region " Windows 窗体设计器生成的代码 "















'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 窗体设计器所必需的



Private components As System.ComponentModel.IContainer







'注意:以下过程是 Windows 窗体设计器所必需的



'可以使用 Windows 窗体设计器修改此过程。



'不要使用代码编辑器修改它。



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()







'该调用是 Windows 窗体设计器所必需的。



InitializeComponent()







'在 InitializeComponent() 调用之后添加任何初始化



Me.Button1.Width = 100 ‘设置按钮的初始大小



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 ‘设置按钮标题



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.Pic