Hiya!
This script works perfectly fine the way it’s written for one button.
I’ve tried quite a few times to get another button to change the foreground color of a label.
It appears I write over the settings file ( obviously ) but I cannot seem to find a way to append the two actions.
Two buttons
One changes background ( from earlier )
One changes a label
Can I use the same settings file or do I have to make a new one?
Do I need another colordialog?
I know $colors holds the info I need to write to the file
ColorDialog
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.
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.
Re: ColorDialog
You have to design the structure first and make it global to the form. If the form runs for the first time the file will not exist o you will have to detect that and create it or supply a default file. This is where we get into the arena of program design. You will have to design a file structure that allows you to reload the file. There are many approaches to this and it does require some serious thinking and learning the first time.
I use an XML file most of the time as I cn easily create a structure that can be easily automated based on the choice of file entries. A function can be designed that reads through the file and sets the colors and, when closing the form I can walk the file and assign the current changes. I also use a context menu item that is added when the context menu is opened if there is a setting with a saved item.
Another method is to capture the mouse and highlight all controls that can be customized then, on a click on the control pop up the color dialog and setting code. This is usually initiated by a main menu subitem on the "Tools" menu.
There are many ways to approach this that allow for simple coding. Experience with code design is necessary and this is one way to get that experience. The final design is driven by requirements for the functionality.
Code: Select all
$settingsFile = Join-Path $PWD 'settings.clixml'
$tbxform_Load={
if(Test-Path $settingsFile){
# load existing settings
$script:colors = Import-Clixml
$tbxForm.BackColor = [System.Drawing.Color]::FromArgb($colors.Form.BackColor)
$textboxComputer.BackColor = [System.Drawing.Color]::FromArgb($colors.textboxComputer.BackColor)
}else{
# create new settings file from current values
$colors = @{
tbxForm = @{
BackColor = $tbxForm.BackColor.ToArgb()
}
textboxComputer = {
BackColor = $textboxComputer.BackColor.ToArgb()
}
}
$colors | Export-Clixml $settingsFile
}
}
Another method is to capture the mouse and highlight all controls that can be customized then, on a click on the control pop up the color dialog and setting code. This is usually initiated by a main menu subitem on the "Tools" menu.
There are many ways to approach this that allow for simple coding. Experience with code design is necessary and this is one way to get that experience. The final design is driven by requirements for the functionality.
Re: ColorDialog
Sorry for the delay, I just got back from vacation. This gives me a lot to chew on in learning. Thank you for the very informative response.