| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2503 人关注过本帖
标题:怎么做图片按钮???
只看楼主 加入收藏
hemingsheng
Rank: 1
等 级:新手上路
帖 子:164
专家分:0
注 册:2007-5-16
结帖率:100%
收藏
 问题点数:0 回复次数:5 
怎么做图片按钮???
各位大虾请问怎么用做图片按钮??
请各位指教小弟。。
小弟是新手。。。
搜索更多相关主题的帖子: 按钮 
2008-03-12 12:36
qlong0728
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:272
专家分:0
注 册:2007-6-15
收藏
得分:0 
图片按钮:思路:很简单,就是在一个picturebox控件上放置一个button控件,然后将这个button添加进picturebox上(确保先拖拽picturebox,后拖拽button),设置这个button的背景色(这个时候是相对于picturebox)为透明。
Imports
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
'注意:以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents Button1 As System.Windows.Forms.Button
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
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
'////
'按钮的单击事件
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 '获得工作区宽
'以按钮的高度来确定控件高度
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

程序人员写程序,又拿程序换酒钱。 奔驰宝马贵者趣,公交自行程序员。 不见满街漂亮妹,哪个归得程序员。
2008-03-12 12:52
hemingsheng
Rank: 1
等 级:新手上路
帖 子:164
专家分:0
注 册:2007-5-16
收藏
得分:0 
非常感谢!!

设计彼岸程序 编写人生代码
2008-03-13 09:33
hemingsheng
Rank: 1
等 级:新手上路
帖 子:164
专家分:0
注 册:2007-5-16
收藏
得分:0 
回复 2# 的帖子
但是怎么才能做那中变化的图片的按钮?
就是按下去时是一副图片 单击时候又是一副图片
这个怎么做到???
望版主指教小弟。。

设计彼岸程序 编写人生代码
2008-03-13 09:40
tntzwc
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:216
专家分:0
注 册:2007-4-28
收藏
得分:0 
我建议你先看看按钮的事件。
然后再写这个程序。

努力了有可能失败,不努力一定失败!
2008-03-13 09:47
hemingsheng
Rank: 1
等 级:新手上路
帖 子:164
专家分:0
注 册:2007-5-16
收藏
得分:0 
我知道按钮有鼠标滑过点击等事件 可以利用其来变换图片
但是我想要的是在属性窗口下就能直接设置的那种方法
如下图:








" border="0" />
是不是有一个控件还是别的什么方法??
请大虾们教教小弟。。。。。
谢谢。。

[[it] 本帖最后由 hemingsheng 于 2008-3-16 10:49 编辑 [/it]]

设计彼岸程序 编写人生代码
2008-03-16 10:38
快速回复:怎么做图片按钮???
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013011 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved