ich hatte mich einige zeit zur Ruhe gesetzt und bin wieder ein bisschen am Programmieren ;) zu meinem Problem:
jedesmal wenn ich in meiner ListBox ein Item abwähle, sprich wenn ich ein anderes Item neu Selektiere, flackert das abgewählte item. Ich hab echt alles versucht überall rum gegooglet aber ich habe keine Ahnung was da passiert und warum es flackert. :(
Wen es interessiert hier mal ein Bld vom Projekt (und der ListBox): siehe Anhang
Hier mal der code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DrawingEx;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace substx
{
class DesignListBox : ListBox
{
public DesignListBox()
{
base.SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.ResizeRedraw |
ControlStyles.AllPaintingInWmPaint,
true);
// DoubleBuffered = true; <-- nutzt auch nix WAH!!!
base.DrawMode = DrawMode.OwnerDrawFixed;
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
Rectangle bnd = e.Bounds;
Graphics dc = e.Graphics;
ColorTable ct = (ColorTable)Items[e.Index];
int pad = 6;
int pwh = bnd.Height - 2 * pad;
Rectangle pi0 = new Rectangle(bnd.X + pad, bnd.Y + pad, pwh, pwh);
Rectangle pi1 = new Rectangle(bnd.X + pi0.Right + pad, bnd.Y + pad, pwh, pwh);
Rectangle pi2 = new Rectangle(bnd.X + pi1.Right + pad, bnd.Y + pad, pwh, pwh);
Rectangle pi3 = new Rectangle(bnd.X + pi2.Right + pad, bnd.Y + pad, pwh, pwh);
if (ct == null)
{
#region Error
dc.FillRectangle(new SolidBrush(BackColor), bnd);
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
dc.DrawString("Error Item.", Font, new SolidBrush(Color.Red), bnd, sf);
#endregion
}
else
{
#region Preview
dc.SetColorTableWindowsVista(ct);
dc.FillRectangle(new SolidBrush(ct.Background), bnd);
dc.DrawVistaButtonBackground(pi0, 2, true, false, false);
dc.DrawVistaButtonBackground(pi1, 2, true, true, false);
dc.DrawVistaButtonBackground(pi2, 2, true, false, true);
dc.DrawVistaButtonBackground(pi3, 2, true, true, true);
Rectangle capt = bnd; capt.X += 8; capt.Width -= 8;
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
dc.DrawString(ct.Name + ((ct == Design.ColorTable) ? " (Aktiv)" : ""), Font, new SolidBrush(ct.Text), capt, sf);
#endregion
}
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
#region Selection
Rectangle sel = bnd;
Rectangle selhalf;
Color selcl = Color.CornflowerBlue;
sel.Inflate(-2, -2);
using (GraphicsPath psel = RoundedRectangle.Create(sel, 2))
{
using (Pen selouter = new Pen(Color.FromArgb(75, selcl)))
{
dc.DrawPath(selouter, psel);
}
}
sel.Inflate(-1, -1);
selhalf = sel;
selhalf.Height /= 2;
using (GraphicsPath psel = RoundedRectangle.Create(selhalf, 2,
RoundedRectangle.RectangleCorners.TopLeft &
RoundedRectangle.RectangleCorners.TopRight))
{
selhalf.Height++;
using (LinearGradientBrush lgb = new LinearGradientBrush(
selhalf, Color.FromArgb(150, selcl), Color.Transparent, 90f))
{
dc.FillPath(lgb, psel);
}
}
using (GraphicsPath psel = RoundedRectangle.Create(sel, 2))
using (Pen selinner = new Pen(Color.FromArgb(150, selcl)))
{
dc.DrawPath(selinner, psel);
}
#endregion
}
}
}
}