Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the TreeView respect the DoubleBuffered property #7403

Merged
merged 6 commits into from Jul 27, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/System.Windows.Forms/src/System/Windows/Forms/TreeView.cs
Expand Up @@ -436,7 +436,14 @@ protected override Size DefaultSize
protected override bool DoubleBuffered
{
get => base.DoubleBuffered;
set => base.DoubleBuffered = value;
set
{
if (DoubleBuffered != value)
{
base.DoubleBuffered = value;
UpdateTreeViewExtendedStyles();
0xC0000054 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

/// <summary>
Expand Down Expand Up @@ -1959,6 +1966,9 @@ protected override void OnHandleCreated(EventArgs e)

base.OnHandleCreated(e);

// The TreeView extended styles are independent of the window extended styles.
UpdateTreeViewExtendedStyles();

int version = (int)User32.SendMessageW(this, (User32.WM)CCM.GETVERSION);
if (version < 5)
{
Expand Down Expand Up @@ -2065,6 +2075,32 @@ protected override void OnHandleCreated(EventArgs e)
SelectedNode = savedSelectedNode;
}

private void UpdateTreeViewExtendedStyles()
0xC0000054 marked this conversation as resolved.
Show resolved Hide resolved
{
if (!IsHandleCreated)
dreddy-work marked this conversation as resolved.
Show resolved Hide resolved
{
return;
}

TVS_EX extendedStyles = (TVS_EX)User32.SendMessageW(this, (User32.WM)TVM.GETEXTENDEDSTYLE);

SetExtendedStyle(ref extendedStyles, TVS_EX.DOUBLEBUFFER, DoubleBuffered);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the default extended styles for TreeView here? why do we have to negate when DoubleBuffered is not enabled? It would default back to current behavior. Did you notice any change in behavior here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default extended styles appeared to be 0 (None) when I was debugging.

But now that I think about it the code is incorrect and would not clear the style anyway, the first SendMessage parameter is a mask.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the GETEXTENDEDSTYLE call and the negation code.
Negating the extended styles would have been a regression for callers that set the values themselves.


User32.SendMessageW(this, (User32.WM)TVM.SETEXTENDEDSTYLE, (int)extendedStyles, (int)extendedStyles);

static void SetExtendedStyle(ref TVS_EX extendedStyles, TVS_EX mask, bool value)
{
if (value)
{
extendedStyles |= mask;
}
else
{
extendedStyles &= ~mask;
}
}
}

// Replace the native control's ImageList with our current stateImageList
// set the value of internalStateImageList to the new list
private void UpdateNativeStateImageList()
Expand Down