默认情况下,此example 用于文本的中间居中对齐。您使用的格式 (NoPrefix|WordBreak|TextBoxControl|EndEllipsis) 默认为左对齐。因此,要修复辉光剪辑,您应该扩展辉光边界。
以下是更正后的示例:
public void DrawTextOnGlass(IntPtr hwnd, String text, Font font, Rectangle bounds, int glowSize){
//...
RECT glowRect = new RECT();
RECT textRect = new RECT();
glowRect.left = bounds.Left - glowSize;
glowRect.right = bounds.Right + glowSize;
glowRect.top = bounds.Top - glowSize;
glowRect.bottom = bounds.Bottom + glowSize;
textRect.left = glowSize;
textRect.top = glowSize;
textRect.right = glowRect.right - glowRect.left;
textRect.bottom = glowRect.bottom - glowRect.top;
//...
int uFormat = (int)(TextFormatFlags.NoPrefix
| TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.EndEllipsis);
//...
DrawThemeTextEx(renderer.Handle, Memdc, 0, 0, text, -1, uFormat, ref textRect, ref dttOpts);
BitBlt(destdc, glowRect.left, glowRect.top,
glowRect.right - glowRect.left,
glowRect.bottom - glowRect.top,
Memdc, 0, 0, SRCCOPY);
//...
}