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.
Locked
User avatar
boyddt_co
Posts: 76
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Mon Dec 17, 2007 5:50 am

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: 14364
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Changing font styles

Post by jvierra »

What control is it that you are trying to change this on?

jvierra
Posts: 14364
Joined: Tue May 22, 2007 9:57 am
Contact:

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: 76
Joined: Mon Dec 17, 2007 5:50 am

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: 76
Joined: Mon Dec 17, 2007 5:50 am

Re: Changing font styles

Post by boyddt_co »

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

Thanx.

jvierra
Posts: 14364
Joined: Tue May 22, 2007 9:57 am
Contact:

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.

Locked