How to force form to show again on application startup? - vb.net

I have a Help form that shows for the first time when the application is started. After the initial startup, that form doesn't show up anymore. Is there a way to reset the show form? Here's my code to only show it once base on the application setting. When the application exit, the application sets the showform to false. <<--Need to reset on the user's computer. Reason i need this is if i have a update to application, i need to show user the updates on that help form.
Private Sub AboutInformation_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
If IsNewVersionAvailable() = True Then
Dim showNextTime As Boolean
showNextTime = My.Settings.LoadAboutForm
If showNextTime = False Then
Show()
Location = New Point(0, 0)
showNextTime = True
My.Settings.LoadAboutForm = showNextTime
My.Settings.Save()
Else
Close()
myForm.Show()
End If
End if
End Sub

For anyone looking for a answer, I save my currentVersion in the application setting on the main form closed and on startup of the help form it checks if the previous version matches the updated version, if it doesn't it will show help form, if it does, it skips to the main for.
Private Sub AboutInformation_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Location = New Point(0, 0)
'If ApplicationDeployment.IsNetworkDeployed Then
Try
Dim thisVersion As Version = ApplicationDeployment.CurrentDeployment.CurrentVersion
If thisVersion.ToString = My.Settings.CurrentVersion Then
Dim showNextTime As Boolean
showNextTime = My.Settings.LoadAboutForm
If showNextTime = False Then
Show()
Location = New Point(0, 0)
showNextTime = True
My.Settings.LoadAboutForm = showNextTime
My.Settings.Save()
Else
Close()
myMainForm.Show()
End If
End If
Catch ex As Exception
'MsgBox(ex.Message)
End Try
End Sub
'Saving setting for main form closed.
Private Sub myMainForm_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs) Handles Me.FormClosed
If ApplicationDeployment.IsNetworkDeployed Then
Dim currentVersion As Version = ApplicationDeployment.CurrentDeployment.CurrentVersion
Debug.Print(currentVersion.ToString)
My.Settings.CurrentVersion = currentVersion.ToString
End If
My.Settings.Save()
End Sub

Related

Underlines of MaskedTextBox disappear

i have a problem in Windows Forms. I've created a form where I can enter the first and last name and click on the Search-Button to show another form with the following code:
Private Sub btnSearchUser_Click(sender As Object, e As EventArgs) Handles btnSearchUser.Click
If Me._clsfrmChild Is Nothing Then
Me._clsfrmChild = New clsFrmChild
End If
If Me._clsfrmChild.ShowDialog = False Then
Me._clsfrmChild.ShowDialog(Me)
End If
In the second form I have a MaskedTextbox:
Empty MaskedTextBox
Whatever I do, If I close the second form with Visible = False and reopen it again, the MaskedTextBox looks like this:
MaskedTextBox without underlines
I close the second form that way:
Private Sub btnAbort_Click(sender As Object, e As EventArgs) Handles btnAbort.Click
Me.Visible = False
End Sub
Does someone of you know why this problem is caused?
This is really not the way you supposed to work with dialogs. The proper way is this
dim result as DialogResult
using f as Form = New MyForm()
result = f.ShowDialog()
' here you can work with form's public properties etc
end using
' optionally here you can continue massaging the result
if result = DialogResult.Ok then
' do for ok result
else
' do for other result. You can have severul results - add elseif
end if
Here is how to make a dialog with results in general. This will be similar to how MessageBox.Show() works.
Public Class clsFrmChild
Private Sub New()
InitializeComponent()
End Sub
Public Shared Shadows Function Show() As DialogResult
Dim result As DialogResult
Using f As New clsFrmChild()
result = f.ShowDialog()
End Using
Return result
End Function
Private Sub OkButton_Click(sender As Object, e As EventArgs) Handles OkButton.Click
DialogResult = DialogResult.OK
Close()
End Sub
Private Sub CancelButton_Click(sender As Object, e As EventArgs) Handles CancelButton.Click
DialogResult = DialogResult.Cancel
Close()
End Sub
End Class
Note the constructor is privatized so there is no more Me._clsfrmChild = New clsFrmChild. You will see the displaying of the modal dialog is much simpler when called like MessageBox
Private Sub btnSearchUser_Click(sender As Object, e As EventArgs) Handles btnSearchUser.Click
Dim result = clsFrmChild.Show() ' static method call instead of instance method
Select Case result
Case DialogResult.OK
MessageBox.Show("Ok")
Case DialogResult.Cancel
MessageBox.Show("Cancel")
End Select
End Sub
If you are not interested in returning a standard DialogResult, you could change the return type to whatever you like such as a custom class, with more information (such as you want to return a string in addition to DialogResult) i.e.
Public Class clsFrmChildResult
Public Property Text As String
Public Property DialogResult As DialogResult
End Class
...
Public Shared Shadows Function Show() As clsFrmChildResult
Dim result As clsFrmChildResult
Using f As New clsFrmChild()
Dim dr = f.ShowDialog()
result = New clsFrmChildResult With {.Text = TextBox1.Text, .DialogResult = dr}
End Using
Return result
End Function
...
Private Sub btnSearchUser_Click(sender As Object, e As EventArgs) Handles btnSearchUser.Click
Dim result = clsFrmChild.Show()
Select Case result.DialogResult
Case DialogResult.OK
MessageBox.Show("Ok")
Dim myString = result.Text
Case DialogResult.Cancel
MessageBox.Show("Cancel")
End Select
End Sub

