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.
This topic is 4 years and 1 day 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
ALIENQuake
Posts: 112
Last visit: Mon Jan 29, 2024 7:35 am
Has voted: 4 times

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: ownerDrawText - checkboxes are messed

Post by jvierra »

Why not just set the nodes color?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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: 112
Last visit: Mon Jan 29, 2024 7:35 am
Has voted: 4 times

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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.
This topic is 4 years and 1 day 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