| 网站首页 | 业界新闻 | 群组 | 人才 | 技术文章 | 下载频道 | 博客 | 代码贴 | 编程论坛
共有 201 人关注过本帖
标题:VB Check 控制按钮的激活状态
只看楼主 收藏
opelwang
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2009-7-2
结帖率:80%
  已结贴   问题点数:20  回复次数:9   
VB Check 控制按钮的激活状态

窗体启动时:
按钮1、按钮2、按钮3,处于激活状态,
按钮4、按钮5、处于未激活状态。

当点击Check1按钮时(True)时,
按钮1、按钮2、按钮3,处于未激活状态,
按钮4、按钮5、处于激活状态。

当点击Check1按钮时(False)时,
按钮1、按钮2、按钮3,处于激活状态,
按钮4、按钮5、处于未激活状态。

以下是程序代码,不知道为什么,就是实现不了,请指教,谢谢!
程序代码:
Private Sub Check1_KeyPress(KeyAscii As Integer)
    With Me
        .Command1.Enabled = False
        .Command2.Enabled = False
        .Command3.Enabled = False

        .Command4.Enabled = True
        .Command5.Enabled = True
    End With
End Sub

Private Sub Command1_Click()
    MsgBox "按钮1", 64 + 0, "提醒"
End Sub

Private Sub Command2_Click()
    MsgBox "按钮2", 64 + 0, "提醒"
End Sub

Private Sub Command3_Click()
    MsgBox "按钮3", 64 + 0, "提醒"
End Sub

Private Sub Command4_Click()
    MsgBox "按钮4", 64 + 0, "提醒"
End Sub

Private Sub Command5_Click()
    MsgBox "按钮5", 64 + 0, "提醒"
End Sub

Private Sub Command6_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    Me.Command4.Enabled = False
    Me.Command5.Enabled = False
End Sub
2017-07-16 21:39
opelwang
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2009-7-2
  得分:0 

上传附件,谢谢。

附件: 您没有浏览附件的权限,请 登录注册
2017-07-16 21:39
ZHRXJR
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:42
帖 子:407
专家分:2315
注 册:2016-5-10
  得分:0 
程序代码:
Private Sub Check1_Click()
    Command1.Enabled = False
    Command2.Enabled = False
    Command3.Enabled = False
    Command4.Enabled = False
    Command5.Enabled = False
If Check1.Value = 0 Then
    Command4.Enabled = True
    Command5.Enabled = True
ElseIf Check1.Value <> 0 Then
    Command1.Enabled = True
    Command2.Enabled = True
    Command3.Enabled = True
End If
End Sub

Private Sub Command1_Click()
    MsgBox "按钮1", 64 + 0, "提醒"
End Sub

Private Sub Command2_Click()
    MsgBox "按钮2", 64 + 0, "提醒"
End Sub

Private Sub Command3_Click()
    MsgBox "按钮3", 64 + 0, "提醒"
End Sub

Private Sub Command4_Click()
    MsgBox "按钮4", 64 + 0, "提醒"
End Sub

Private Sub Command5_Click()
    MsgBox "按钮5", 64 + 0, "提醒"
End Sub

Private Sub Command6_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    Command1.Enabled = True
    Command2.Enabled = True
    Command3.Enabled = True
    Command4.Enabled = False
    Command5.Enabled = False
End Sub

QQ    2653043392
2017-07-16 23:03
opelwang
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2009-7-2
  得分:0 
以下是引用ZHRXJR在2017-7-16 23:03:32的发言:

Private Sub Check1_Click()
    Command1.Enabled = False
    Command2.Enabled = False
    Command3.Enabled = False
    Command4.Enabled = False
    Command5.Enabled = False
If Check1.Value = 0 Then
    Command4.Enabled = True
    Command5.Enabled = True
ElseIf Check1.Value <> 0 Then
    Command1.Enabled = True
    Command2.Enabled = True
    Command3.Enabled = True
End If
End Sub

Private Sub Command1_Click()
    MsgBox "按钮1", 64 + 0, "提醒"
End Sub

Private Sub Command2_Click()
    MsgBox "按钮2", 64 + 0, "提醒"
End Sub

Private Sub Command3_Click()
    MsgBox "按钮3", 64 + 0, "提醒"
End Sub

Private Sub Command4_Click()
    MsgBox "按钮4", 64 + 0, "提醒"
End Sub

Private Sub Command5_Click()
    MsgBox "按钮5", 64 + 0, "提醒"
End Sub

Private Sub Command6_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    Command1.Enabled = True
    Command2.Enabled = True
    Command3.Enabled = True
    Command4.Enabled = False
    Command5.Enabled = False
End Sub


感谢版主帮忙,测试了下,好像不行。

