VB.NET in the production method of image button

Idea: simple, is in a picturebox control to place a button control, and then added into the picturebox on the button (to ensure that first drag the picturebox, after the drag button), set this button's background color (this time is relative to the picturebox ) is transparent.Imports System.ComponentModelPublic Class picturebuttonInherits System.Windows.Forms.UserControl# Region "Windows Form Designer generated code"'UserControl overrides dispose to clean up the component list.Protected Overloads Overrides Sub Dispose (ByVal disposing As Boolean)If disposing ThenIf Not (components Is Nothing) Thencomponents.Dispose ()End IfEnd IfMyBase.Dispose (disposing)End Sub'Windows Form Designer requiredPrivate components As System.ComponentModel.IContainer'Note: The following procedure is Windows Forms Designer required'You can use the Windows Form Designer to modify this process.'Do not modify it using the code editor.Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBoxFriend WithEvents Button1 As System.Windows.Forms.ButtonPrivate 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 = 0Me.PictureBox1.TabStop = False''Button1'Me.Button1.Name = "Button1"Me.Button1.TabIndex = 1Me.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 RegionPublic Sub New ()MyBase.New ()'This call is Windows Forms Designer required.InitializeComponent ()'In the InitializeComponent () call to add any initialization after theMe.Button1.Width = 100 'Set the initial size of the buttonMe.Button1.Height = 23Me.Button1.BackColor = Color.Transparent 'background color transparentMe.Button1.ForeColor = Color.BlackMe.PictureBox1.Controls.Add (Me.Button1)End SubPrivate m_text As String 'set the button titlePrivate a As Integer'Private m_image As Image_Public Property image () As imageGetReturn Me.PictureBox1.ImageEnd GetSet (ByVal Value As image)Me.PictureBox1.Image = ValueInvalidate ()End SetEnd PropertyShadows Property forecolor () As ColorGetReturn Me.Button1.ForeColorEnd GetSet (ByVal Value As Color)Me.Button1.ForeColor = ValueInvalidate ()End SetEnd PropertyShadows Sub ResetForeColor ()Me.Button1.ForeColor = SystemColors.ControlTextEnd Sub'////'Button click eventEvent 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'////'Control to change the size, need to redraw the control, so beautiful qualifying child controlsPrivate Sub FileTextBox_Resize (ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.ResizeRedrawControls ()End Sub'Child controls will automatically continue the Font property of the container, so to change the Font property of the container must redraw controlProtected Overrides Sub OnFontChanged (ByVal e As System.EventArgs)'To update the text box-based controlMyBase.OnFontChanged (e)'Redraw controlRedrawControls ()End Sub'Redraw controlPrivate Sub RedrawControls ()'Control widthDim width As Integer = Me.ClientRectangle.Width 'wide access to work area'To the button's height to determine the height of the controlDim btnSide As Integer = Button1.HeightDim btnwidth As Integer = Button1.WidthIf Me.ClientRectangle.Height btnSide Then'Set the size of the control work area'Me.SetClientSizeCore (btnwidth, btnSide)Me.SetClientSizeCore (width, btnSide) 'wide work area is used here because of: buttons to adjust the width and the picturebox'The above statement is inspired nested Resize event, requiring immediate exit, if you do not quit, they will repeatedly call into the dead cycleExit SubEnd If'Adjust the size of child controls'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.StretchImageMe.Button1.SetBounds (0, 0, width, btnSide)End SubEnd Class

赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《VB.NET in the production method of image button》
文章链接:https://www.skykkk.com/archives3255.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

相关推荐

  • 暂无文章