|
-
Feb 11th, 2013, 11:45 PM
#1
Thread Starter
Lively Member
[RESOLVED] Bypass 1st Form based on My.Settings (conditional)
Hey guys / gals. I'm having a little trouble figuring out how to bypass the first form of my program based on the content of a My.Settings... setting.
Details
When the program loads it shows a form that allows you to select the network adapter you wish to monitor.
When you have selected the adapter you click a button (Save), which shows Form1 (main form) and saves the settings.
When Form1 loads it closes NICselect then reloads the settings.
txtAdapters.Text is the property I wish to check.
Problem
The issue is that it gets annoying having to reselect the adapter each time the program is launched, so I wish to check the My.Settings property of a control on NICselect which holds the last selected adapter. I have tried a few times, but I'm still getting the NICselect form on each launch.
Current code
NICselect load:
Code:
'Form Load
Private Sub NICselect_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'Need to add My.Settings check to see if the adapter matches the My.Settings setting. If so, skip this form and open Form1.
'Otherwise, start with this form.
If My.Settings.txtAdapters <> Nothing Then
Form1.Show()
Me.Close()
Else
Me.Show()
End If
Save command for NICselect:
Code:
'Save, open Form1, close this form
Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
Form1.Show()
My.Settings.Save()
perfErrorCatcher.Dispose()
End Sub
Form1 load
Code:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
perfNetDown.InstanceName = NICselect.txtAdapters.Text.Replace("/", "_")
perfNetUp.InstanceName = NICselect.txtAdapters.Text.Replace("/", "_")
NICselect.Close()
My.Settings.Reload()
Any and all help contributed would be greatly appreciated. =)
-
Feb 12th, 2013, 12:04 AM
#2
Fanatic Member
Re: Bypass 1st Form based on My.Settings (conditional)
Hi,
im not sure of your question but to set the setting
Code:
my.settings.txtAdapters = "something"
and to test you have it there
Code:
if my.settings.txtAdaptors <> "" then
form1.show()
me.close
else
'nothing as already on me
end if
My CodeBank Submissions
- Listbox with transparency and picture support - Click Here
- Check for a true internet connection - Click Here
- Open Cash drawer connected to receipt printer - Click Here
- Custom color and size border around form - Click Here
- Upload file to website without user logins, includes PHP - Click Here
- List All Removable USB Storage Devices - Click Here
- Custom On/Off Slide Control - Click Here
- Insert multiple rows of data into one database table using parameters - Click Here
- Trigger USB/Serial Cash Drawer - Click Here
-
Feb 12th, 2013, 12:11 AM
#3
Re: Bypass 1st Form based on My.Settings (conditional)
You're going about that all wrong I'm afraid. You selection dialogue shouldn't know anything about the main form. In the project properties, select the main form as the startup form. Handle the Startup event of the application, which is raised before the startup form is created, and display your selection dialogue in there. Let's say that you have a user setting named SelectedNic. Your Startup event handler would look something like this:
Code:
If My.Settings.SelectedNic = String.Empty Then
'No NIC selected yet.
Using dialogue As New NicSelectionDialogue
If dialogue.ShowDialog() = DialogResult.Cancel Then
'No NIC selected so exit app.
e.Cancel = True
End If
End Using
End If
Your dialogue then simply saves the selected NIC to the SelectedNic property and the dialogue will never be shown again.
-
Feb 14th, 2013, 12:03 PM
#4
Thread Starter
Lively Member
Re: Bypass 1st Form based on My.Settings (conditional)
Thanks for pointing me in the right direction jmcilhinney. I'll now mark this as Resolved.
Here's what I did in case you're interested:
NICselect Load:
Code:
Removed what I had before.
Save command for NICselect:
Code:
'Save, open Form1, close this form
Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
My.Settings.Save()
Form3.lblCurrentAdapter.Text = txtAdapters.Text.Trim
perfErrorCatcher.Dispose()
Form1.Show()
Me.Close()
End Sub
Form1 Load:
Code:
If My.Settings.txtAdapters = String.Empty Then
'No NIC selected yet.
NICselect.Show()
End If
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|