How do you use . as Tab
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
How do you use . as Tab
I am creating a form that people will be entering IP addresses into. To make it more simple for them - and harder for me, apparently - I need to give the form the ability to tab to the next box when a person presses the "." key on the numpad. Is this possible?
Re: How do you use . as Tab
To do this you have to handle all keyboard characters in the controls of interest. Pass all characters and react when you receive a dot.
PowerShell Code
Double-click the code block to select all.$textbox1_KeyPress=[System.Windows.Forms.KeyPressEventHandler]{ #Event Argument: $_ = [System.Windows.Forms.KeyPressEventArgs] #TODO: Place custom script here if($_.KeyChar -eq '.'){ #[System.Windows.Forms.MessageBox]::Show('trapped') $textbox2.Focus() } }
Re: How do you use . as Tab
So, using the code you have there, if I have the first box called $Octet1 and the next in line is called $Octet2, would it look like this?
I assume that I would add this code to the main function section of the script and then add some sort of event handler to the $Octet1 section of the form, correct?
Code: Select all
$Octet1_KeyPress=[System.Windows.Forms.KeyPressEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.KeyPressEventArgs]
#TODO: Place custom script here
if($_.KeyChar -eq '.'){
#[System.Windows.Forms.MessageBox]::Show('trapped')
$Octet2.Focus()
}
}
Re: How do you use . as Tab
Just crate the event handler and paste the code into it. The event handler names will follow the object.
I created the $textbox1 event handler in the designer. I then added the reference to the $textbox2 object.
It seems pretty obvious to me.
I created the $textbox1 event handler in the designer. I then added the reference to the $textbox2 object.
It seems pretty obvious to me.
Re: How do you use . as Tab
Okay, you rock. It's working, but I have one small issue. When you press the . key, it actually types the . before it tabs to the next section. How do I tell it to remove the actual .?
Re: How do you use . as Tab
Set the following in the event when you detect a period:
PowerShell Code
Double-click the code block to select all.$_.Handled = $true
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: How do you use . as Tab
Thank you both so much for your help. It's working great! I am new here, so forgive me for asking stupid questions, please!!
Re: How do you use . as Tab
Not a stupid question.
Certain techniques like key handling are not obvious. Unfortunately there is no PowerShell book on Windows Forms development.
Try using MSDN and search for the control class.
Certain techniques like key handling are not obvious. Unfortunately there is no PowerShell book on Windows Forms development.
Try using MSDN and search for the control class.