How do I get a "show password" effect in vb.net? - vb.net

I am making an email login program in visual basic 2015 with various options, one of them being the option to show password or not with probably a check box. It is just a simple, standard windows forms application, I am relatively new to it.
Edit: Answered by jmcilhinney. Thanks! :D
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
'Display plain text if and only if check box is checked.
TextBox1.UseSystemPasswordChar = Not CheckBox1.Checked
End Sub

Set the UseSystemPasswordChar property of your TextBox to True to mask the password.
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
'Display plain text if and only if check box is checked.
TextBox1.UseSystemPasswordChar = Not CheckBox1.Checked
End Sub

Private Sub txtPassword_MouseHover(sender As Object, e As EventArgs) Handles txtPassword.MouseHover
txtPassword.PasswordChar = ""
End Sub
Private Sub txtPassword_MouseLeave(sender As Object, e As EventArgs) Handles txtPassword.MouseLeave
txtPassword.PasswordChar = "*"
End Sub

You have to do couple of changes. Change your password textbox UseSystemPasswordChar to false and the PasswordChar to Char(0). Something like this:
If chkViewPassword.Checked Then txbPwd.PasswordChar = Convert.ToChar(0) Else txbPwd.PasswordChar = Convert.ToChar("*")
txbSMTPPwd.UseSystemPasswordChar = Not chkViewPassword.Checked

Related

Enable/Disable a form while in an another form

I'm trying to figure out how to disable my form(Form1.vb) without hiding it then enabling it after I'm done with the other form(Form2.vb).
I've searched on youtube but it says C#. I've tried it but somehow it was indicated as an error in VS 2015. I tried messing around with the syntax because I really can't figure it out. The syntax that I have tried is "LandingForm.ActiveForm.Owner.Enabled = True".
Indicated below are the codes of my system. The first one is form1.vb/LandingForm.vb and the second one is form2.vb/AcctSettings.vb.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Enabled = False
AcctSettings.Show()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
LandingForm.ActiveForm.Owner.Enabled = True
Me.Hide()
End Sub
Am I missing something? Can somebody help?
On your form1 just have a simple line like
Form2.Show()
wherever/however you wish to open the other form (button etc.)
then in the code for that form2 in the formload handeler have
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form1.Enabled = False
End Sub
This will keep form1 open but basically grey it out.
Then have a simple button click like so to have access to form 1.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Form1.Enabled = True
End Sub
And you are done! And if you wish just add another button or a IF statement to the button2 sub and say form1.enabled = false if you want to be able to enable/disable etc.
To enable/disable your userform :
To disable your userform you will need yo enable it before :
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form1.Enabled = True
Form1.Enabled = False
End Sub
To disable it will be easier you just got to set your userform.enabled as False
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Form2.Enabled = True
End Sub
If you want to close your userform useroform.Unload might be the solution.
In your code it would be like this :
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Enabled = False
AcctSettings.Show()
form1.Unload
End Sub
and
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
LandingForm.ActiveForm.Owner.Enabled = True
Me.Hide()
form2.Unload
End Sub
an other option is to Hide your user form : it will just hide the userform and will not release the objects and variables from the memory. Where as Unload method will release the objects and variables from the memory.
UserForm1.Hide
To conclude : Hide method will be used when we want to hide the form temorarly and to show after sometime to the user. Where as unload will be used when it completes the task.
Note that this is YourUserForm_Name.Unload

VB.Net BalloonTipText appears as a black rectangle

I have a strange problem, I have created a test form FrmTest. Added a NotifyIcon and added the code shown:
Public Class FrmTest
Private Sub FrmTest_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Sub FormTest_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Click
Call SetBalloonTip()
NotifyIcon1.Visible = True
NotifyIcon1.ShowBalloonTip(30000)
End Sub
Private Sub SetBalloonTip()
NotifyIcon1.Icon = SystemIcons.Exclamation
NotifyIcon1.BalloonTipTitle = "Balloon Tip Title"
NotifyIcon1.BalloonTipText = "Balloon Tip Text."
NotifyIcon1.BalloonTipIcon = ToolTipIcon.Error
End Sub
End Class
When I click to make the balloon appear I get this:
I must be doing something obviously wrong but I am stumped!
There is nothing to say you did well...
That is what a balloon Tip looks like on Windows 10. Best of luck.

How to do a 'Button.Clicked' tag, but for Bunifu?

I was wondering what the code is to if a button is selected, then say it will send the enter key. This make no sense, I know, and I'm sorry, but my code might help.
Private Sub BunifuCheckbox1_OnChange(sender As Object, e As EventArgs) Handles BunifuCheckbox1.OnChange
If BunifuFlatButton1.clicked() And BunifuCheckbox1.Checked = True Then
SendKeys.Send("{Enter}")
End If
End Sub
So when you look at 'BunifuFlatButton1.clicked' is there a tag for that?
Rather than try to send the string when you change the checkbox, delete that sub and use this. This way, you can change the checkbox and then click the button
Private Sub BunifuFlatButton1_Click(sender As Object, e As EventArgs) Handles BunifuFlatButton1.Click
If BunifuCheckbox1.Checked = True Then
SendKeys.Send("{Enter}")
End If
End Sub

