Page 1 of 1

Powershell Studio Title text manipulation

Posted: Thu Jan 23, 2020 1:16 pm
by owinsloe
Would it be possible to add a table to the text title so you could have a left align cell followed by a right aligned cell?

I would like to specify left aligned product and version on the left and Company (owner) copyright details right aligned on teh right.

You can not really do this by padding with spaces and a resize of the form does not reposition.

Thanks

Re: Powershell Studio Title text manipulation

Posted: Thu Jan 23, 2020 1:48 pm
by brittneyr
I'm not quite sure what you are asking for, can you please elaborate?

Re: Powershell Studio Title text manipulation

Posted: Sun Jan 26, 2020 1:04 pm
by owinsloe
Hmmm, after re-reading I can see that I did not explain myself very well (seemed to sound right in my head at the time).

If you look at the image you can see the text position on the Form title bar. I want to be able to separate the two different types of strings and have them remain where they are if the form is resized. I had tried padding with spaces but its not very nice.

'cnwiniadmin v1.0.3.4' left-aligned
'(c) Jade Software Corporation' right-aligned

Thanks
form.jpg
form.jpg (48.92 KiB) Viewed 15317 times

Re: Powershell Studio Title text manipulation

Posted: Sun Jan 26, 2020 1:05 pm
by owinsloe
Oh, I should explain that I used ms-paint to move the strings into the desired positions to explain what I would like. This is not an example of what the form current has (all text left-aligned)

Re: Powershell Studio Title text manipulation

Posted: Sun Jan 26, 2020 1:55 pm
by Alexander Riedel
Hmm, yeah, I can see how you may be tempted to do that. The short answer is, no, there is no such control or style. For a long winded explanation as to why not, please read on :D

There is a thing called CUA (Common User Access) (see https://en.wikipedia.org/wiki/IBM_Common_User_Access) which defined a long time a go where what goes and what certain keys do in an application.
The overall goal was to make all graphical applications adhere to the same standards, so that once user was trained in one application, the knowledge gained would transfer to all other applications and thereby reduce the amount of training required. Which is why *most* windows applications look very similar and even Linux and Apple MacOS apps look somewhat familiar.
The window's caption, which is the area you want to customize, is meant to be descriptive as to the task the window represents.
So if you click on an "open..." item, the following dialog or form should be titled "Open".
The application's main window by convention contains the title of the application, centered. If an app opens documents, single or multiple, it generally either uses a prefix or a post-fix placement for the title.
My document - Very Cool App or Very Cool App - My document
This allows the user to easily comprehend which application is active and what document, if any is open. The main window's caption is also used by the Windows task bar to display information when hovering.
So in general, and that is just my private opinion, I would rather stick to the standard and not mess with that.

If you really want to do that, there is a Windows message, WM_NCPAINT (https://docs.microsoft.com/en-us/window ... wm-ncpaint) which paints all non-client areas of a window.
It is quite a complex undertaking and I think not something you want to tackle in powershell. But you could most certainly paint the actual caption left justified rather than centered and paint additional
supplemental information wherever you like it, without disturbing the actual caption data itself.
This is however not an job for the faint of heart, (just read this https://social.msdn.microsoft.com/Forum ... evelopment) as it involves doing what Windows normally does for you and, usually, undocumented trickery.
But if you want to do that, I wish you the best of luck :D

Re: Powershell Studio Title text manipulation

Posted: Sun Jan 26, 2020 2:01 pm
by owinsloe
Alexander,
I really appreciate the time you have taken to outline this. I think I will stick to the way it currently works. Thanks

Re: Powershell Studio Title text manipulation

Posted: Mon Jan 27, 2020 3:21 pm
by owinsloe
Okay, I may be chasing a lost cause but after a little reading I thought I could achieve my deired result approaching this in a different direction. However it does not work and I think I'm comparing apples with pears but can not see where it's going wrong..

The code
$Product = 'cnwiniadmin'
$script:version = '1.0.0.0'

$Font = [System.Drawing.SystemFonts]::CaptionFont
$TotalWidth = ($MainForm.clientsize).width

$Space = ' '
$SpaceSize = ([System.Windows.Forms.TextRenderer]::MeasureText($Space, $font)).width
$SpacePercent = ($SpaceSize * 100)/$TotalWidth

$ProductText = $Product + ' v' + $script:version
$ProductSize = ([System.Windows.Forms.TextRenderer]::MeasureText($ProductText, $font)).width
$ProductPercent = ($ProductSize * 100)/$TotalWidth

$CompanyText = '© ' + (Get-Date -Format 'yyyy') + ' Jade Software Corporation'
$CompanySize = ([System.Windows.Forms.TextRenderer]::MeasureText($CompanyText, $font)).width
$CompanyPercent = ($CompanySize * 100)/$TotalWidth

#Determine space padding
$i=0
do
{
$i++
$SpaceSizeTotal += $SpacePercent
}
until ($SpaceSizeTotal -ge (100 - ($ProductPercent + $CompanyPercent)) )

$Title = $ProductText.PadRight($i,' ') + $CompanyText
$MainForm.text = $Title

The result
form.jpg
form.jpg (35.25 KiB) Viewed 15284 times

Re: Powershell Studio Title text manipulation

Posted: Mon Jan 27, 2020 5:04 pm
by owinsloe
I know this is a wish list forum but have added to this to show the history behind the query