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

Changing font styles

Post by boyddt_co » Tue Apr 15, 2014 8:45 pm

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"	
	}
}

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Changing font styles

Post by jvierra » Tue Apr 15, 2014 10:53 pm

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

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Changing font styles

Post by jvierra » Tue Apr 15, 2014 11:13 pm

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

Re: Changing font styles

Post by boyddt_co » Tue Apr 15, 2014 11:14 pm

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

Thanx for the help

User avatar
boyddt_co
Posts: 75
Joined: Mon Dec 17, 2007 5:50 am

Re: Changing font styles

Post by boyddt_co » Tue Apr 15, 2014 11:22 pm

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

Thanx.

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Changing font styles

Post by jvierra » Tue Apr 15, 2014 11:37 pm

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