I'm new hear, but not new in Powershell.
I just started to try a new way with System.Windows.Forms
Now my problem.
Add-Type -AssemblyName System.Windows.Forms $Form = New-Object system.Windows.Forms.Form $Form.ClientSize = '492,280' $Form.text = "Simple Management" $Form.TopMost = $true $Label1 = New-Object system.Windows.Forms.Label $Label1.text = "Computer name" $Label1.AutoSize = $true $Label1.width = 25 $Label1.height = 10 $Label1.location = New-Object System.Drawing.Point(29,29) $Label1.Font = 'Microsoft Sans Serif,10' $Label1.Name = "aaaa" $Label1.AccessibleName = "bbbb" $Form.controls.AddRange(@($Label1)) [void]$Form.ShowDialog()
I've tried a lot, and searched many.
Has someone an idea how to manage this?
You don't have to do this from scratch.
Yet, doing from scratch is a good learning experience.
You do not have anything on your form called 'Name'. What you have is a label element called '$Label1' that has a property called Name.
What do you want to do with the label element, that you've already assigned a property settings and values?
You'd normally put in another form element next to the label element that is associated with it that user will / could interact with. Otherwise you just are changing it's property settings, color, font family, etc... User don't interact with labels under normal circumstances. They are just there to give the user some indication of what is or could be enter in the input element next to it.
Yet, remember, we are here to help you with code that is either not working or that you are having other issue with. Not really GUI design stuff. There are lots of sites / resources to educate you on GUI design in PowerShell using WPF/XAML/Web, etc... Heck there are tons of YouTube videos that walk you through all that as well …
and other videos on MS Channel9.
Thanks for your reply.
The whole program has a configfile where the devices where listed.
The Variable will be each time the same during a Foreach Loop.
The Label will be the Status Display. A background Job will update the status every x seconds or after a action on a device.
Thats why i need to access the objects over a dynamic way.
I will take a look at your links. Thanks
OK, then you are only acting on this ...
$Label1.text = "Computer name"
… on every pass.
Not really these...
$Label1.Name = "aaaa" $Label1.AccessibleName = "bbbb"
… since these are not something the user will ever see. These are just elements, that you can get, but you really should not be dynamically changing them. I cannot think of a good reason why you would.
If these …
btnON, btnOFF, btnRESET, lblSTATUS
… never change, then I would just set them once and move on. Updating a status element makes sense.
You must be logged in to reply to this topic.