
13/07/2009, 20:11
|
 | | | Fecha de Ingreso: julio-2009
Mensajes: 31
Antigüedad: 15 años, 8 meses Puntos: 1 | |
Respuesta: CAmbiar color lineas listbox Yo lo hice heredando la clase listbox, sobrescribiendo los métodos de dibujo del ítem: onmeasureitem, ondrawitem, todo muy complejo porque mi objetivo fue colocar imágenes y efectos, pero debe de haber otra solución más simple, esta es parte del código, son 1000 lineas más:
Código:
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
{
base.OnDrawItem(e);
//((pr1.Form1)this.FindForm()).listBox1.Items.Insert(0,e.State.ToString() + " " + e.Index);
System.Drawing.Rectangle r;
System.Drawing.Brush bro=null;
System.Drawing.Brush brot=null;
ComboBoxItem it = null;
// System.Diagnostics.Debug.WriteLine(e.State );
if (Contains(e.State,System.Windows.Forms.DrawItemState.Selected))
{
bro = new System.Drawing.SolidBrush(_lc);
brot = new System.Drawing.SolidBrush(_ltc);
}
else
{
bro = new System.Drawing.SolidBrush(base.BackColor);
brot = new System.Drawing.SolidBrush(e.ForeColor);
}
if (e.Index != -1)
{
if (_pot)
{
r = new System.Drawing.Rectangle(e.Bounds.X+19,e.Bounds.Y,e.Bounds.Width,e.Bounds.Height);
}
else
{
r = e.Bounds;
}
if (this.Items[e.Index] is ComboBoxItem)
{
it = ((ComboBoxItem)this.Items[e.Index]);
//if (Contains(e.State,System.Windows.Forms.DrawItemState.ComboBoxEdit))//{// e.Graphics.FillRectangle(bro,e.Bounds);//}
it.DrawBack(bro,r,e);
if (_pot)
{
it.DrawImage(e,new System.Drawing.Rectangle(e.Bounds.X+1,e.Bounds.Y+1,16,16),false,base.BackColor,this);
}
else
{
it.DrawImage(e,new System.Drawing.Rectangle(e.Bounds.X+1,e.Bounds.Y+1,16,16),Contains(e.State,System.Windows.Forms.DrawItemState.Selected),base.BackColor,this);
}
if (it.TextDraw) {it.DrawText(it.ToString(),brot,new System.Drawing.Rectangle(e.Bounds.X + 18,e.Bounds.Y + 2,e.Bounds.Width - 18,e.Bounds.Height -1),e);}
}
else
{
e.Graphics.FillRectangle(bro,e.Bounds);
e.Graphics.DrawString(this.Items[e.Index].ToString(),e.Font,brot,e.Bounds);
}
}
else
{
e.Graphics.FillRectangle(bro,e.Bounds);
}
if (bro != null) {bro.Dispose();}
if (brot != null) {brot.Dispose();}
it = null;
}
Última edición por maycol_alvarez; 13/07/2009 a las 20:20 |