vb动态添加二维控件数组
我想把button按钮动态添加成二维数组,按command1 出现a11、a12....a130这30个按钮 然后按command2 出现a21,a22....a230这30个按钮,如何用vb实现?求解。十分感谢。 --------------------编程问答-------------------- 会很卡的,没必要加这么多,想点其他办法 --------------------编程问答-------------------- command1\command2 设计时,设置index属性为0代码中
for j= 1 to 30
load command1(j)
command1(j).visible=true
command1(j).move ....'移动到一个合适位置
command2(j).visible=true
command2(j).move ....'移动到一个合适位置
next
--------------------编程问答-------------------- #define y1 CCU_ALARM y2 y5_ERR y3 CCU_ERR_MPI y4 CCU_485 y5 SDR_TYPE y6
//CCU_typedef.h #ifndef __CCU_TYPEDEF_H__#define __CCU_TYPEDEF_H__
.. <stdio.h>.. <string.h>.. <stdlib.h>.. <malloc.h>.. <ctype.h>.. <errno.h>
.. <fcntl.h>.. <unistd.h>.. <termios.h>.. <stdlib.h>.. <pthread.h>.. <unistd.h>
.. <signal.h>.. <dirent.h>.. <sys/sem.h>.. <sys/ipc.h>.. <sys/msg.h>.. <sys/ioctl.h>
.. <sys/mman.h>.. <sys/time.h>.. <sys/types.h>.. <sys/stat.h>.. <arpa/inet.h>.. <stdarg.h>
y1 CCU_FRead fread y1 CCU_FWrite fwrite y1 CCU_FClose fclose
y1 CCU_FTell ftell y1 CCU_FSeek fseek y1 CCU_FGets fgets
y1 CCU_FOpen fopen y1 CCU_POpen popen y1 CCU_PClose pclose
y1 CCU_Access access y1 CCU_MemSet memset y1 CCU_MemCpy memcpy
y1 CCU_MemMove memmove y1 CCU_MemCmp memcmp y1 CCU_StrLen strlen
y1 CCU_StrCmp strcmp y1 CCU_StrnCmp strncmp
y1 CCU_StrCpy(destStr, srcStr) \
strncpy(destStr, srcStr, (INT)strlen(srcStr)+1)\
y1 CCU_StrnCpy strncpy y1 CCU_StrStr strstr y1 CCU_StrChr strchr
y1 CCU_Sprintf(desStr, args...) \
snprintf(desStr, 2048, ##args);\
y1 CCU_Snprintf snprintf y1 CCU_StrCat strcat
y1 CCU_StrnCat strncat y1 CCU_AtoI atoi
y1 CLIPrintf printf y1 CCU_Printf if(g_AllSwitch) printf
y1 CCU_System system y1 CCU_Time time
y1 CCU_GmTime gmtime y1 CCU_MkTime mktime
y1 CCU_MemAlloc(x,y,z) malloc(z) y1 CCU_MemFree(x,y) free(y) --------------------编程问答-------------------- y1 CCU_USleep(x) usleep(x)y1 CCU_Sleep(x) sleep(x)
y1 CCU_UnLink unlinky1 CCU_VAStart va_start
y1 CCU_VAEnd va_endy1 CCU_VFprintf vfprintf
y1 CCU_FPrintf fprintfy1 CCU_SScanf sscanf
y1 CCU_Getpid getpidy1 CCU_Str2UL strtoul
y1 CCU_ScanDir scandiry1 CCU_JoinThread pthread_join
y1 CCU_GetTimeOfDay gettimeofdayy1 CCU_CreateThread pthread_create
y1 CCU_ClearHistory clear_historyy1 CCU_G_StrStrip g_strstrip
y1 CCU_G_StrDup g_strdupy1 CCU_AddHistory add_history
y1 CCU_SigAction sigactiony1 CCU_Signal signal
y1 CCU_Chdir chdiry1 CCU_ReadLine readline
y1 CCU_Exit exity1 CCU_StrCaseCmp strcasecmp
y1 CCU_StrNCaseCmp strncasecmpy1 CCU_StrTok strtok
y1 CCU_CompletionMatches completion_matchesy1 CCU_Select select
y1 CCU_Connect connecty1 CCU_StrError strerror
y1 CCU_Write writey1 CCU_Read read
y1 CCU_GetHostByName gethostbynamey1 CCU_Socket socket
y1 CCU_FFlush fflushy1 CCU_Close close
y1 CCU_AtoL atoly1 CCU_AtoF atof
y1 CCU_PThreadAttrInit pthread_attr_init
y1 CCU_PThreadAttrSetStackSize pthread_attr_setstacksize
y1 CCU_PThreadAttrDestroy pthread_attr_destroy
y1 CCU_PThreadDetach pthread_detachy1 CCU_PThreadSelf pthread_self
y1 CCU_SetSockOpt setsockopty1 CCU_BZero bzero
y1 CCU_HtoNL htonly1 CCU_HtoNS htonsy1 CCU_Bind bindy1 CCU_Listen listen
y1 CCU_Accept accepty1 CCU_FPuts fputsy1 CCU_Rename renamey1 CCU_PutChar putchar
y1 CCU_CFMakeRaw cfmakerawy1 CCU_TCSetAttr tcsetattry1 CCU_TCGetAttr tcgetattr --------------------编程问答-------------------- y1 CCU_FGetC fgetcy1 CCU_SigFillSet sigfillsety1 CCU_SigDelSet sigdelset
y1 CCU_SigProcMask sigprocmasky1 CCU_SigEmptySet sigemptysety1 CCU_SigAddSet sigaddset
y1 CASE(CASEVALUE) case CASEVALUE:y1 CCU_TRUE (1) y1 CCU_FALSE (0)y1 CCU_OK (0)
y1 CCU_ERR (1)y1 CCU_ERROR (-1)y1 IPC_FAIL_CODE (-1) /* IPC错误返回码 */
y1 CCU_ZERO_VALUE (0) /* 初始化值 */
y1 CCU_NULL_BYTE (0xFF) /* 字节宏定义 */ y1 CCU_NULL_WORD (0xFFFF) /* 字宏定义 */
y1 CCU_NULL_LONG (0xFFFFFFFF) /* 长整形宏定义 */
y1 CCU_NULL_DWORD (0xFFFFFFFF) /* 双字宏定义 */y1 CCU_NULL_PTR (NULL) /* 空指针宏定义 */
y1 CCU_5S_TICK (5000) /* 5S tick数 */
y1 CCU_500MS_TICK (500) /* 500ms tick 数 */
y1 CCU_300MS_TICK (300) /* 300ms tick 数 */
y1 CCU_200MS_TICK (200) /* 200ms tick 数 */
y1 CCU_100MS_TICK (100) /* 100ms tick 数 */
y1 CCU_50MS_TICK (50) /* 50 ms tick 数 */
y1 y5_SEND_ADDR_TIME (100) /* 发送地址时间 */
y1 y5_SEND_DATA_TIME (500) /* 发送数据时间 */
y1 y5_QUERY_TIME (500) /* 查询时间 */
/* 定义重复, 需要清理 */
y1 CCU_ACK (0x7F) /* ACK */y1 CCU_NACK (0x70) /* NACK */
y1 NODE_NOMSG_RESP (0x73) /* 无事响应 */
y1 NOTHING_RESPONSE (0x73) /* 无事响应 */y1 DISAFFIRM_RESPONSE (0x70) /* NACK */
y1 AFFIRM_RESPONSE (0x7f) /* ACK */y1 I2C_9555_ERR_RET (0xFFFF0000)
y1 CCU_MAX_ADDRESS (32) /* 从节点最大地址 */ y1 SEND_FIRST_TIME (0) /* 第一次下发 */
y1 MAX_SEND_TIME (3) /* 最大重发次数 */y1 QUERY_PROC (0) /* 轮询命令 */
y1 TRANSMIT_PROC (1) /* 转发命令 */y1 CMD1POS (3) /* 命令字1 */
y1 CMD2POS (4) /* 命令字2 */y1 MAX_INSIDE_CARD_NUM (4) /* 最大子卡数 */ --------------------编程问答-------------------- 其实不必真的“动态”添加。可以通过设置 Visual 属性来掩藏和“添加”。当然,也可以通过改变 Form 的大小来显示更多的控件。
--------------------编程问答-------------------- 虽然不明白为什麽要求这麽写(新增加的60个按键是不会有回应的)^^...
'请在Form上植入Command1与Command2
Private Sub Form_Load()
Command1.Move 0, 0
Command2.Move Command1.Left + Command1.Width, Command1.Top, Command1.Width, Command1.Height
End Sub
Private Sub Command1_Click()
addCommandButton Command1
End Sub
Private Sub Command2_Click()
addCommandButton Command2
End Sub
Private Function addCommandButton(bt As CommandButton)
Dim iBt As CommandButton, i As Byte
For i = 1 To 30 '按键在母键下垂直排列
Set iBt = Controls.Add("VB.CommandButton", bt.Name & i, Form1)
iBt.Move bt.Left, bt.Height * i, bt.Width, bt.Height
iBt.Caption = bt.Caption & i
iBt.Visible = True
Next 'i
End Function --------------------编程问答-------------------- '还是建议改成这样,采用共用的事件吧^^...
'请在Form上植入Command1(0)与Command2(0)
Private Sub Form_Load()
Command1(0).Move 0, 0
Command2(0).Move Command1(0).Left + Command1(0).Width, Command1(0).Top, Command1(0).Width, Command1(0).Height
End Sub
Private Sub Command1_Click(Index As Integer)
Dim i As Byte
If Index = 0 Then
addCommandButton Command1
Else
' 在这写入想执行的程序呗
MsgBox Command1(Index).Caption
End If
End Sub
Private Sub Command2_Click(Index As Integer)
Dim i As Byte
If Index = 0 Then
addCommandButton Command2
Else
' 在这写入想执行的程序...
MsgBox Command2(Index).Caption
End If
End Sub
Private Function addCommandButton(bt As Object)
For i = bt.Count To 30 '按键在母键下垂直排列
Load bt(i)
bt(i).Caption = bt(i).Caption & i
bt(i).Move bt(0).Left, bt(0).Height * i, bt(0).Width, bt(0).Height
bt(i).Visible = True
Next 'i
End Function
补充:VB , 控件