小程序鼠标点击按钮(改变背景颜色字体-active的运用)

小程序鼠标点击按钮(改变背景颜色字体-active的运用),第1张

目标需求:实现下历锋图,给点击的view增加类,每肢嫌晌次只能选择一个。

主要思路:给点击的view增加类,依靠点击的index对state进行赋值。如果相同时,给该view增加类者前。

效果演示:

wxml

wxss

js

在form中添加一个按钮,一个combobox,combo1的style属性调成2,配禅完成后粘扰陆贴如下代码,运培李尘行。移动鼠标到按钮上面看效果,点击列表框换颜色

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If X >15 And X <Command1.Width - 15 And Y >15 And Y <Command1.Height - 15 Then

Form1.Caption = "按钮是" &Combo1.List(Combo1.ListIndex) &"色的"

Command1.BackColor = Combo1.ItemData(Combo1.ListIndex)

Else

Form1.Caption = "没变"

Command1.BackColor = &H8000000F

End If

End Sub

Private Sub Form_Load()

Combo1.AddItem "红"

Combo1.AddItem "绿"

Combo1.AddItem "黄"

Combo1.AddItem "蓝"

Combo1.AddItem "白"

Combo1.ItemData(0) = vbRed

Combo1.ItemData(1) = vbGreen

Combo1.ItemData(2) = vbYellow

Combo1.ItemData(3) = vbBlue

Combo1.ItemData(4) = vbWhite

Combo1.ListIndex = 0

Command1.Left = Form1.Width / 4

Command1.Top = Form1.Height / 4

Command1.Width = Form1.Width / 3

Command1.Height = Form1.Height / 3

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If X <Command1.Left Or X >Command1.Left + Command1.Width Or Y <Command1.Top Or Y >Command1.Top + Command1.Height _

Then Command1.BackColor = &H8000000F: Form1.Caption = "没变"

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12366228.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存