Siva chidambaram
Siva chidambaram

Reputation: 5

VB.NET Multilingual MenuStrip

On VB.NET the multilingual resource for MenuStrip is not applied to the drop down down submenu . Take a look at the pic to know more clearly

If any mistakes in the questions , I apologize

Here is my code snippet

For Each item As ToolStripItem In MenuStrip1.Items
    If TypeOf item Is ToolStripDropDownItem Then
        For Each dropDownItem As ToolStripItem In CType(item, ToolStripDropDownItem).DropDownItems
            resources.ApplyResources(dropDownItem, dropDownItem.Name, New CultureInfo(Lang))
        Next
    End If
    If TypeOf item Is ToolStripMenuItem Then
        For Each child As ToolStripItem In CType(item, ToolStripMenuItem).DropDownItems
            resources.ApplyResources(child, child.Name, New CultureInfo(Lang))
        Next
    End If
    resources.ApplyResources(item, item.Name, New CultureInfo(Lang))
Next

The drop down sub menu is not changing

I have also tried this code but it seems nothing to change i.e i have cleared a small error and the output is the same as in the picture


            If TypeOf item Is ToolStripMenuItem Then
                For Each child As ToolStripMenuItem In CType(item, ToolStripMenuItem).DropDownItems
                    For Each dropDownItem As ToolStripItem In CType(item, ToolStripDropDownItem).DropDownItems
                        resources.ApplyResources(child, child.Name, New CultureInfo(Lang))
                    Next
                    resources.ApplyResources(child, child.Name, New CultureInfo(Lang))
                    Next
            End If
            resources.ApplyResources(item, item.Name, New CultureInfo(Lang))
        Next

Upvotes: 0

Views: 110

Answers (1)

Precious Uwhubetine
Precious Uwhubetine

Reputation: 3007

As @HansPassant suggested in the comments, you can use a recursive method to get the job done.

I also suggest you take a look at the article @Jimi posted.

Well, here's how to get it done recursively.

Sub ApplyLanguageChanges(ByRef item As Object)
    'Check for a MenuStrip first'
    If TypeOf item Is MenuStrip Then
        resources.ApplyResources(item Ctype(item, MenuStrip).Name, New CultureInfo(Lang))
        For Each child In Ctype(item, MenuStrip).Items
            ApplyLanguageChanges(child)
        Next
    'Next, check for a ToolStripDropDownItem'
    Else If TypeOf item Is ToolStripDropDownItem
        resources.ApplyResources(item CType(item,  ToolStripDropDownItem).Name, New CultureInfo(Lang))
        For Each child In CType(item,  ToolStripDropDownItem).DropDownItems
            ApplyLanguageChanges(child)
        Next
    'Finally, check for a ToolStripMenuItem'
    Else If TypeOf item Is ToolStripMenuItem
        resources.ApplyResources(item, CType(item, ToolStripMenuItem).Name, New CultureInfo(Lang))
     End If
End Sub

The Method above can be called like this:

ApplyLanguageChanges(MenuStrip1)

Upvotes: 1

Related Questions