2014-10-12 123 views
1

我有一個函數「listView1_DrawSubItem」的問題。我只更改第二欄,因爲我必須在第二欄中放置一些圖片。 問題出在FONT上。當我繪製第二列字體比第一列更清晰。只有當我第一次打開圖表形式時,它纔會出現。 由於它在代碼中顯示第一列默認是drawinng,第二列是由我繪製的。C#ListView DrawSubitem字體已更改

這是一個圖像。以全分辨率觀看。 With chart, without chart

這裏是我的代碼:

FO是我的字體,我可以改變。

private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) 
    { 
     if (e.Header != this.columnHeader2) 
     { 
      e.DrawDefault = true; 
      return; 
     } 

     if (e.Item.SubItems[1].Text == "1") 
     { 
      e.DrawBackground(); 
      e.Graphics.DrawImage(Properties.Resources.Blank_Badge_Green, e.SubItem.Bounds.Location.X, e.SubItem.Bounds.Location.Y, 10, 10); 
     } 
     else if (e.Item.SubItems[1].Text == "0") 
     { 
      e.DrawBackground(); 
      e.Graphics.DrawImage(Properties.Resources.Blank_Badge_Grey, e.SubItem.Bounds.Location.X, e.SubItem.Bounds.Location.Y, 10, 10); 
     } 
     else 
     { 
      e.DrawBackground(); 
      e.Graphics.DrawString(e.SubItem.Text, fo, new SolidBrush(e.SubItem.ForeColor), e.SubItem.Bounds.Location.X, e.SubItem.Bounds.Location.Y); 
     } 
    } 

    private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) 
    { 
     e.DrawDefault = true; 
    } 

回答

3
e.Graphics.DrawString(...) 

兩個問題。首先是你使用的方法,ListView使用TextRenderer.DrawText()。第二個問題很明顯,當你使用像SysInternals的ZoomIt這樣的工具時(推薦),你會發現這個討厭的文本沒有藍色/紅色的抗鋸齒像素。你需要設置Graphics.TextRenderingHint屬性來避免這種情況。

所以,大致爲:約樹形

else 
{ 
    e.DrawBackground(); 
    e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; 
    TextRenderer.DrawText(e.Graphics, ...); 
} 
+0

一個問題。當我更新和更改複選框時,它閃爍。我使用Property DoubleBuffered alredy: 「PropertyInfo property1 = typeof(TreeView).GetProperty(」DoubleBuffered「,BindingFlags.NonPublic | BindingFlags.Instance); property1.SetValue(treeView1,true,null);」 – user3447900 2014-10-14 07:13:23

+0

好的我發現它在 [TreeView閃爍](http://stackoverflow.com/questions/10362988/treeview-flickering) – user3447900 2014-10-14 07:51:57

0

最有可能你必須測試你畫上圖形的各種SmoothingModes:

e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 
    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 
    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; 
    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; 

試試,看看最匹配的系統得出的質量細胞!

在繪製文本之前設置它!

理論上其他一些特性可以有所作爲:

int e.Graphics.TextContrast // for adding a gamma correction 
e.Graphics.InterpolationMode // for resizing images 
e.Graphics.CompositingMode  // for combining an image with the pixels below 
e.Graphics.CompositingQuality // controls the quality thereof 

但最有可能的是SmoothingMode。