使用this complete example我可以在Aero Glass上绘制文字。渲染非常精细,但存在视觉问题:光晕在文本对齐侧被剪裁。
仅供参考,文本格式定义如下:
Dim uFormat As Integer = TextFormatFlags.NoPrefix Or TextFormatFlags.WordBreak Or _
TextFormatFlags.TextBoxControl Or TextFormatFlags.EndEllipsis
可以修复吗?
答案 0 :(得分:4)
默认情况下,此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);
//...
}