2014-10-12 28 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。