自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

VB.NET制作圖片按鈕實現(xiàn)步驟一一講解

開發(fā) 后端
VB.NET制作圖片按鈕的思路很簡單,只要把編程思路理清,再根據(jù)我們提前設(shè)計好的步驟,一一進(jìn)行,就能很好的實現(xiàn)這一功能。

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

VB.NET制作圖片按鈕思路:很簡單,就是在一個picturebox控件上放置一個button控件,然后將這個button添加進(jìn)picturebox上(確保先拖拽picturebox,后拖拽button),設(shè)置這個button的背景色(這個時候是相對于picturebox)為透明。

  1. Imports System.ComponentModel   
  2. Public Class picturebutton   
  3. Inherits System.Windows.Forms.UserControl   
  4. #Region " Windows 窗體設(shè)計器生成的代碼 "   
  5. 'UserControl 重寫 dispose 以清理組件列表。   
  6. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)   
  7. If disposing Then   
  8. If Not (components Is Nothing) Then   
  9. components.Dispose()   
  10. End If   
  11. End If   
  12. MyBase.Dispose(disposing)   
  13. End Sub   
  14. 'Windows 窗體設(shè)計器所必需的   
  15. Private components As System.ComponentModel.IContainer  

注意:以下VB.NET制作圖片按鈕的過程是 Windows 窗體設(shè)計器所必需的

可以使用 Windows 窗體設(shè)計器修改此過程。

不要使用代碼編輯器修改它。

  1. Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox   
  2. Friend WithEvents Button1 As System.Windows.Forms.Button   
  3. <System.Diagnostics.DebuggerStepThrough()> 
    Private Sub InitializeComponent()   
  4. Me.PictureBox1 = New System.Windows.Forms.PictureBox()   
  5. Me.Button1 = New System.Windows.Forms.Button()   
  6. Me.SuspendLayout()   
  7. 'PictureBox1   
  8. Me.PictureBox1.Name = "PictureBox1"   
  9. Me.PictureBox1.Size = New System.Drawing.Size(136, 40)   
  10. Me.PictureBox1.TabIndex = 0   
  11. Me.PictureBox1.TabStop = False   
  12. 'Button1   
  13. Me.Button1.Name = "Button1"   
  14. Me.Button1.TabIndex = 1   
  15. Me.Button1.Text = "Button1"   
  16. 'picturebutton   
  17. Me.Controls.AddRange(New System.Windows.Forms.Control() 
    {Me.Button1, Me.PictureBox1})   
  18. Me.Name = "picturebutton"   
  19. Me.ResumeLayout(False)   
  20. End Sub   
  21. #End Region   
  22. Public Sub New()   
  23. MyBase.New()  

該調(diào)用是 Windows 窗體設(shè)計器所必需的。

  1. InitializeComponent()   
  2. '在 InitializeComponent() 調(diào)用之后添加任何初始化   
  3. Me.Button1.Width = 100 ‘設(shè)置按鈕的初始大小   
  4. Me.Button1.Height = 23   
  5. Me.Button1.BackColor = Color.Transparent ‘背景色透明   
  6. Me.Button1.ForeColor = Color.Black   
  7. Me.PictureBox1.Controls.Add(Me.Button1)   
  8. End Sub   
  9. Private m_text As String ‘設(shè)置按鈕標(biāo)題   
  10. Private a As Integer   
  11. 'Private m_image As Image   
  12. <Description("picturebox圖片。")> _   
  13. Public Property image() As image   
  14. Get   
  15. Return Me.PictureBox1.Image   
  16. End Get   
  17. Set(ByVal Value As image)   
  18. Me.PictureBox1.Image = Value   
  19. Invalidate()   
  20. End Set   
  21. End Property   
  22. Shadows Property forecolor() As Color   
  23. Get   
  24. Return Me.Button1.ForeColor   
  25. End Get   
  26. Set(ByVal Value As Color)   
  27. Me.Button1.ForeColor = Value   
  28. Invalidate()   
  29. End Set   
  30. End Property   
  31. Shadows Sub ResetForeColor()   
  32. Me.Button1.ForeColor = SystemColors.ControlText   
  33. End Sub  

