programming an messagebox for a form with the opening of a program

JohnDW

Well-known member
Joined
Jun 13, 2012
Messages
60
Location
Antwerp, Belgium
Programming Experience
1-3
In Form_Ticket I have the following code in the Load event:

VB.NET:
[FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]Dim result1 [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]DialogResult[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] = [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]MessageBox[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Show([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"Use Ticket With Buttons?"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2], _
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515][FONT=Consolas][SIZE=2][COLOR=#a31515]"Buttons?"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2], _
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]MessageBoxButtons[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].YesNo)
 
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] result1 = DialogResult.Yes [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Exit Sub
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]DGV2.Columns(11).Visible = [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]False
End If
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]


I would like that with the opening of my program the user can
answer this messagebox,
so that the answer is know throughout the entire program ,
and the question is no longer made ​​at the opening and reopening of the form_ticket.

How can I achieve this?

Txs,

John









 
Last edited:
You can add a user setting in Project settings of type System.Windows.Forms.DialogResult and set its default value to None.
Upon startup you ask question only if setting is None and assign the dialog result to the setting.
Application Settings
 
Despite my efforts, I do not succeed.
what I did:

project
properties,
application settings,
especially: settings
type: System.Windows.Forms.Dialogresult
Scope: User
Value: None

I have a start up form

and there I put my code in:

VB.NET:
   Private Sub Start_Load (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim result1 AsDialogResult = MessageBox.Show ("Use Ticket With Buttons?", _
"Buttons", _
MessageBoxButtons.YesNo)

If result1 = DialogResult.Yes Then
Exit Sub
else
DGV2.Columns (11). Visible = False
end If

    end Sub
end Class
[/ CODE]

I'm doing it wrong, this code can't reacht form ticket.

I need help.

John
 
You haven't even tried to use the setting in your code. Let say you added a setting named ticket:
        If My.Settings.ticket = Windows.Forms.DialogResult.None Then
            My.Settings.ticket = MessageBox.Show("Use Ticket With Buttons?", "Buttons", MessageBoxButtons.YesNo)
        Else
            MessageBox.Show("stored ticket answer is " & My.Settings.ticket.ToString)
        End If
 
Everything works great.
But ...
now I'm trying the change the settings from 'Ticket' in the Properties, by changing the scope of 'user' to
'application'.
(The idea is that the decision of the user will be kept by the program
when the program is closing.)
When I debug the program it displays an error:
Property 'Ticket' is read only.

However, the program works when I run
close the development environment and open the application.
But not while debugging.
If I change the settings back to 'user' then I can debug, and
again without error.

Any idea what's the problem, and how I can solve this?

Grt,

John
 
Settings Page, Project Designer
Scope
Select either Application or User.

Application-scoped settings (such as connection strings) are associated with the application; users cannot change them at run time.

User-scoped settings (such as system fonts) are intended to be used for user preferences; users can change them at run time.
Application Page, Project Designer (Visual Basic)
Save My.Settings on Shutdown
Select this check box to specify that the application's My.Settings settings are saved when users shut down their computers. The default setting is enabled. If this option is disabled, you can save application settings manually by calling My.Settings.Save.
 
Back
Top