opendialog to show a file and save it with checkbox vb.net

I'm trying to connect to a database (mdb file of my choice) in a login screen and i want to save it for faster logon next times i boot the software.
I click on choose database button, opendialog lets me choose the file, i click OK and the db location shows in a textbox.
there's a checkbox beneath to save it before i connect to it.
But i can't manage to keep the checkbox checked, nor the textbox filled after i restart te program.
here's my current code:
Public Class LoginScreen
Private Sub Loginscreen_load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ProgressBar2.Minimum = 0
ProgressBar2.Maximum = 100
ProgressBar2.Visible = False
Panel1.Visible = False
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Application.Exit()
End Sub
Private Sub btnExit2_Click(sender As Object, e As EventArgs) Handles btnExit2.Click
Application.Exit()
End Sub
Private Sub tmrLogin_Tick(sender As Object, e As EventArgs) Handles tmrLogin.Tick
ProgressBar2.Value = ProgressBar2.Value + 20
lblLoginMessages.Text = ProgressBar2.Value & "%" & " Completed"
If ProgressBar2.Value >= 100 Then
tmrLogin.Enabled = False
If txtUser.Text = "azert" And txtPassword.Text = "azert" Then
ProgressBar2.Value = 0
Else
lblLoginMessages.Text = "Wrong credentials, Try again!"
pboxClosed.Visible = True
PboxOpen.Visible = False
ProgressBar2.Value = 0
txtPassword.Text = ""
txtUser.Text = ""
End If
End If
End Sub
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
ProgressBar2.Visible = True
tmrLogin.Enabled = True
pboxClosed.Visible = False
PboxOpen.Visible = True
''navraag doen om dit correct in te stellen! ! ! ! !!
'If ProgressBar2.Value = 100 Then
'lblLoginMessages.Text = "Logging in..."
Me.Hide()
Mainscreen.Show()
'End If
If chkSavePassword.Checked = True Then
My.Settings.databaselocation = txtDatabaselocationshow.Text
My.Settings.SaveLocation = True
End If
End Sub
Private Sub btnDBConnect_Click(sender As Object, e As EventArgs) Handles btnDBConnect.Click
If Panel1.Visible = False Then
Panel1.Visible = True
Else
Application.Exit()
End If
End Sub
Private Sub btnChoose_Click(sender As Object, e As EventArgs) Handles btnChoose.Click
Dim strtext As String
OpenFileDialog1.Filter = "Database Files | *.mdb"
OpenFileDialog1.InitialDirectory = "F:\GoogleDrive\EINDWERK VBNET"
OpenFileDialog1.Title = "Choose your Database"
OpenFileDialog1.ShowDialog()
strtext = OpenFileDialog1.FileName
txtDatabaselocationshow.Text = strtext
'If OpenFileDialog1.ShowDialog = DialogResult.OK Then
' strtext = OpenFileDialog1.FileName
' txtDatabaselocationshow.Text = strtext
'Else
' MsgBox("Error: the database file could not be read, try again.")
'End If
End Sub
Private Sub tmrshowloginpanel_Tick(sender As Object, e As EventArgs) Handles tmrshowloginpanel.Tick
Panel1.Width += 5
If Panel1.Width >= 700 Then
tmrshowloginpanel.Stop()
End If
End Sub
End Class
i've scoured the net but can't really find what to do?
if you need more information, shoot!
Walk through this with me:
Make a new project, one form, add a textbox and a combobox.
Click the textbox:
In the properties grid at the top click (Application Settings), then the 3 dots next to Property Binding. Scroll to Text. Drop down the setting and choose New at the bottom.
Give it a name of ChosenDatabasePath or something useful and descriptive like that
Repeat from "Click the textbox" for the checkbox instead, and this time bind the Checked property not the Text property.. Call the checkbox's Checked binding SavePassword or similar
Close all the dialogs so you're back at the form
Click anywhere on the background of the form when switch to Events in the property grid, find FormClosing and double click it
Put My.Settings.Save() in the FormClosing event handler
Run the app, write something in the textbox, close the form (by the X, not by stopping debugging), then immediately open the app again (run it)

