2011-11-06 72 views
2

使用this complete example我可以在Aero Glass上繪製文字。渲染非常好,但有一個視覺問題:發光被裁剪在文本對齊方面。DrawThemeTextEx和修剪發光

enter image description here

僅供參考,文本格式的定義如下:

Dim uFormat As Integer = TextFormatFlags.NoPrefix Or TextFormatFlags.WordBreak Or _ 
      TextFormatFlags.TextBoxControl Or TextFormatFlags.EndEllipsis 

這個問題能解決嗎?

回答

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); 
//...  
} 
+0

結果是完美的:) – Velcro