PeterBaileyUk
asked on
vb.net make textbox not visible after 1 minute elapsed
I have a menu item that needs a password entered for the feature to function. I would like to make it so that if they select the menu item but dont enter the password that the pw textbox will go invisible after one minute.
am working on a windows form application
am working on a windows form application
Hi Peter
You can add a timer to your form, when the menu item is clicked it starts the timer and displays the password textbox or small mini form/message box.
After timer is up it hides it
Hope this Helps.
If you can supply specific field names etc I can update it to work with your forms and fields
You can add a timer to your form, when the menu item is clicked it starts the timer and displays the password textbox or small mini form/message box.
After timer is up it hides it
Public tTimer As Timer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
tTimer = New Timer()
tTimer.Interval = 60000
tTimer.Enabled = False
AddHandler tTimer.Tick, AddressOf OnLayouttimerTick
End Sub
Private Sub menuitem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuitem.Click
'insert password box display code here
tTimer.Start()
End sub
Private Sub OnLayouttimerTick(sender As Object, e As EventArgs)
'change this to your password form or box
passwordtext.visible=false
tTimer.Enabled = False
End Sub
Hope this Helps.
If you can supply specific field names etc I can update it to work with your forms and fields
ASKER
ive got a key event on the text box itself like this:
the menu on clicks
the code all works as expected but I think its best to trap if someone selected a menu item and the textbox sat there waiting for input but none arrived.
ive called it tbpassword
Private Shadows Sub OnKeyUpTBPW(sender As Object, e As KeyEventArgs) Handles TBPassword.KeyUp
Dim tb1 = DirectCast(sender, TextBox)
Dim connectionString As String = ConfigurationManager.ConnectionStrings("Dictionary").ConnectionString
Dim StrProcName
If e.KeyCode.Equals(Keys.Enter) Then
'DataGridViewStrCommon.SearchAndSelect(tb1.Text, CBStrCommonSearchDesc.SelectedItem, True)
If tb1.Text = PW Then
'MessageBox.Show("correct")
If DeleteFinalTagSetsTableToolStripMenuItem.Checked = True Then
StrProcName = "usp_DeleteAllFinalTagSets"
ElseIf DeleteStrCommonResultsTableToolStripMenuItem.Checked = True Then
StrProcName = "usp_DeleteAllStrCommon"
ElseIf DeleteToolStripMenuItem.Checked = True Then
StrProcName = "usp_DeleteAllLinks"
End If
Using conn As New SqlConnection(connectionString)
Using cmd As New SqlCommand(StrProcName, conn)
cmd.CommandTimeout = 0
cmd.CommandType = CommandType.StoredProcedure
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
End Using
End Using
Else
MessageBox.Show("Password Incorrect")
TBPassword.Focus()
TBPassword.Text = ""
End If
TBPassword.Focus()
TBPassword.Text = ""
TBPassword.Visible = False
tb1.Clear()
e.Handled = True
End If
End Sub
the menu on clicks
Private Sub DeleteFinalTagSetsTableToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DeleteFinalTagSetsTableToolStripMenuItem.Click
Me.TBPassword.Visible = True
DeleteFinalTagSetsTableToolStripMenuItem.Checked = True
DeleteStrCommonResultsTableToolStripMenuItem.Checked = False
DeleteToolStripMenuItem.Checked = False
End Sub
Private Sub DeleteStrCommonResultsTableToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DeleteStrCommonResultsTableToolStripMenuItem.Click
Me.TBPassword.Visible = True
DeleteFinalTagSetsTableToolStripMenuItem.Checked = False
DeleteStrCommonResultsTableToolStripMenuItem.Checked = True
DeleteToolStripMenuItem.Checked = False
End Sub
Private Sub DeleteToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DeleteToolStripMenuItem.Click
Me.TBPassword.Visible = True
DeleteFinalTagSetsTableToolStripMenuItem.Checked = False
DeleteStrCommonResultsTableToolStripMenuItem.Checked = False
DeleteToolStripMenuItem.Checked = True
End Sub
the code all works as expected but I think its best to trap if someone selected a menu item and the textbox sat there waiting for input but none arrived.
ive called it tbpassword
ASKER
i may have made it overcomplex
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, it integrated nicely.
Once user tries to access the password protected function, and set the timer control to true.
Regards,
Chinmay.