textbox control and regional settings

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
Locked
User avatar
ari0k.84
Posts: 3
Joined: Thu Dec 07, 2017 8:51 am

textbox control and regional settings

Post by ari0k.84 » Tue Nov 27, 2018 9:08 am

Hi guys,

I'm under Posh Studio up to date version (november 18).
I'm under Windows 7x64 up to date (all framework, visual,c,dot net etc)

I made a little form with some textbox / combobox and textbox validate ip (for IP / Mask / Gateway).
All stuff are working on my W7x64.

I exported it to an .exe file and try it on a W10 1803 x64 : up to date (november 2018 with last .dot net) and It doesn't work as expected because controls textbox IP are showing "," instead of "." (comma instead of dot).
My regional settings in the W10 config is "decimal" = "," and of course, it works if change it to "."

any help, somehting I missed ?
thanks in advance.

PS:I've for instance a premium support for your product until 30 of november, I'm wondering if we renew :) and if i open a ticket...

User avatar
jvierra
Posts: 13392
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: textbox control and regional settings

Post by jvierra » Tue Nov 27, 2018 9:32 am

Windows 10 is using the declared decimal separator. What you are seeing is the normal behavior or Windows.

User avatar
ari0k.84
Posts: 3
Joined: Thu Dec 07, 2017 8:51 am

Re: textbox control and regional settings

Post by ari0k.84 » Thu Nov 29, 2018 1:09 am

Ok I see. However, why the control textbox Ip isn't properly configure to test OS Version and replace "," by "." ?? Is there a way to do it by properties or something else ? or by the way, is it totally useless in W10 ? Why put this control if it's not properly coded for any OS version ? I don't understand...
Well, much questions uhhh, but i'm so surprised... You agree with the fact that we don't have to change the decimal separator in the OS to put a validating ip textbox in a program ?

User avatar
davidc
Posts: 5805
Joined: Thu Aug 18, 2011 4:56 am

Re: textbox control and regional settings

Post by davidc » Thu Nov 29, 2018 8:48 am

Try setting the culture of the MaskedTextBox:

$maskedtextboxIP.Culture = 'en-US'
David
SAPIEN Technologies, Inc.

User avatar
jvierra
Posts: 13392
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: textbox control and regional settings

Post by jvierra » Thu Nov 29, 2018 9:54 am

If a "textbox" then the control is not adding the commas or dots. It is in you code. If it is a RichTextBox then you must have set the separator to a comma somehow. If Windows is set to use a comma then this only effects numbers. An IP is not a number it is a string.

Without an example of your code there is no way to guess at what you are asking about. Please post a simple form showing the code that causes this to happen.

User avatar
ari0k.84
Posts: 3
Joined: Thu Dec 07, 2017 8:51 am

Re: textbox control and regional settings

Post by ari0k.84 » Mon Dec 03, 2018 4:03 am

Ok, first of all, thanks to you both for answering.
I'll attach two screenshots.

I tried $masquedIPtextbox.culture = 'en-us', same thing.

It's not a richtextbox, it's an integrated masquedtextboxip from Sapien.

When i open the form on my computer :> $textbox for ipaddress shows up with . . .
When i open on my w2008r2 or windows 10 :> $textbox for ipaddress shows up with , , ,

And of course, if you enter an ip and hit tab to change textbox, the validate function doesn't work, a red exclamation mark appears. The code is given by Sapien, the function is integrated, so I never touched it or made a mistake. Just using an integrated control & functions...

I modify Regional/Decimal settings to fit (On my own, that's not normal to do that), then it works (of course).

Here's the code from Sapien :

$maskedtextboxIP_Validating=[System.ComponentModel.CancelEventHandler]{
#Event Argument: $_ = [System.ComponentModel.CancelEventArgs]

$IP = $null
try
{
$IP = Get-IPAddressFromMaskedTextBox $this
}
catch
{
$errorprovider1.SetError($this, $_.Exception.Message)
}

$_.Cancel = $IP -eq $null
}

$maskedtextboxIP_Validated={
$errorprovider1.SetError($this, "")

}

function Get-IPAddressFromMaskedTextBox
{
[OutputType([System.Net.IPAddress])]
param(
[Parameter(Mandatory=$true)]
[ValidateNotNull()]
[System.Windows.Forms.MaskedTextBox]$MaskedTextbox)

try{
return [System.Net.IPAddress]::Parse($MaskedTextbox.Text.Replace(" ",""))#Remove Whitespaces
}
catch {
if($_.Exception.InnerException -ne $null)
{
throw $_.Exception.InnerException
}
else
{
throw $_.Exception
}
}

return $null
}
Attachments
w10.PNG
w10.PNG (811 Bytes) Viewed 348 times
w7.JPG
w7.JPG (8.9 KiB) Viewed 348 times

User avatar
jvierra
Posts: 13392
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: textbox control and regional settings

Post by jvierra » Mon Dec 03, 2018 6:45 am

Can you please post a PSF with an example that shows what is happening.

Please note that the top of the page states: "
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file. "

Posting code as text is not helpful.

You can attach your PSF using the "Full Editor" at the bottom of the editor.

From your pictures it certainly looks like you are using a numeric converter which will insert commas. An IP address is a string and not number.

User avatar
jvierra
Posts: 13392
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: textbox control and regional settings

Post by jvierra » Mon Dec 03, 2018 6:57 am

Now that we know it is not a TextBox control but is a MaskedTextbox control I can use it in a form in Windows 10. When I build a form and run it on W10 I see no issue like you are reporting.

Without a copy of your full PSF that shows this issue it is not really possible to see why this might be happening.

Locked