Bold text if checkbox = checked

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 8 years and 5 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
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Bold text if checkbox = checked

Post by localpct »

Got it!
PowerShell Code
Double-click the code block to select all.
$formPCHealth_Load={
	
	
}




$button1_Click= {
	#TODO: Place custom script here
	if (Test-Connection pc -Count 1 -Quiet)
	{
		$freespaceonc.ImageIndex = 0
		$displayinfo.Text = '1' | Out-String
		$Font = New-Object System.Drawing.Font("Tahoma", 9, [System.Drawing.FontStyle]::Bold)
		$freespaceonC.Font = $Font
	}
	else
	{
		$freespaceonc.ImageIndex = 1
	}
	
	if (Test-Connection pc -Count 1 -Quiet)
	{
		$freespaceonD.ImageIndex = 1
		$displayinfo.Text += '2' | Out-String
	}
	else
	{
		$freespaceonD.ImageIndex = 0
	}
	if (Test-Connection pc -Count 1 -Quiet)
	{
		$freespaceonE.ImageIndex = 1
		$displayinfo.Text += '3' | Out-String
	}
	else
	{
		$freespaceonE.ImageIndex = 0
	}
	
	if (Test-Connection pc -Count 1 -Quiet)
	{
		$freespaceonF.ImageIndex = 0
		$displayinfo.Text += '4' | Out-String
	}
	else
	{
		$freespaceonF.ImageIndex = 1
	}
	
	if ($freespaceonD.ImageIndex = 1)
	{ $displayinfo.Text += "Yay, I'm not dumb" }
	
}
$freespaceonC_Click={
	#TODO: Place custom script here

}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Bold text if checkbox = checked

Post by jvierra »

This:
$displayinfo.Text = '1' | Out-String

Doesn't do anything. It is a nonsense construct. YOu only need this:
$displayinfo.Text=1
e.
What us will doo is add extra blank lines which can make the display unusable.

The code posted has the same bad lines repeated over and over again. Why? Look closely at the code. It does the same test repeatedly. Only the last one will work.

This is the aggregate effect:
PowerShell Code
Double-click the code block to select all.
$button1_Click = {
	if (Test-Connection pc -Count 1 -Quiet) {
		$freespaceonc.ImageIndex = 0
		$displayinfo.Lines += '1'
		$freespaceonC.Font = New-Object System.Drawing.Font("Tahoma", 9, [System.Drawing.FontStyle]::Bold)
		$freespaceonD.ImageIndex = 1
		$displayinfo.Lines += '2'
		$freespaceonE.ImageIndex = 1
		$displayinfo.Lines += '3'
		$freespaceonF.ImageIndex = 0
		$displayinfo.Lines += '4'
	} else {
		$freespaceonc.ImageIndex = 1
		$freespaceonD.ImageIndex = 0
		$freespaceonE.ImageIndex = 0
		$freespaceonF.ImageIndex = 1
		$freespaceonE.ImageIndex = 0
	}
		
	if ($freespaceonD.ImageIndex = 1) { $displayinfo.Lines += "Yay, I'm not dumb" }
	
}
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Bold text if checkbox = checked

Post by localpct »

Thanks. I do have to say you answer a lot on here and you also ask the same question"why?"

You'd think the answer is always going to be the same "because we don't know"

Not everyone has the time or learns the same and so we need some visual help or a little guidance. Ease up a bit slim ;)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Bold text if checkbox = checked

Post by jvierra »

I am trying to help you understand how to simplify the code. The way you have written it causes it to not work as you may want it to.

Think carefully about the steps you need too preform. Try to see how each one can conflict with another. Filter logic can be tricky and is not purely additive.

I recommend starting with one of the many good books or tutorials available for PowerShell.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Bold text if checkbox = checked

Post by localpct »

I really do appreciate all the help you provide to the numerous of people who use this site

Have you ever thought about making your own tutorial or maybe a How To blog? I know Sapien provides some good tutorials but I think they're all geared towards people who already have a good understanding of scripting in general. Again, it's all appreciated.

I'm still working on this application. I will work on it for the next week before I post back to this forum.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Bold text if checkbox = checked

Post by jvierra »

Just keep working at it and keep reading the blogs. At some point a light will goon and much will become clear.

Don't try too hard. Work in little pieces. Over working wears out your brains ability to catch onto new ideas. Do what is easy and fun and progress naturally.

There. My blog for the day. Good luck and have fun.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Bold text if checkbox = checked

Post by dan.potter »

localpct wrote:I really do appreciate all the help you provide to the numerous of people who use this site

Have you ever thought about making your own tutorial or maybe a How To blog? I know Sapien provides some good tutorials but I think they're all geared towards people who already have a good understanding of scripting in general. Again, it's all appreciated.

I'm still working on this application. I will work on it for the next week before I post back to this forum.

He has a blog :)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Bold text if checkbox = checked

Post by jvierra »

But it has been mostly for more advance and corner case issues,

http://tech-comments.blogspot.com/

There are so many great blogs. I try not to duplicate what others have done well.
This topic is 8 years and 5 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