2

Recently I discovered how to get Aero Blur to work in borderless Forms across Windows Vista, 7 and 10. I am achieving this using the following function:

private void UpdateAeroBlur() {
    if (!SupportsAeroBlur) //do not do anything if XP or older
        return;
    else if (useSetWindowComposition) { //true if SetWindowCompositionAttribute function
                                        //exists in user32.dll
        AccentPolicy accent = new AccentPolicy();
        accent.AccentState = enableAeroBlur ? AccentState.ENABLE_BLURBEHIND : AccentState.DISABLED;
        WindowCompositionAttributeData data = new WindowCompositionAttributeData();
        data.Attribute = DwmWindowAttribute.ACCENT_POLICY;
        data.SizeOfData = AccentPolicy.Size;
        unsafe
        {
            data.Data = new IntPtr(&accent);
        }
        NativeApi.SetWindowCompositionAttribute(Handle, ref data);
    }
    DWM_BLURBEHIND style = new DWM_BLURBEHIND() {
        dwFlags = DWM_BB.Enable,
        fEnable = true
    };
    NativeApi.DwmEnableBlurBehindWindow(Handle, ref style);
}

And it manages to make the border of my custom Form translucent! However I am getting an annoying side-effect.

Look at this:

Aero Blur Demo

The text in the TextBox controls has become transparent, while the text on the buttons which are drawn using anti-aliased text GDI+ are not transparent.

I tried calling SetLayeredWindowAttributes and tried LWA_ALPHA with bAlpha = 255 and then tried LWA_COLORKEY with a COLORREF zeroed out, but the issue remained.

How do I make the text in TextBox controls opaque while leaving the border translucent?

MathuSum Mut
  • 2,765
  • 3
  • 27
  • 59
  • 1
    You just can't. TextBox is an old horse in the toolbox, it uses the GDI text rendering engine. The MSDN article warns about this: "Some Windows Graphics Device Interface (GDI) operations do not preserve alpha values, so care must be taken when presenting child windows because the alpha values they contribute are unpredictable." You have to use DwmExtendFrameIntoClientArea() instead to limit the effect. – Hans Passant Oct 16 '17 at 16:36
  • The thing is that I am using `DwmExtendFrameIntoClientArea` with MARGINS set to {0, 0, 0, 1}. I guess I'll have to re-implement textbox drawing myself. – MathuSum Mut Oct 16 '17 at 16:38

0 Answers0