February 26, 2018 at 3:32 pm #94653
I'm trying to make form in Powershell to prompt idle users with a pending logoff, that can be used across multiple IT departments and can be changed to meet their needs. Specifically, they can change the presented logoff message by changing a registry value.
The problem I'm having is with "Location" for the different pieces of the form. Currently we are changing the location as below,
$btnOk.Location = new-object System.Drawing.Size(170, 175)
This works fine for our test message text, however if a different department wants to customize the message, or if they want to make the message longer it would mess up the formatting.
I'm wondering if there is any way to specify alignment on the text, so I can specify say "Y=170,X=Center" so that the text is at a specific height, but the message will always be centered on the form.
Kind of a powershell noob. Thanks for anyone who can help.
February 26, 2018 at 3:38 pm #94654
This really isn't a PowerShell question at all, so your noob status wouldn't have mattered [grin]. This is a pure .NET Framework question.
This is a problem UI designers deal with all the time when planning for app localization – phrases in German, for example, often wind up being much longer than their English equivalent, and you have to plan for that space. You generally do so by making your label as large as needed for the maximum message size, and then – as you suggest – applying an alignment to keep things looking pretty. So you'd make the label BIGGER, and then apply a centering alignment to the text itself.
It's more usual to display messages in a label, though, not as the text of a button. Bear in mind that Windows treats buttons in a specific way, such as how it deals with them for people who have visual impairment. Loading a button down with text breaks the OS standards, and creates an inconsistent user experience.
There's not a specific way to "align" a control to the center of its container, though. Not exactly. The practice would be to make a label stretch over the entire area, and then let the label center its text within the label's boundaries. That's literally what labels are for.
There are some other tricks you can do with pinning a control to be a certain number of pixels from the side of its container, but that's more about dealing with variable-size windows, and not a means of accomplishing what you're after.
You might also consider asking for suggestions someplace like Stack Overflow, where you get more legit developers working in WinForms and WPF and whatnot. Again, the fact that you're coding this in PowerShell is less a thing than the actual technology you're working with, which is very much, in this case, a developer thing.
You must be logged in to reply to this topic.