Access dynamically created UserControl's Public Declare - WinForms

Logic
There is Form1 with a FlowLayoutPanel 'flowItems' to be populated by UserControl 'UCItem'. For populating flowItems, an array is used. For-Loop loopes over the array and creates a new UCItem, gives it a tag name with number and adds it to flowItem. All this part works.
Issue
I want to change the public declared boolean variable 'isChecked' each time the newly created UCItem is clicked. For achieving this, I've added an event handler (UCItem.Click) which gets and sets the property.
How ever, I'm unable to access the public boolean variable in UCItem.
Code: UC_Item.vb
Public isChecked As Boolean = False
Private Sub toggle_color()
If Me.BackColor = Color.FromArgb(24, 24, 24) Then
Me.BackColor = Color.RoyalBlue
Me.txtName.BackColor = Color.RoyalBlue
Me.txtName.ForeColor = Color.Black
Me.BackgroundImage = Nothing
isChecked = True
Else
Me.BackColor = Color.FromArgb(24, 24, 24)
Me.txtName.BackColor = Color.Black
Me.txtName.ForeColor = Color.White
Me.BackgroundImage = Image.FromFile(Application.StartupPath & "/res/UCItem_Wallpaper.png")
isChecked = False
End If
End Sub
Private Sub UC_Item_Click(sender As Object, e As EventArgs) Handles MyBase.Click
toggle_color()
End Sub
Private Sub TxtName_Click(sender As Object, e As EventArgs) Handles txtName.Click
toggle_color()
End Sub
Code: Form1.vb
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim UCItem As UC_Item
flowItems.SuspendLayout()
For i As Integer = 0 To items.Count - 1
UCItem = New UC_Item
UCItem.Tag = "UCItem" & i
UCItem.txtName.Text = items(i).ToString
flowItems.Controls.Add(UCItem)
UCItem.Show() : UCItem.Visible = True
AddHandler(UCItem.Click), AddressOf UCItem_Click
Next
flowItems.ResumeLayout()
End Sub
Private Sub UCItem_Click(sender As Object, ByVal e As EventArgs)
' -- not working part --
' If sender.isChecked = True Then
' sender.isChecked = False
' else
' sender.isChecked = True
End Sub
Tried
I've tried passing 'UCItem As sender.Tag' but this doesn't work too. I can't access the .Tag and .Name property of sender in the click event.
Any help is appreciated!

PictureBox is not showing up on button click event

I am using a PictureBox inside a button click event. When the button is clicked I am enabling the PictureBox and I am running a long database call and at the end of the process, I am trying to disable the PictureBox. Inside the PictureBox I have a loading GIF.
But I don't know what's happening. My PictureBox does not show up..
Please suggest how can I fix this. I tried Thread.Sleep(1000), but it didn't work.
Private Sub btnRetrieve_Click(sender As Object, e As EventArgs) Handles btnRetrieve.Click
Me.PictureBox1.Visible = True
lblSuccess.Text = Nothing
UltraNumberOfConveyance.Value = Nothing
GetData() --Long Running Query
Me.PictureBox1.Visible = False
End Sub
My GetData Function:
Private Function GetData()
dsCheckPointTimes = GetCheckPointTimesByTerminalID()
dtDataTable = dsCheckPointTimes.Tables(0)
chkdtDataTable = dsCheckPointTimes.Tables(1)
If Not DBNull.Value.Equals(chkdtDataTable.Rows.Item(0).Item("ConveyanceName")) Then
lblConveyanceNameText.Text = chkdtDataTable.Rows.Item(0).Item("ConveyanceName").ToString()
End If
If Not DBNull.Value.Equals(chkdtDataTable.Rows.Item(0).Item("NumberOfConveyance")) Then
UltraNumberOfConveyance.Value = chkdtDataTable.Rows.Item(0).Item("NumberOfConveyance")
End If
If Not DBNull.Value.Equals(chkdtDataTable.Rows.Item(0).Item("Dock")) Then
UltratxtChangeLabel1.Value = chkdtDataTable.Rows.Item(0).Item("Dock")
End If
If Not DBNull.Value.Equals(chkdtDataTable.Rows.Item(0).Item("Lines")) Then
UltratxtChangeLabel2.Value = chkdtDataTable.Rows.Item(0).Item("Lines")
End If
If Not DBNull.Value.Equals(chkdtDataTable.Rows.Item(0).Item("CHECKPOINTTYPE")) Then
SetFields(chkdtDataTable.Rows.Item(0).Item("CHECKPOINTTYPE"))
End If
If dtDataTable.Rows.Count > 0 Then
LoadFlow()
Else
lblSuccess.Text = "No Records Found! Please check the ordernumber"
lblSuccess.ForeColor = Color.Red
End If
Return Nothing
End Function
Use a BackgroundWorker to do this:
Private WithEvents bgw As New BackgroundWorker
Private Sub btnRetrieve_Click(sender As Object, e As EventArgs) Handles btnRetrieve.Click
PictureBox1.Visible = True
bgw.RunWorkerAsync()
End Sub
Private Sub bgw_DoWork(sender As Object, e As DoWorkEventArgs) Handles bgw.DoWork
GetData() --Long Running Query
End Sub
Private Sub bgw_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles bgw.RunWorkerCompleted
PictureBox1.Visible = False
End Sub

Using a timer to update form - VB.Net

I want to display the status of aspects of my application on a form.
I tried adding a timer to the form. Every 10 seconds the timer runs and checks a database for a particular status, then changes elements on the form based on the status.
This works fine for changing the colour of menu items, but when I try and make an image (in)visible on the form, I get a cross-thread error.
Should I be using a timer, Backgroundworker or something else?
Does someone have a basic bit of code that will do this elegantly?
Private WithEvents tmrMain As New System.Timers.Timer(10000)
Private Sub frmMaster_Load(sender As Object, e As EventArgs) Handles Me.Load
tmrMain.Enabled = True
tmrMain.Start()
End Sub
Private Sub tmrMain_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles tmrMain.Elapsed
Dim TRunning As Boolean = True
TRunning = BTools.CheckImportRunningStatus '' This gets the on/off status from the DB
If TRunning Then
miFileMYOBImport.ForeColor = Color.Red '' Change menu color
pbMYOBDownload.Visible = True '' Make image visible
Else
miFileMYOBImport.ForeColor = Color.DarkGreen
pbMYOBDownload.Visible = False
End If
End Sub
Try:
Private Sub MakeImageVisible(ByVal control As Control, ByVal visible As Boolean)
If control.InvokeRequired Then
control.BeginInvoke(New Action(Of Control, Boolean)(AddressOf MakeImageVisible), control, visible)
Else
control.Visible = visible
End If
End Sub
Private Sub tmrMain_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles tmrMain.Elapsed
Dim TRunning As Boolean = True
TRunning = BTools.CheckImportRunningStatus '' This gets the on/off status from the DB
If TRunning Then
miFileMYOBImport.ForeColor = Color.Red '' Change menu color
Else
miFileMYOBImport.ForeColor = Color.DarkGreen
End If
MakeImageVisible(pbMYOBDownload, TRunning) ' Make image visible or invisible
End Sub