result of a modal form in vb.net

I create a form 'frmX' and i call it as a modal form :
res = frmX.ShowDialog()
This form has 3 buttons, Abort(3), Retry(4) and Ignore(5), but when the form opens, all the buttons on the first click return 2.
I don't know why this occurs--all of the buttons has their property DialogResult right.
*Private Sub btnIgnorar_Click(sender As Object, e As EventArgs) Handles btnIgnorar.Click
btnIgnorar.DialogResult = DialogResult.Ignore
End Sub
Private Sub btnAbortar_Click(sender As Object, e As EventArgs) Handles btnAbortar.Click
btnAbortar.DialogResult = DialogResult.Abort
End Sub
Private Sub btnReintentar_Click(sender As Object, e As EventArgs) Handles btnReintentar.Click
btnReintentar.DialogResult = DialogResult.Retry
End Sub*
Can someone help me?
Could do with seeing a bit more context, but the following should do what I think you want:
Private Sub btnIgnorar_Click(sender As Object, e As EventArgs) Handles btnIgnorar.Click
DialogResult = DialogResult.Ignore
Close
End Sub
This will close the dialog and return the associated result code to the caller. As to the original code, it seems a bit strange setting the values in the buttons click handlers?
The error comes from the fact that you set the DialogResult of the buttons. You must set the DialogResult of the form !
You actually have more than one option.
Option 1 : Set the Form.DialogResult
Private Sub btnIgnorar_Click(sender As Object, e As EventArgs) Handles btnIgnorar.Click
Me.DialogResult = DialogResult.Ignore
End Sub
Private Sub btnAbortar_Click(sender As Object, e As EventArgs) Handles btnAbortar.Click
Me.DialogResult = DialogResult.Abort
End Sub
Private Sub btnReintentar_Click(sender As Object, e As EventArgs) Handles btnReintentar.Click
Me.DialogResult = DialogResult.Retry
End Sub
Option 2 : Set the Button.DialogResult
Public Sub New()
InitializeComponents()
'Your init code here
'...
'By setting the buttons DialogResults, you don't even have to handle the click events
btnIgnorar.DialogResult = DialogResult.Ignore
btnAbortar.DialogResult = DialogResult.Abort
btnReintentar.DialogResult = DialogResult.Retry
End Sub
'However, if you need to do some stuff before closing the form, you can
Private Sub btnAbortar_Click(sender As Object, e As EventArgs) Handles btnAbortar.Click
'Do some stuff
'You don't need the following line, as it will be done implicitly
'Me.DialogResult = DialogResult.Abort
End Sub

Enable and disable TextBox with a checkbox in visual basic

I've 6 TextBox and 6 CheckBox. Now I want to disable the TextBox1 with a CheckBox1 and reactivate it with the Same CheckBox.
How a can do it?
Edit1 15.55 14/02/2013
I have done so to solve my problem!
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
TextBox1.Enabled = False
ElseIf CheckBox1.Checked = False Then
TextBox1.Enabled = True
End If
End Sub `
This will work, just add more for the other check boxes
Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
TextBox1.Enabled = True
Else
TextBox1.Enabled = False
End If
End Sub
What this does: if checkbox1 is check, the checked_changed event fires and the code inside is ran. The if statement looks to see if the checkbox is checked or not. If it is checked, then it sets the textbox1 to enabled, if not it sets it to disabled. Be sure to set the enabled property to either enabled or disabled when you create your program. If you want it to be enabled from the start, that is the default....otherwise set it to disabled in its properties view.
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
TextBox1.Enabled = CheckBox1.Checked
End Sub
Take a look at this tutorial below. After, look at the checkbox control's events and choose the most fitting one. The property you will be changing on the textbox is Enabled.
http://www.youtube.com/watch?v=4PbUryXqZ50
This works if you have a layer built in that you can send objects behind (therefore hide things). I use this as a way to make text boxes and other items appear and disappear depending on other selections.
Private Sub checkbox_Click()
If (checkbox = True) Then
ActiveSheet.Shapes("textbox").ZOrder msoSendToFront
ActiveSheet.Shapes("textbox").ZOrder msoSendToFront
Else
ActiveSheet.Shapes("textbox").ZOrder msoSendToBack
ActiveSheet.Shapes("textbox").ZOrder msoSendToBack
End If
End Sub
This worked for me:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TextBox1.Enabled = False
If Not TextBox1.Enabled Then
TextBox1.BackColor = Color.White
End If
End Sub
Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
TextBox1.Enabled = True
Else
TextBox1.Enabled = False
End If
End Sub
End Class