Home Image-Pro Automation (Macros, Apps, Reports)

REFERENCES to use CONTROL TYPED VARIABLE . . .

2021-05-13-113528

All --

What REFERENCE or LIBRARY needs to be ADDED or IMPORTED to support the TYPE = CONTROL in the

        Dim cControl As Control

statement within the code below?

Private Sub SetControls()
        Dim cControl As Control
        For Each cControl InMe.Controls
            If (TypeOf cControl Is TextBox) Then
                cControl.Text = "abc"
            End If
        Next cControl
    End Sub

I believe that a couple of other modifications will be necessary also.

Private Sub SetControls2()
        Dim cControl As Control
        For Each cControl In MyControl.Controls
            If (TypeOf cControl Is TextBox) Then
                cControl.Text = "abc"
            End If
        Next cControl
    End Sub

when the FORM for the APP is

    MyControl

I am looking for a way to get a list of the CONTROLS within an APP / FORM and then change the .TEXT ATTRIBUTE for most of the CONTROLS based on a TRANSLATION TABLE for MULTIPLE LANGUAGES.

Thank you for your assistance.

-- Matt

Best Answers

  • Accepted Answer
    Hi Matt, 

    This code works for me:

        Private Sub SetControls2()
           
            For Each cControl As System.Windows.Forms.Control In MyControl.Controls
                If (TypeOf cControl Is System.Windows.Forms.TextBox) Then
                    cControl.Text = "abc"
                End If
            Next cControl
        End Sub

    I'm curious about the way you're localizing your app.  
    I'll check with the Engineering team if there is an easier way to go about it. 
    Andrew

  • Accepted Answer
    Hi Matt,

    As you know, Image-Pro is a fully localizable application, currently it can run in 3 languages: English, Japanese and Chinese.

    The localization involves multiple steps and uses several external tools:
    - the "Localizable" option of the forms and controls is activated: it forces extracting all localizable fields from the forms and user controls to RESX files (for .NET modules)
    - then a special tool is used to create resource DLL from these files
    - another tool is used to extract localizable strings to a database
    - databases for multiple languages are creates and translated accordingly
    - new resource DLLs are created and installed to application sub-folders (en/ja/zh-Hans)

    These localization DLLs are used when Windows has language settings corresponded to these languages.

    These are the steps we use in Image-Pro and they are available for addins created in Visual Studio, but not for the apps that are created in Project Workbench. You can also create addins in Visual Studio.

    If you create apps in Project Workbench, you can use other approaches:
    1. the method I recommended (localizing in Designer view), if you use that approach I would recommend to have App.vb file only for UI and all the processing functions in Module.vb, so you can duplicate only UI file for localized versions and use the same processing functions from Module.vb. 
    2. Use run-time localization, as you wanted initially. In that case you have to create a list of all your controls that require localization (you can go through App.designer.vb to find which controls should be localized), you may try to create a function that finds all controls in your your app starting from the main form and recursively going through the list of children of every control (Controls property) (analyzing App.designer.vb can give you idea how controls are related to each other, start from Me.Controls.Add()). and have corresponded localized text for every control, then you can assign localized strings of required language in some initialization function.
    Yuri

Answers

  • 2021-05-13-133730

    Andrew --

    Thanks you for the code and for the guidance.

    I have an APP / FORM which contains dozens of CONTROLS (TABS, BUTTONS, TEXT BOXES, CHECK BOXES, ETC.).

    The APP / FORM was created in ENGLISH.  I have a TRANSLATION TABLE that has:

    -- CONTROL NAME
    -- ENGLISH TEXT
    -- SPANISH TEXT

    I am working on a way to change the TEXT to SPANISH.

    I can HARD CODE it with

        button10.text = "Hola"

    to replace the

        button10.text = "Hello"

    that is in the DIALOG EDITOR

    I think that would be short sighted as the company wants to do more languages than SPANISH.

    It looks like the loop in our examples will need to be made recursive so that the loop gets the CONTROLS that are within CONTROLS.  I guess I'm going to need some more coffee!

    Thanks again.

    -- Matt

  • edited May 14
    Hi Matt,

    The easiest way to translate an app is to create a copy of the app and translate all visible text in Designer view of Project Workbench. You may also need to adjust size of some controls as translated text length can be longer then the English equivalent. 

    You can also translate text in App.designer.vb file (which you can find in the app's folder), (e.g. replacing Text, Tooltip, Combobox and other English fields by Spanish translations), though you should be careful editing the file to avoid breaking the structure, which could make the app unloadable. Editing in designer view is safer.

    Yuri

  • 2021-05-14-100744

    Yuri --

    Thanks for the guidance on this.

    Maintaining multiple copies of the APP in different languages does not seem prudent. because SPANISH is the first of several languages that this APP will need to be able run in.

    There are approximately 200 VB.NET CONTROLS within the APP.  I believe the NATIVE LANGUAGE (ENGLISH) from the DESIGNER VIEW and the APP.DESIGNER.VB FILE can be superseded at RUN TIME by ROUTINES that change the .TEXT (or appropriate) PROPERTY of those 200 CONTROLS.

    I have this working for the 13 TABCONTROL TABPAGE TEXT PROPERTIES right now.  I am working on smoothing this out and expanding to the other CONTROLS (LABELS, CHECKBOXES, RADIOBUTTONS, GROUPBOXES, and MESSAGE BOXES).

    When I add FEATURES and FUNCTIONS to the CODE, I will only need to do it once and then add the TRANSLATIONS for the CONTROLS to the appropriate ROUTINES.

    My biggest challenge right now is that CONTROLS seem to nest within other CONTROLS so for a ROUTINE to "see" a CONTROL, it seems that the CODE needs to parse through the "FAMILY TREE" for each CONTROL.

    Perhaps you know of an easy way to INVENTORY all CONTROLS within a FORM.  My attempts show the CONTROLS by "LEVEL" or "GENERATION".  FIRST LEVEL / GENERATION CONTROLS being those within the FORM.  Second LEVEL / GENERATION being those within the FIRST LEVEL CONTROLS. ETC ETC ETC.

    Thanks.

    -- Matt

  • 2021-05-14-152941

    Yuri --

    Thanks for the additional guidance.

    The ENGLISH VERSION (V1D) of the APP is up and running.  The APP.VB FILE is approximately 14,000 lines of code so it would be a major effort to move the CODE for the FEATURES to a MODULE.VB FILE.

    I believe the method that you outline as the second option is going to work well for this app.  The CONTROLS in the APP look like they are enumerated early in the APP.DESIGNER.VB FILE.  In the case of this app from LINE 20 to LINE 502 (approximately 250 CONTROLS).  Not all CONTROLS need to be translated so building a TRANSLATION TABLE ROUTINE will not be difficult.

    I should have this up and running by MON or TUE of next week.  Holler if you would like to WEBEX.  I would love your thoughts on ways to improve it.

    Thanks again.

    -- Matt


Sign In or Register to comment.