Check1按第一下,没反应。

再点击就有反应了。



附件: 您没有浏览附件的权限,请 登录注册
2017-07-17 20:30
ZHRXJR
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:42
帖 子:407
专家分:2315
注 册:2016-5-10
  得分:0 
肯定的,你的代码原来启动就设置了
    Me.Command4.Enabled = False
    Me.Command5.Enabled = False
那么
    Command1.Enabled = True
    Command2.Enabled = True
    Command3.Enabled = True
与  Check1.Value = 0 是一致的,因此看起来没有变化,除非将
程序代码:
Private Sub Form_Load()
    Command1.Enabled = False
    Command2.Enabled = False
    Command3.Enabled = False
    Command4.Enabled = False
    Command5.Enabled = False
End Sub

或:
Private Sub Form_Load()
     Check1.Value = 0
End Sub

设置成这样。

[此贴子已经被作者于2017-7-18 11:47编辑过]


QQ    2653043392
2017-07-18 11:39
opelwang
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2009-7-2
  得分:0 
以下是引用ZHRXJR在2017-7-18 11:39:33的发言:

肯定的,你的代码原来启动就设置了
    Me.Command4.Enabled = False
    Me.Command5.Enabled = False
那么
    Command1.Enabled = True
    Command2.Enabled = True
    Command3.Enabled = True
与  Check1.Value = 0 是一致的,因此看起来没有变化,除非将
Private Sub Form_Load()
    Command1.Enabled = False
    Command2.Enabled = False
    Command3.Enabled = False
    Command4.Enabled = False
    Command5.Enabled = False
End Sub
或:
Private Sub Form_Load()
     Check1.Value = 0
End Sub
设置成这样。



还是不行:
我的结果是,在窗体启动时:
    Command1,Command2,Command3 为激活状态
    Command4,Command5 为未激活状态
    Check1为未选中状态。

当点击:Check1为选中状态时,
    Command1,Command2,Command3 为未激活状态
    Command4,Command5 为激活状态

当点击:Check1为非选中状态时,
    Command1,Command2,Command3 为激活状态
    Command4,Command5 为未激活状态

能否上传一个搞好的附件,谢谢。

.
2017-07-18 21:56
wmf2014
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:116
帖 子:1536
专家分:8585
注 册:2014-12-6
  得分:0 
so easy!

程序代码:
Private Sub Check1_Click()
  Command1.Enabled = False
  Command2.Enabled = False
  Command3.Enabled = False
  Command4.Enabled = False
  Command5.Enabled = False
  If Check1.Value Then
    Command4.Enabled = True
    Command5.Enabled = True
  Else
    Command1.Enabled = True
    Command2.Enabled = True
    Command3.Enabled = True
  End If
End Sub

Private Sub Form_Load()
  Check1.Value = 0
  Check1_Click
End Sub

能编个毛线衣吗?
2017-07-19 08:10
ZHRXJR
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:42
帖 子:407
专家分:2315
注 册:2016-5-10
  得分:10 
Private Sub Form_Load()
    Check1.Value = 1
End Sub

哎!上次代码有点错误,应该是 Check1.Value = 1,不是  Check1.Value = 0
已经测试过,没有问题。
你自己也应该动动手,不要亦为靠别人。

QQ    2653043392
2017-07-19 10:26
Jason666
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2017-7-6
  得分:0 
那不就是取反,在check_click 事件中 按钮.enable值取反
程序代码:
Private Sub Check1_Click()
    Command1.Enabled = Not Command1.Enabled
    Command2.Enabled = Not Command2.Enabled
    Command3.Enabled = Not Command3.Enabled
    Command4.Enabled = Not Command4.Enabled
    Command5.Enabled = Not Command5.Enabled
End Sub
2017-07-19 13:43
奔驰obc
Rank: 2
等 级:论坛游民
帖 子:4
专家分:10
注 册:2017-7-19
  得分:10 
已经验证,没问题
Option Explicit
Private Sub Check1_Click()
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
If Check1.Value = 1 Then
Command4.Enabled = True
Command5.Enabled = True
Else
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
End If
End Sub

Private Sub Command1_Click()
MsgBox "按钮1", 64, "提醒"
End Sub

Private Sub Command2_Click()
MsgBox "按钮2", 64, "提醒"
End Sub

Private Sub Command3_Click()
MsgBox "按钮3", 64, "提醒"
End Sub

Private Sub Command4_Click()
MsgBox "按钮4", 64, "提醒"
End Sub

Private Sub Command5_Click()
MsgBox "按钮5", 64, "提醒"
End Sub

Private Sub Command6_Click()
End
End Sub

Private Sub Form_Load()
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = False
Command5.Enabled = False
End Sub
2017-07-19 18:15









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

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