VisualBasicJC

I would like my program could have an option, before start (and ONLY FIRST TIME starting), to give users choice between two or more languages.

Then my program would start, always, with language selected first time program started.

How could I do it

I tried DialogueBox but it seems not work very well...

Maybe using a second form, which should be executed before my program, could work

I also think using If statements, I could call Text properties to show correct language to user.

Or there is other way to show correct words with my program



Re: Visual Basic Express Edition My program with different languages

ReneeC

Main Menu | Project | Properties | Settings

Create a user scope boolean setting called FirstTime and set its default value to True

In your form load event:

If Mysettings.FirstTime then

' add your first time code

My.settings.firsttime = false

My.Settings.Save

End if

The first time code will never run after the first time.






Re: Visual Basic Express Edition My program with different languages

VisualBasicJC

Very good idea ReneeC!

I am also with two other problems with my program.

Maybe you, people, could help me.

First problem, I tried to avoid normal background color of my form to appear....

I would like to use a color such as inside my Form_Paint event. But that personal color appears always AFTER previous color mentioned above. How can I clear that previous normal color

Second problem is about my If statments to use my buttons.

As you can see, my If code to my ComboBox1 is not working very well.

Button1 should be enabled when I choose any idiom.

Public Class Form1 '(to choose idiom)

Friend WithEvents Button1 As Button

Friend WithEvents Button2 As Button

Friend WithEvents ComboBox1 As ComboBox

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

'My Form should have:

With Me

.FormBorderStyle = Windows.Forms.FormBorderStyle.None

.Size = New Size(300, 172)

.MinimizeBox = False

.MaximizeBox = False

'

'ComboBox1:

.ComboBox1 = New ComboBox

'

.ComboBox1.Location = New Point(81, 33)

.ComboBox1.Size = New Size(121, 21)

.ComboBox1.TabIndex = 1

.ComboBox1.Items.AddRange(New Object() {"Choose Idiom", "English", _

"Francais", "Portugues"})

.ComboBox1.SelectedIndex = 0 'This keeps "Choose Idiom" as

'first item visible when Form loads.

'

.Controls.Add(Me.ComboBox1)

'

'Button1:

.Button1 = New Button

'

.Button1.Location = _

New Point(31, Me.Height - (Button1.Height * 3))

.Button1.Size = New Size(75, 23)

.Button1.TabIndex = 2

.Button1.Text = "OK"

.Button1.Enabled = False 'because I selected nothing inside ComboBox1

'

.Controls.Add(Me.Button1)

'

'Button2:

.Button2 = New Button

'

.Button2.Location = _

New Point(179, Me.Height - (Button2.Height * 3))

.Button2.Size = New Size(75, 23)

.Button2.TabIndex = 3

.Button2.Text = "Cancel"

.Button2.Enabled = True

'

.Controls.Add(Me.Button2)

'

End With

'Suggested by RenneeC:

'Multilanguage program:

'

'-> Choose in the main menu: PROJECT >> YourApplicationNamePROPERTIES >>

'>> SETTINGS.

'

'Modify all settings:

'NAME: FirstTime

'TYPE: Boolean

'SCOPE: User

'VALUE: True

If My.Settings.FirstTime Then

If ComboBox1.SelectedIndex <> 0 Then

Button1.Enabled = True

If Me.DialogResult = Windows.Forms.DialogResult.OK Then

MessageBox.Show(Me, "You choose" & ComboBox1.SelectedItem.ToString)

'To write code to load a second Form with Idiom selected.

ElseIf Me.DialogResult = Windows.Forms.DialogResult.Cancel Then

MessageBox.Show(Me, "You have chosen 'CANCEL', so program will not open!" _

& vbNewLine & "You can try later to chose any idiom!", _

"Warning!", MessageBoxButtons.OK)

Application.Exit()

End If

End If

My.Settings.FirstTime = False

My.Settings.Save()

End If

End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

' Get Graphics Object

Dim g As Graphics = e.Graphics

Dim MyFormSize As New Rectangle(0, 0, 300, 172)

'create brush

Dim MyBrush As _

New Drawing2D.LinearGradientBrush(MyFormSize, _

Color.Black, _

Color.White, _

Drawing2D.LinearGradientMode.BackwardDiagonal)

' Draw to screen.

e.Graphics.FillRectangle(MyBrush, MyFormSize)

'tidy up

MyBrush.Dispose()

End Sub

Private Sub Button1_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Me.DialogResult = Windows.Forms.DialogResult.OK

End Sub

Private Sub Button2_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

Me.DialogResult = Windows.Forms.DialogResult.Cancel

End Sub

End Class





Re: Visual Basic Express Edition My program with different languages

VisualBasicJC

ReneeC, all my questions above are already solved BUT, I am SO LOST when I try to write correct code to execute your idea using My.Settings.FirstTime.

It never saves and executes ONLY second Form with correct text.

I write this simple example below, to try to get your idea, about which code, I should write to execute ONLY second Form, after I already to have chosen my language first time my program started.

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Button1.Visible = False

ComboBox1.Items.AddRange(New Object() {"", "English", _

"Francais"})

ComboBox1.SelectedIndex = 0

If My.Settings.MyOption And _

Me.DialogResult = Windows.Forms.DialogResult.OK Then

'With this option, my language chosen with Form1

'( using ComboBox1 and, when I clicked button "OK",

'to confirm my chose ), should remain.

'

'Then Form2 will be always executed ( without Form1 to be

'shown ) and, with language chosen first time:

My.Settings.MyOption = False

My.Settings.Save()

End If

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Me.DialogResult = Windows.Forms.DialogResult.OK

Dim MeuForm2 As New Form2

MeuForm2.ShowDialog()

End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

If ComboBox1.SelectedIndex <> 0 Then

If ComboBox1.SelectedIndex = 1 Then 'English

Button1.Text = "Ok"

ElseIf ComboBox1.SelectedIndex = 2 Then 'Francais

Button1.Text = "Accepter"

End If

Button1.Visible = True

Else

Button1.Visible = False

End If

End Sub

End Class

-----------------------------------------------------//------------------------

And inside my Form2:

Public Class Form2

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Form1.ComboBox1.SelectedIndex = 1 Then 'English

Me.Button1.Text = "Ok"

ElseIf Form1.ComboBox1.SelectedIndex = 2 Then 'Fran ais

Me.Button1.Text = "Accepter"

End If

End Sub

End Class