对于在VB.NET如何制作图片按钮效果讲解
2012-07-13 08:50
471 查看
VB.NET是目前应用比较广泛的编程语言。它在文件处理,移动设备操作,图形界面的处理方面都能够体现强大的作用。那么今天我们就一起学习一个其中的应用技巧,VB.NET制作图片按钮的实际操作方法。
VB.NET制作图片按钮思路:很简单,就是在一个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
注意:以下VB.NET制作图片按钮的过程是 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.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
控件改变大小时,需重绘控件,以使子控件排位美观
Private Sub FileTextBox_Resize(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Resize
RedrawControls()
End Sub
子控件会自动继续容器的Font属性,所以改变容器的Font属性时也要重绘控件
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 '获得工作区宽
以VB.NET制作图片按钮的高度来确定控件高度
Dim btnSide As Integer = Button1.Height
Dim btnwidth As Integer = Button1.Width
If Me.ClientRectangle.Height <> btnSide Then
设置控件工作区的大小
'Me.SetClientSizeCore(btnwidth, btnSide)
Me.SetClientSizeCore(width, btnSide)
'这里使用工作区的宽是因为:按钮和picturebox可以调整宽度
'上面的语句激发了嵌套的Resize事件,因此需要立即退出,如果不退出,就会反复调用进入死循环
Exit Sub
End If
调整子控件的大小
'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制作图片按钮的相关实现方法就为大家介绍到这里。B.NET制作图片按钮的相关实现方法就为大家介绍到这里。
VB.NET制作图片按钮思路:很简单,就是在一个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
注意:以下VB.NET制作图片按钮的过程是 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.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
控件改变大小时,需重绘控件,以使子控件排位美观
Private Sub FileTextBox_Resize(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Resize
RedrawControls()
End Sub
子控件会自动继续容器的Font属性,所以改变容器的Font属性时也要重绘控件
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 '获得工作区宽
以VB.NET制作图片按钮的高度来确定控件高度
Dim btnSide As Integer = Button1.Height
Dim btnwidth As Integer = Button1.Width
If Me.ClientRectangle.Height <> btnSide Then
设置控件工作区的大小
'Me.SetClientSizeCore(btnwidth, btnSide)
Me.SetClientSizeCore(width, btnSide)
'这里使用工作区的宽是因为:按钮和picturebox可以调整宽度
'上面的语句激发了嵌套的Resize事件,因此需要立即退出,如果不退出,就会反复调用进入死循环
Exit Sub
End If
调整子控件的大小
'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制作图片按钮的相关实现方法就为大家介绍到这里。B.NET制作图片按钮的相关实现方法就为大家介绍到这里。
相关文章推荐
- VB.NET中制作图片按钮
- [VB.NET]请问如何在picturebox中实现幻灯片查看图片效果
- C#/VB.NET 操作Word批注(二)——如何插入图片、读取、回复Word批注内容
- PS如何使用制作图片投影效果
- [VB.NET]如何重载控件中的按钮事件?
- 二进制图片信息存入数据库并用gridview显示图片(添加鼠标移到图片上显示大图效果)后台语言vb.net
- [vb.net]使用GDI+绘图达到图片随鼠标缩放与移动的效果
- [VB.NET]如何通过FileListBox在PictureBox显示图片!!!!
- 教你如何利用灰度图透明效果制作隐藏图片.Part2
- VB.net基础:如何获得并显示网上图片
- VB用户控件制作讲解与实例-----用户控件属性或函数的描述信息如何写入程序
- 一个VB.NET写的简单图片缩放处理组件源代码,支持添加半透明效果小图标
- java如何制作图片一样形状的按钮
- asp.net中按钮在鼠标进入与离开时,显示不同的图片效果
- VB.NET里如何在textbox里按回车后就触发command1按钮
- WPF 如何制作图片按钮(imageButton)
- VB.net基础:如何获得并显示网上图片
- js如何制作放大效果的图片
- 使用QtQuick如何制作带有冷却效果的按钮
- 安卓开发 欢迎画面制作 与 按钮如何使用讲解