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.
This topic is 5 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ari0k.84
Posts: 3
Last visit: Mon Jun 20, 2022 8:06 am

textbox control and regional settings

Post by ari0k.84 »

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...
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: textbox control and regional settings

Post by jvierra »

Windows 10 is using the declared decimal separator. What you are seeing is the normal behavior or Windows.
User avatar
ari0k.84
Posts: 3
Last visit: Mon Jun 20, 2022 8:06 am

Re: textbox control and regional settings

Post by ari0k.84 »

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: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: textbox control and regional settings

Post by davidc »

Try setting the culture of the MaskedTextBox:

$maskedtextboxIP.Culture = 'en-US'
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: textbox control and regional settings

Post by jvierra »

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
Last visit: Mon Jun 20, 2022 8:06 am

Re: textbox control and regional settings

Post by ari0k.84 »

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 2084 times
w7.JPG
w7.JPG (8.9 KiB) Viewed 2084 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: textbox control and regional settings

Post by jvierra »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: textbox control and regional settings

Post by jvierra »

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.
This topic is 5 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked