Close Form VBA By Key - vb.net

I'm looking for a routine that allows me to pick up a key combination such as Ctrl + L to allow me to close a form, all written in VB to someone've already shown how to manage?

This is not a very good question. You're asking users to do the coding for you, not showing an error/attempt that you need work with.
Please learn how to properly ask stackoverflow questions. Please refer to How To Ask
But, to answer:
You're looking for the key down event.
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Control & Keys.L Then
Form1.Close()
End If
End Sub

Related

Prevent the introduction of similar characters vb.net

Is it possible to prevent entering characters that are already in the textbox?
like if I wrote in textbox
abcd
Then it is not allowed to write the same letters in it,
I searched and tried but could not find a way
All are about stopping letter gouging
It's pretty simple, just use the following code:
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
e.Handled = TextBox1.Text.Contains(e.KeyChar)
End Sub
It'll help preventing typing the existing text(s) containing in a TextBox.
Hope it helps you!

Visual Basic GUI Input Validation

I took an entry level computer programming class this past term and I'm having problems with my final project. I have to design a program in visual basic GUI that asks the player to accurately guess a number between 1-100 within a limited number of guesses.
My first form asks the user to set the number of guesses allowed. It has one textbox and an "enter" button, among other buttons that I've gotten to work.
I'm trying to get code to work that will validate the input on the guesses allowed. Specifically, I want a message box to pop up if the player enters letters or special characters instead of numbers, or enters a number less than zero, or greater than twenty. Here's what I have:
Public Class Noofguesses
Shared maxguesscnt As Integer
Private Sub Numberofguesses_TextChanged(sender As Object, e As EventArgs) Handles Numberofguesses.TextChanged
End Sub
Private Sub Quit_Click(sender As Object, e As EventArgs) Handles Quit.Click
End
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Form3.Show()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Val(Numberofguesses) > 20 Then MsgBox("Number of Guesses Cannot Exceed 20")
If Val(Numberofguesses) < 0 Then MsgBox("Number of Guesses Must Be Greater Than 0")
If Not IsNumeric(Numberofguesses) Then MsgBox("Entry Cannot be Letters or Characters")
Me.Close()
Form2.Show()
End Sub
End Class
What am I doing wrong? Please let me know.
Thanks
I would generally suggest using a NumericUpDown rather than a TextBox, in which case no validation is required. As this is an assignment though, I'm guessing that validating a TextBox is a requirement. In that case, you should use Integer.TryParse to validate a String, i.e. the Text of the TextBox and convert it if it is valid. You can then test the converted value to make sure that it isn't less than zero, etc. I'm not going to write the code for you, given that this is homework, but that should be enough for you to do it yourself or, if you feel you must, find examples online.

VB.net SendKeys to send keys combined not using "ALT" or "CTRL", like "{INS}(S)"

I need to send the keystroke combination INSERT + S keys simultaneously but it seems that VB only leaves use key combinations with ALT, CTRL and SHIFT.
Is there any way to do it?
I've tried:
{INS}(S)
{INS}S
and many others, but this does not work.
Thanks a lot.
It does. See:
https://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
Had you tried "{INS}(S)" ?
UPDATE
I did the following test:
Private Sub TextBox1_Click(sender As Object, e As EventArgs) Handles TextBox1.Click
SendKeys.Send("{Ins}S")
End Sub
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
MsgBox(e.KeyCode)
End Sub
Look, I received in the KeyDown event 2 codes: the INS and the "S"
The problem is about the KeyDown event will file TWO TIMES, I mean, you cannot get the INS-S code with ONE reading.
So, you must consider have a FRIEND/PUBLIC variable to receive both codes and only after this, make the critic about these.
Good luck

Menu Strip Control "Window"

I am working on a project and am just stymied by this. It should be really straight forward. I have included the code so you can see the other Menu Strip Items.
The user has the ability to open as many "Child" forms into the mdiParent form. I would like the "Window" function on the menu strip to populate with the Bank Name found on the Child form so if a user had 10 bank forms open, they could find a specific form by clicking Window and seeing the bank name (the name of the text field which I would like to pull is Bank.lblbank.text) This functionality was found in the 2007 and older versions of many of the Microsoft Suite products.
If I hadn't seen my professor do this in class, I would think it was a bit of proprietary Microsoft Office coding that us mere mortals cannot access. Unfortunately, he whipped it out and I didn't get it captured.
Obviously, I am not asking the right questions on the search engines because I cannot find a clear answer. Does anyone have any advice? This functionality isn't necessary but a little something I want to add. I've worked on this way too long and just want a little bit of success.
Let me know if a zip copy of the project or screen prints would be helpful. I'm happy to send them your way.
Appreciate everyone looking at this post and their feedback. Thank you for your time!
Lauren
Public Class Loan_Evaluator
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub NewLoanToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NewLoanToolStripMenuItem.Click
Dim NewBank As New Bank
NewBank.MdiParent = Me
NewBank.Show()
End Sub
Private Sub VerticalToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles VerticalToolStripMenuItem.Click
Me.LayoutMdi(MdiLayout.TileVertical)
End Sub
Private Sub CascadeToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CascadeToolStripMenuItem.Click
Me.LayoutMdi(MdiLayout.Cascade)
End Sub
Private Sub HorizontalToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles HorizontalToolStripMenuItem.Click
Me.LayoutMdi(MdiLayout.TileHorizontal)
End Sub
Private Sub WindowToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles WindowToolStripMenuItem.Click
End Sub
End Class
Select the main MenuStrip control, not the ToolStripMenuItem. So you'd click on MenuStrip1, not WindowToolStripMenuItem, for example. Now change the MdiWindowListItem() property to "Window" (or whatever menu item you want to be populated with open MdiChildren). Done.

How to update value in combo box using combo box text?

I have a very simple question that i can't seem to find the answer, i have looked up and down in google, msdn with no luck...
it's really simple yet i can't seem to wrap my mind around it.
here goes:
If i'm using simple Drop down style combo box(the one that looks like a listbox with textbox attached on top of the cbobx control) when i want to update one of the value in it, once i start typing in the textbox the selection inside the combo box is gone. Thus i can't update the value inside the combo box.
i know i can use a regular text box to do this, but i'd really like to make this work or i would really loose sleep over this.
Thanks in advance for all your help.
Ray
It doesnt seem very intuative editing the selection in a combobox, but the following should do the trick:
Private cbindex As Integer
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
cbindex = ComboBox1.SelectedIndex
End Sub
Private Sub ComboBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.LostFocus
ComboBox1.Items(cbindex) = ComboBox1.Text
End Sub