Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Folks,

I have a problem with my application. Long post, but surely a short answer !!
I've done an application in French, and want to make it converted into multi-languages, using the Globalization.

What i've already done :
- Set properties of my form to Localizable = True
- Change the language = English
- Change some of the Controls, labels, ... with the text in English (it created the form1.en.resx)

Under Form1.vb, there are :
- Form1.designer.vb
- A form1.en.resx have been created
- Form1.resx

In the code, i've import :
Imports System.Globalization


In the Public Class Form1 :
#Region " Code généré par le Concepteur Windows Form "
    Inherits System.Windows.Forms.Form

    Public Sub New()
        MyBase.New()

        ' Cet appel est requis par le concepteur.
        InitializeComponent()

        ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().

    End Sub

    'Form remplace la méthode Dispose pour nettoyer la liste des composants.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Requise par le Concepteur Windows Form
    Private components As System.ComponentModel.IContainer

    'REMARQUE : la procédure suivante est requise par le Concepteur Windows Form
    'Elle peut être modifiée à l'aide du Concepteur Windows Form.  
    'Ne la modifiez pas à l'aide de l'éditeur de code.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
 ...

End Sub


There's also :

 Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents GroupBoxPlanification As System.Windows.Forms.GroupBox
    Friend WithEvents CheckBoxSauvegardeActif As System.Windows.Forms.CheckBox

...

#End Region


And Finally i've added this code, to select the language into a combobox :

VB
Private Sub ComboBoxLangue_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBoxLangue.SelectedIndexChanged
        Select Case ComboBoxLangue.SelectedValue
            Case "FR"
                                System.Threading.Thread.CurrentThread.CurrentUICulture = FrenchCulture
                
            Case "EN"
                System.Threading.Thread.CurrentThread.CurrentUICulture = EnglishCulture
                
            Case Else
                System.Threading.Thread.CurrentThread.CurrentUICulture = FrenchCulture
                
        End Select

        My.Settings.Langue = ComboBoxLangue.SelectedValue.ToString
        My.Settings.Save()

        AfficherTexte()
    End Sub

    Private Sub AfficherTexte()
        Button1.Text = RM.GetString("Button1.Text")
        Button2.Text = RM.GetString("Button2.Text")
        ButtonAccederLogs.Text = RM.GetString("ButtonAccederLogs.Text")
        ButtonChoisirDossiersOutlook.Text = RM.GetString("ButtonChoisirDossiersOutlook.Text")
        ButtonDefinir.Text = RM.GetString("ButtonDefinir.Text")
        ButtonDossierArchivage.Text = RM.GetString("ButtonDossierArchivage.Text")
        ' A CONTINUER
    End Sub


And on the Load Form1 :

SQL
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' /////////////////////////////////////////////////////////////////
        ' /// Lit le settings pour les différents controles sur la form ///
        ' /////////////////////////////////////////////////////////////////

        ' On recharge les valeurs enregistrées pour tous les contrôles de la fenêtre
        My.Settings.Reload()

        Select Case My.Settings.Langue
            Case "FR"
                System.Threading.Thread.CurrentThread.CurrentUICulture = FrenchCulture
            Case "EN"
                System.Threading.Thread.CurrentThread.CurrentUICulture = EnglishCulture
            Case Else
                System.Threading.Thread.CurrentThread.CurrentUICulture = FrenchCulture
        End Select

        AfficherTexte()

        'Licence
...



The damned, is that i've got an error when running the application, that i don't understand :
Quote:
System.InvalidOperationException



VB
L'exception System.InvalidOperationException n'a pas été gérée
  Message=Une erreur s'est produite lors de la création du formulaire. Pour plus d'informations, consultez Exception.InnerException. L'erreur est : La référence d'objet n'est pas définie à une instance d'un objet.
  Source=OutlookEmailManager
  StackTrace:
       à OutlookEmailManager.My.MyProject.MyForms.Create__Instance__[T](T Instance) dans 17d14f5c-a337-4978-8281-53493378c1071.vb:ligne 190
       à OutlookEmailManager.My.MyProject.MyForms.get_Form1()
       à OutlookEmailManager.My.MyApplication.OnCreateMainForm() dans C:\Users\Pascal\Documents\Visual Studio 2010\Projects\OutlookEmailManager\OutlookEmailManager\My Project\Application.Designer.vb:ligne 35
       à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       à OutlookEmailManager.My.MyApplication.Main(String[] Args) dans 17d14f5c-a337-4978-8281-53493378c1071.vb:ligne 81
       à System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       à System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       à System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
       à System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
       à System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       à System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
       à System.Activator.CreateInstance(ActivationContext activationContext)
       à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       à System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.NullReferenceException
       Message=La référence d'objet n'est pas définie à une instance d'un objet.
       Source=OutlookEmailManager
       StackTrace:
            à OutlookEmailManager.Form1.ComboBoxLangue_SelectedIndexChanged(Object sender, EventArgs e) dans C:\Users\Pascal\Documents\Visual Studio 2010\Projects\OutlookEmailManager\OutlookEmailManager\Form1.vb:ligne 1023
            à System.Windows.Forms.ComboBox.OnSelectedIndexChanged(EventArgs e)
            à System.Windows.Forms.ComboBox.set_SelectedIndex(Int32 value)
            à System.Windows.Forms.ComboBox.set_Text(String value)
            à OutlookEmailManager.Form1.InitializeComponent() dans C:\Users\Pascal\Documents\Visual Studio 2010\Projects\OutlookEmailManager\OutlookEmailManager\Form1.vb:ligne 434
            à OutlookEmailManager.Form1..ctor() dans C:\Users\Pascal\Documents\Visual Studio 2010\Projects\OutlookEmailManager\OutlookEmailManager\Form1.vb:ligne 19
       InnerException:



Is anybody can help ?
Thanks !
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900