作者jakevin (真。假凯文)
看板Visual_Basic
标题[.NET] 动态按钮的制作
时间Sat Feb 19 17:50:32 2011
请输入专案类型(网站专案或者应用程式专案):应用程式
本来想说直接picturebox来放
但好像没有跟VB6一样 Picturebox1.Picture = LoadPicture("......")
下去写
改用书上教的 但是图片都不会显示也不会更动 好像是路径问题
图片资料夹放置在 WindowsApplication1 之下
以下是这段功能的程式码
Dim path As String = Application.StartupPath & "\..\Image\"
Dim PlayImage As Boolean
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PictureBox1.Click
'打开报名系统
Dim sign_up1 As New sign_up
sign_up.Show()
End Sub
Sub setICON()
'报名系统
PictureBox1.Tag = New String() {"011.gif", "012.gif", "013.gif"}
End Sub
Sub ShowICON(ByVal sender As Object, ByVal index As Integer)
Dim ctl As PictureBox
ctl = CType(sender, PictureBox)
If (ctl Is PictureBox1) AndAlso index = 0 AndAlso PlayImage Then
'让play 按钮为Down的状态
index = 2
End If
Dim strFile As String = path & ctl.Tag(index)
If System.IO.File.Exists(strFile) Then
ctl.Image = Image.FromFile(strFile)
End If
End Sub
Private Sub PictureBox1_MouseEnter(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles PictureBox1.MouseEnter
ShowICON(sender, 1)
End Sub
Private Sub PictureBox1_MouseLeave(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles PictureBox1.MouseLeave
ShowICON(sender, 0)
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
ShowICON(sender, 2)
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
ShowICON(sender, 1)
End Sub
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.124.75.85
1F:推 chinoyan:为什麽不用button做呢,该有的事件都有啊 02/20 08:57
2F:→ jakevin:因为按钮外型是特殊造型,用button事件 会有框线 02/20 14:46
3F:推 horngsh:既然知道是路径问题, 将图改放到和主程式同一LEVEL的image 03/02 00:07
4F:→ horngsh:资料夹中试试,如path=Application.StartupPath & "image\" 03/02 00:09