回复 第10楼 Joforn 的帖子
是这样的:"例如某酒店有20间房间,有10间已经有人入住,还剩下10间。我需要添加10个按钮来表示还有10间可以入住,并且按钮的caption是从数据库里面读取的房间号,如果点击某个按钮,则表示该按钮caption所示房间号的房间有人预定或入住,然后隐藏或清除该按钮。" 这样能实现吗? 也不知道我说没说清楚。
是这样的:"例如某酒店有20间房间,有10间已经有人入住,还剩下10间。我需要添加10个按钮来表示还有10间可以入住,并且按钮的caption是从数据库里面读取的房间号,如果点击某个按钮,则表示该按钮caption所示房间号的 ...
将下面代码框中的文本粘贴至一个新建文本,更名Form1.FRM双击打开。
'************************************************************************************************
程序代码:
VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 3090 ClientLeft = 60 ClientTop = 450 ClientWidth = 4680 LinkTopic = "Form1" ScaleHeight = 3090 ScaleWidth = 4680 StartUpPosition = 3 '窗口缺省 Begin CMD1 Caption = "CMD1" Height = 420 Index = 0 Left = 1485 TabIndex = 0 Top = 1125 Width = 1005 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub CMD1_Click(Index As Integer) Dim I As Long, K As Long, L As Long If Index Then CMD1(Index).Visible = False For I = 1 To Index If CMD1(I).Visible = False Then K = K + 1 Next I Do While I <= CMD1.UBound If CMD1(I).Visible Then CMD1(I).Top = (I - K + 1) * 50 + (I - K) * CMD1(0).Height Else K = K + 1 End If I = I + 1 Loop ElseIf CMD1.UBound Then L = Val(InputBox("请输入要退房的房号:", "南宫飘雪")) L = L - 100 If L < 1 Or L > CMD1.UBound Then MsgBox "错误:输入的房号有误!", vbCritical, "南宫飘雪" ElseIf CMD1(L).Visible Then MsgBox "错误:此房暂时还没有人入住!", vbCritical, "南宫飘雪" Else CMD1(L).Visible = True For I = L + 1 To CMD1.UBound CMD1(I).Top = CMD1(I).Top + 50 + CMD1(0).Height Next I End If End If End Sub Private Sub Form_Click() Dim I As Long, K As Long, L As Long On Error Resume Next K = Val(InputBox("请输入房号数:", "南宫飘雪")) If K < 0 Then MsgBox "错误:输入有误!", vbCritical, "南宫飘雪" Exit Sub ElseIf K > 99 Then K = 99 End If If K < CMD1.UBound Then For I = CMD1.UBound To K + 1 Step -1 Unload CMD1(I) Next I End If For I = 1 To CMD1.UBound CMD1(I).Caption = "1" & Format(I, "00") CMD1(I).Visible = True CMD1(I).Top = (I + 1) * 50 + (I) * CMD1(0).Height Next I Do While I <= K Load CMD1(I) CMD1(I).Left = 150 CMD1(I).Top = (I + 1) * 50 + (I) * CMD1(0).Height CMD1(I).Width = CMD1(0).Width CMD1(I).Height = CMD1(I).Height CMD1(I).Caption = "1" & Format(I, "00") CMD1(I).Visible = True I = I + 1 Loop End Sub Private Sub Form_Load() CMD1(0).Visible = True CMD1(0).Top = 50 CMD1(0).Left = 150 CMD1(0).Caption = "退房" End Sub
[[it] 本帖最后由 Joforn 于 2008-12-4 21:14 编辑 [/it]]