在vb6中我在commandbutton上加载图片,但图片太小,如何让其自动匹配
展开全部
如果要做自定义的按钮的话在VB6里面还是不要用command button,不如用image 控件,它也有commandbutton的所有事件。2005或以上版本里可以做MFC解决。总之VB6里面的COMMANDBUTTON不能自动缩放大小只能和窗体一样装个图片进去
image控件:stretch属性,自动拉伸图片适应控件大小。
image控件:stretch属性,自动拉伸图片适应控件大小。
追问
在运行时,怎么才能让image控件也有command button的那种按键感
追答
有两种办法
1如果你不怕程序启动慢和体积大,就做三个大小一样的image 我们假设从上到下依次叫img_a img_b img _c(右击控件可以改变它们的上下顺序-Zorder),然后你先做好三张图片,依次是原始按钮,鼠标移上去时候的,按下键的,(就是像XP以上系统里的那种效果),然后
Private Sub img_b_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
img_a.Visible = True
【按钮事件处理】
End Sub
Private Sub img_a_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
img_a.Visible = False
End Sub
Private Sub img_b_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
img_b.Visible = False
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
img_a.Visible = True '恢复原状
End Sub
这个是偷懒的办法
2.如果要做像样点,就先画一个image叫它imgbtn好了,假设程序目录下(自己决定)已经有了三个名为img_n.jpg,img_a.jpg img_d.jpg(分别是默认状态,鼠标移至上方状态,鼠标按下状态的图片)然后
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
imgbtn.picture=loadpicture(app.path+"/img_n.jpg") '恢复原状
End Sub
Private Sub imgbtn_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
imgbtn.picture=loadpicture(app.path+"/img_a.jpg")
【按钮事件处理】
End Sub
Private Sub imgbtn_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
imgbtn.picture=loadpicture(app.path+"/img_a.jpg")
End Sub
Private Sub imgbtn_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
imgbtn.picture=loadpicture(app.path+"/img_d.jpg")
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询