我的程序運行時﹐用戶如果覺得某個控件(如命令按鈕﹑標僉)的名字不適合﹐他就可以右鍵單擊這個控件﹐然后彈出對話框進行修改。
    問題的關鍵是﹕這個右鍵單擊事件能發生在所有的控件上﹐。。怎樣做呢﹖用timer控件監聽事件會不會太消耗系統資源了﹖我這樣做的目的﹐是想實現程序的多語言版﹐不知可行不可行

解决方案 »

  1.   

    数据库可以这样设计:
    LANG(语言),FRMNAME(窗体名),CTRLNAME(控件名),TEXT(显示标题)
    侦测对方的语言类别.然后加载即可.
      

  2.   

    用数据库比用资源文件要简单方便得多.组织好数据库后,只要十几条语句就搞定了
    ///////
    我看過聽說全球買得最好公司做的erp,就是那樣的方法。我的程序運行時﹐用戶如果覺得某個控件(如命令按鈕﹑標僉)的名字不適合﹐他就可以右鍵單擊這個控件﹐然后彈出對話框進行修改。
    //////////
    不就是和右鍵菜單一個原理嗎?
      

  3.   

    Load一个新的,就随便你怎么定义了!
      

  4.   

    //////////////////////
    数据库可以这样设计:
    LANG(语言),FRMNAME(窗体名),CTRLNAME(控件名),TEXT(显示标题)
    侦测对方的语言类别.然后加载即可.
    /////////////////////////////////
    我也想過這樣做呀﹐這個軟件不是我一個人做的﹐還有窗體﹐控件都會在軟件開發過程中修改。
    我這樣做的目的是想讓用戶自行修改軟件的某些標題﹐標題內容保存在本地文本文件。這樣我就免去了因為修改控件的caption而修改﹑重新編譯軟件。//////////
    不就是和右鍵菜單一個原理嗎?
    ///////////////////////
    對﹐也就是做一個修改控件的caption的右鍵菜單。
      

  5.   

    倒...caption属性直接附值就行了.那不是控件名称!
      

  6.   

    對﹐也就是做一個修改控件的caption的右鍵菜單。
    ///在這個菜單的事件中間直接寫command1.caption="aaa"不就行了嗎?你不是菜單不會做吧...
      

  7.   

    對﹐也就是做一個修改控件的caption的右鍵菜單。
    ///在這個菜單的事件中間直接寫command1.caption="aaa"不就行了嗎?你不是菜單不會做吧...
    有几千個command,label等等 ﹐你給我一個個寫呀﹐
      

  8.   


    dim ctl as control
    for each ctl in form1 '循环窗体里的所有控件
        ctl.caption = "用循环"
    next
      

  9.   

    '修改commandButton的caption
    Private Sub mnuEditCommandCaption_Click()
        Dim ctr As Control
        For Each ctr In Me.Controls
            If TypeOf ctr Is CommandButton Then
                If ctr.Index = 1 Then 'index 可以用inputbox 从用户那得到
                    ctr.Caption = "aa"  'caption也可以用inputbox 从用户那得到
                End If
            End If
        Next
    End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Me.PopupMenu a  '做一个名为mnuTest 的菜单
    End Sub
      

  10.   

    commandbutton用的是控件数组,最好用动态方式(load 函数)加载。
      

  11.   

    Me.PopupMenu a  '做一个名为mnuTest 的菜单
     这一行写错了 应为: Me.PopupMenu mnuTest '做一个名为mnuTest 的菜单
      

  12.   

    有几千個command,label等等 ﹐你給我一個個寫呀﹐
    /////
    把窗體上所有控件進行循環判斷呀。
    嘿嘿,你和偶最考試做程序一樣,那時候也特不知道這事情。
      

  13.   

    對了,如果用循環,某寫疊加的控件會出現問題,比如shape上面疊label。所以要對shape的消息進行攔截
      

  14.   

    sysmaster(为什么我还不懂)
    你好﹗
            If TypeOf ctr Is CommandButton Then
                If ctr.Index = 1 Then 'index 可以用inputbox 从用户那得到
                    ctr.Caption = "aa"  'caption也可以用inputbox 从用户那得到
                End If
            End Ifindex 不可能從用戶那里得到呀﹖﹗用戶哪里知道某個CommandButton的index呢﹖
      

  15.   


    '最后一次回答这个问题.希望你试一下效果.'放一堆COMMANDBUTTON(但不能是控件数组),一个CHECKBOX,一个时钟控件.一个TEXTBOXOption ExplicitDim WithEvents Ev_CommandButton As VB.CommandButtonPrivate Sub Check1_Click()
            Text1.Visible = False
    End SubPrivate Sub Form_Load()
            Check1.Caption = "修改"
            Text1.Visible = False
            Timer1.Interval = 50
    End SubPrivate Sub Text1_Change()
            If Not (Ev_CommandButton Is Nothing) And Text1.Visible Then
               Ev_CommandButton.Caption = Text1.Text
            End If
    End SubPrivate Sub Timer1_Timer()
            If UCase$(TypeName(Me.ActiveControl)) = UCase$("COMMANDBUTTON") Then
               Set Ev_CommandButton = Me.ActiveControl
               If Check1.Value = 1 Then
                  Text1.Move Ev_CommandButton.Left, Ev_CommandButton.Top, Ev_CommandButton.Width, Ev_CommandButton.Height
                  Text1.Text = Ev_CommandButton.Caption
                  Text1.Visible = True
                  Text1.ZOrder 0
                  Text1.SetFocus
               End If
            End If
    End Sub
      

  16.   

    我的代码确实有一个很大的问题,就是运行效率不高。
    不过如果你采用的话,可以自己做个例示于“查找与替换”的对话框,主用户输入现在的caption (原来所有的caption不能相同)用它来找index 找到后改变就行了
      

  17.   

    Private Sub cmdEditCaption_Click()
        oldCaption = InputBox("请输入旧的控件名:")
        For Each ctr In Me.Controls
            If TypeOf ctr Is CommandButton Then
                If ctr.Caption = oldCaption Then
                    ctr.Caption = InputBox("请输入新的控件名:")
                End If
            End If
        Next
    End Sub
      

  18.   

    Private Sub cmdEditCaption_Click()
        oldCaption = InputBox("请输入旧的控件名:")
        For Each ctr In Me.Controls
            If TypeOf ctr Is CommandButton Then
                If ctr.Caption = oldCaption Then
                    ctr.Caption = InputBox("请输入新的控件名:")
                    MsgBox "控件名称修改成功"
                    ctr.SetFocus
                    Exit Sub '每次只修改一个控件名,改好后就退出
                End If
            End If
        Next
        MsgBox "你输入的名称不正确" '如果没找到,返回给用户一个信息
    End Sub
      

  19.   

    謝謝
     sysmaster(为什么我还不懂) 
     MSTOP(陈建华(东莞立晨企资)) 
    我按照你的方法做了﹐但對label不起作用。是不是label不能獲得焦點的原因﹖Option ExplicitDim WithEvents Ev_CommandButton As VB.CommandButton
    Dim WithEvents Ev_Label As VB.Label
    Dim WithEvents Ev_CheckBox As VB.CheckBox
    Private Sub Check1_Click()
            Text1.Visible = False
    End SubPrivate Sub Form_Load()
            Check1.Caption = "修改"
            Text1.Visible = False
            Timer1.Interval = 50
    End SubPrivate Sub Text1_Change()
            If TypeName(Me.ActiveControl) = "COMMANDBUTTON" And _
                (Not (Ev_CommandButton Is Nothing)) And Text1.Visible Then
               Ev_CommandButton.Caption = Text1.Text
            End If
            If Not (Ev_Label Is Nothing) And Text1.Visible Then
                Ev_Label.Caption = Text1.Text
            End If
            If Not (Ev_CheckBox Is Nothing) And Text1.Visible Then
                Ev_CheckBox.Caption = Text1.Text
            End If
    End SubPrivate Sub Timer1_Timer()
            If UCase$(TypeName(Me.ActiveControl)) = UCase$("COMMANDBUTTON") Then
               Set Ev_CommandButton = Me.ActiveControl
               If Check1.Value = 1 Then
                  Text1.Move Ev_CommandButton.Left, Ev_CommandButton.Top, Ev_CommandButton.Width, Ev_CommandButton.Height
                  Text1.Text = Ev_CommandButton.Caption
                  Text1.Visible = True
                  Text1.ZOrder 0
                  Text1.SetFocus
               End If
            End If
            If UCase$(TypeName(Me.ActiveControl)) = UCase$("label") Then
                Set Ev_Label = Me.ActiveControl
                If Check1.Value = 1 Then
                    Text1.Move Ev_Label.Left, Ev_Label.Top, Ev_Label.Width, Ev_Label.Height
                    Text1.Text = Ev_Label.Caption
                    Text1.Visible = True
                    Text1.ZOrder 0
                    Text1.SetFocus
                End If
            End If
            If UCase$(TypeName(Me.ActiveControl)) = UCase$("checkbox") And Me.ActiveControl <> Check1 Then
                Set Ev_CheckBox = Me.ActiveControl
                If Check1.Value = 1 Then
                    Text1.Move Ev_CheckBox.Left, Ev_CheckBox.Top, Ev_CheckBox.Width, Ev_CheckBox.Height
                    Text1.Text = Ev_CheckBox.Caption
                    Text1.Visible = True
                    Text1.ZOrder 0
                    Text1.SetFocus
                End If
            End If
            
    End Sub
      

  20.   

    吓我一跳,我还以为改控件的name属性呢?原来是caption属性啊
    1:可以用资源文件,然后用变量替换
    2:可以在数据库中适当加几列,分别表示各种语言版本的caption
    然后根据你的选择选择数据库中的内容重新给控件赋值即可
      

  21.   

    我按照你的方法做了﹐但對label不起作用。是不是label不能獲得焦點的原因﹖
    是的,LABEL不能获得焦点。
      

  22.   

    這么說﹐就不能用你那種方法修改label的caption了﹖