ownerDrawText - checkboxes are messed

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
ALIENQuake
Posts: 66
Joined: Sun Mar 03, 2013 12:45 pm

ownerDrawText - checkboxes are messed

Post by ALIENQuake »

Hi,

I was forced to use ownerDrawText because I need to set the background color of the treeview node when the treeview is not focused.

But there is another problem when I enable this option:

Image

You can see that the right-line of the checkbox rectangle is not visible (or is covered by the surface of node text?)

Is there a way to fix this?

jvierra
Posts: 14583
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Been upvoted: 1 time
Contact:

Re: ownerDrawText - checkboxes are messed

Post by jvierra »

Why not just set the nodes color?

jvierra
Posts: 14583
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Been upvoted: 1 time
Contact:

Re: ownerDrawText - checkboxes are messed

Post by jvierra »

Just do this:

Code: Select all

$treeview1_DrawNode=[System.Windows.Forms.DrawTreeNodeEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.DrawTreeNodeEventArgs]
	$_.Node.BackColor = 'Aqua'
}

User avatar
ALIENQuake
Posts: 66
Joined: Sun Mar 03, 2013 12:45 pm

Re: ownerDrawText - checkboxes are messed

Post by ALIENQuake »

Well, it won't work because when the treeview is not focused, the node will have a 'grey' color, regardless of BackColor value.

Example of the same problem: https://stackoverflow.com/questions/211 ... ot-focused

I want to use the solution provided by stackoverflow but as I said, there is yet another problem with messed checkboxes.

jvierra
Posts: 14583
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Been upvoted: 1 time
Contact:

Re: ownerDrawText - checkboxes are messed

Post by jvierra »

Unfortunately there is no Paint event for nodes. That is where you would reset any node.
Also there is no way to understand what it is you are seeing without the code.

Locked