C# to VB.Net Conversion Help

baabaa_nl
baabaa_nl used Ask the Experts™
on
Hi Experts,

On one of my questions I wanted help to make my application mutli-culture, and an expert gave me the following link, Changing Your Application User Interface Culture On The Fly.

I am a VB.Net programmer and have very less knowledge about C#.Net and I was not able to convert the code on the source code to a VB.Net.

All I need is to change the language of my form at run time on a click of a button or by click on the menu strip as done on the application which is included on the above link.

Could you please give me the VB.Net version of that example given on the source code that is provided on the link.

Thanks in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Systems Development / Support Specialist
Commented:

Author

Commented:
Hi Anuradhay,

I will try those links that you have commented.

But to give more info of what I have tried:

On the source code of the application that was in the website, and in the Form's Code, I tried changing it to VB.Net and I have included the code below:

The code that was part of the Form from the sourcode in C#:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using Infralution.Localization;
namespace TestCultureManager
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            UpdateLanguageMenus();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void UpdateLanguageMenus()
        {
            CultureInfo culture = CultureManager.ApplicationUICulture;
            englishToolStripMenuItem.Checked = (culture.TwoLetterISOLanguageName == "en");
            frenchToolStripMenuItem.Checked = (culture.TwoLetterISOLanguageName == "fr");
        }

        private void englishToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CultureManager.ApplicationUICulture = new CultureInfo("en-us");
        }

        private void frenchToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CultureManager.ApplicationUICulture = new CultureInfo("fr-fr");
        }

        private void cultureManager_UICultureChanged(CultureInfo newCulture)
        {
            UpdateLanguageMenus();
        }
    }
}

Open in new window


And this is the code that I tried converting to VB.Net: (I did not get any errors compiling or running it, but it did not work). For the Infralution.Localization to be imported, I added the Infralution.dll file from the project that was included in the sourcecode bin folder

Imports System.Globalization
Imports Infralution.Localization

Public Class Form1

    Private Sub UpdateLanguageMenus()
        Dim culture As CultureInfo = CultureManager.ApplicationUICulture

        englishToolStripMenuItem.Checked = (culture.TwoLetterISOLanguageName = "en")
        frenchToolStripMenuItem.Checked = (culture.TwoLetterISOLanguageName = "fr" 
    End Sub

    Private Sub englishToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles englishToolStripMenuItem.Click
        CultureManager.ApplicationUICulture = New CultureInfo("en-us")
    End Sub

    Private Sub frenchToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles frenchToolStripMenuItem.Click
        CultureManager.ApplicationUICulture = New CultureInfo("fr-fr")
    End Sub

    Private Sub cultureManager_UICultureChanged(ByVal newCulture As CultureInfo)
        UpdateLanguageMenus()
    End Sub

End Class

Open in new window

Author

Commented:
Hi Experts,

I created a new solution and a new project, and to the project I have added the Infralution.Localization.dll into the reference of the project. Also added the control to the visual studio toolbox. After adding to the tool box I added it to the form.

But when I run the application, it gives me an error:


InvalidOperationException was unhandled

An error occurred creating the form. See Exception.InnerException for details.  The error is: Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "TestCulture.Form1.resources" was correctly embedded or linked into assembly "TestCulture" at compile time, or that all the satellite assemblies required are loadable and fully signed.

I really don't know what to do next.

Thanks in advance.
Most Valuable Expert 2012
Top Expert 2014
Commented:
reloads the localizable resources for each open form that has a CultureManager component.

The component works by reloading the UI elements (Text etc) from resources. Now the author did not provide enough information in article on how to configure these so look into the demo application to get an idea.

Author

Commented:
Thank you codeCruiser, i will look into it as you say.

Thanks Experts

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial