Changing font styles

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 10 years and 3 days 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
boyddt_co
Posts: 89
Last visit: Mon Sep 25, 2023 9:36 pm

Changing font styles

Post by boyddt_co »

Ok, batter up!

I have a form with multiple labels and on a click event I would like to set the font style to strikethrough / strikeout. Everything I've seen so far makes it seem as though this is a read-only value. Is there a way to do this?

This is what I'm trying but it isn't happy
PowerShell Code
Double-click the code block to select all.
$M1D1P1_Click={
	#TODO: Place custom script here
	If(	$M1D1P1BG.BackColor -eq "LimeGreen"){
		$M1D1P1.Font.style.Strikeout = $true
	}
	Else{
	$M1D1P1BG.BackColor = "LimeGreen"	
	}
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Changing font styles

Post by jvierra »

What control is it that you are trying to change this on?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Changing font styles

Post by jvierra »

Here is a hint t how this is done for a label control.
PowerShell Code
Double-click the code block to select all.
$label1_Click={
    $s=[System.Drawing.FontStyle]::Strikeout
    $f=New-Object System.Drawing.Font($label1.Font,$s)
    $label1.Font=$f
}
User avatar
boyddt_co
Posts: 89
Last visit: Mon Sep 25, 2023 9:36 pm

Re: Changing font styles

Post by boyddt_co »

It is for a label and I'll try your suggestion.

Thanx for the help
User avatar
boyddt_co
Posts: 89
Last visit: Mon Sep 25, 2023 9:36 pm

Re: Changing font styles

Post by boyddt_co »

You are the man, it worked like a champ!!!!

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

Re: Changing font styles

Post by jvierra »

So the lesson is.... To edit a font...copy it to a new font and edit the new font. Reassign to control.


Good luck.
This topic is 10 years and 3 days 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