VB.NET制作圖片按鈕的單擊事件

  1. Event BtnClick(ByVal sender As Object, ByVal e As System.EventArgs)   
  2. Private Sub Button1_Click(ByVal sender As Object, 
    ByVal e As System.EventArgs) Handles Button1.Click   
  3. RaiseEvent BtnClick(Me, e)   
  4. End Sub  

控件改變大小時,需重繪控件,以使子控件排位美觀

  1. Private Sub FileTextBox_Resize(ByVal sender As Object,
     ByVal e As System.EventArgs) Handles MyBase.Resize   
  2. RedrawControls()   
  3. End Sub  

子控件會自動繼續(xù)容器的Font屬性,所以改變?nèi)萜鞯腇ont屬性時也要重繪控件

  1. Protected Overrides Sub OnFontChanged(ByVal e As System.EventArgs)   
  2. '讓基控件更新文本框   
  3. MyBase.OnFontChanged(e)   
  4. '重繪控件   
  5. RedrawControls()   
  6. End Sub   
  7. '重繪控件   
  8. Private Sub RedrawControls()   
  9. '控件寬度   
  10. Dim width As Integer = Me.ClientRectangle.Width '獲得工作區(qū)寬  

以VB.NET制作圖片按鈕的高度來確定控件高度

  1. Dim btnSide As Integer = Button1.Height   
  2. Dim btnwidth As Integer = Button1.Width   
  3. If Me.ClientRectangle.Height <> btnSide Then  

設(shè)置控件工作區(qū)的大小

  1. 'Me.SetClientSizeCore(btnwidth, btnSide)   
  2. Me.SetClientSizeCore(width, btnSide) 
  3. '這里使用工作區(qū)的寬是因為:按鈕和picturebox可以調(diào)整寬度   
  4. '上面的語句激發(fā)了嵌套的Resize事件,因此需要立即退出,
    如果不退出,就會反復(fù)調(diào)用進(jìn)入死循環(huán)   
  5. Exit Sub   
  6. End If  

調(diào)整子控件的大小

  1. 'Txt.SetBounds(0, 0, width, btnSide)   
  2. 'Btn.SetBounds(width - 19, 2, 17, btnSide - 4)   
  3. Me.PictureBox1.SetBounds(0, 0, width, btnSide)   
  4. Me.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage   
  5. Me.Button1.SetBounds(0, 0, width, btnSide)   
  6. End Sub   
  7. End Class  

VB.NET制作圖片按鈕的相關(guān)實現(xiàn)方法就為大家介紹到這里。

【編輯推薦】

  1. VB.NET MyClass使用方法細(xì)講
  2. VB.NET磁盤格式化小心使用
  3. VB.NET刪除文件夾實現(xiàn)方法介紹
  4. VB.NET安裝工程具體應(yīng)用方法解析
  5. VB.NET對象序列劇本概念剖析
責(zé)任編輯:曹凱 來源: wewill.cn
相關(guān)推薦

2010-01-08 18:37:08

VB.NET顯示圖片

2009-11-10 16:20:25

VB.NET全局熱鍵

2010-01-11 16:04:10

VB.NET使用wit

2009-10-20 10:16:24

VB.NET COMB

2009-10-23 13:22:25

VB.NET實現(xiàn)拖動圖

2009-10-23 15:35:42

VB.NET實用教程

2009-10-23 13:10:14

VB.NET List

2009-10-12 13:54:22

VB.NET Data

2009-10-15 11:42:05

VB.Net賦值語句

2009-10-14 09:58:43

VB.NET程序

2009-11-10 15:18:35

VB.NET封面

2009-10-16 09:35:24

VB.NET制作透明窗

2011-05-20 16:56:11

VB.NETGDI

2010-01-22 18:08:18

VB.NET與GDI結(jié)

2009-10-14 17:21:47

VB.NET定制Win

2009-10-13 14:42:30

VB.NET靜態(tài)成員

2010-01-18 18:20:49

VB.NET使用API

2010-01-07 17:51:36

VB.NET實現(xiàn)Sin

2009-10-28 13:24:25

VB.NET文件

2010-01-14 15:44:17

VB.NET數(shù)據(jù)綁定
點贊
收藏

51CTO技術(shù)棧公眾號