ciao a tutti,
volevo porvi un dubbio per quanto riguarda la funzione listBox_DrawItem,
questa è la funzione che ho scritto:
codice:
private void lstBox_DrawItem(object sender,System.Windows.Forms.DrawItemEventArgs e)
{
e.DrawBackground();
Brush myBrush = Brushes.Black;
int pos = riassunto.SelectedIndex;
riassunto.SelectedIndex = e.Index;
String[] s= riassunto.SelectedItem.ToString().Split('x');
Piatto p=getPiatto(s[1].Substring(1));
switch (p.Colore)
{
case 0:
case 1:
myBrush = Brushes.Black;
break;
case 2:
myBrush = Brushes.Purple;
break;
case 3:
myBrush = Brushes.Blue;
break;
case 4:
myBrush = Brushes.Green;
break;
case 5:
myBrush = Brushes.Yellow;
break;
case 6:
myBrush = Brushes.Gray;
break;
case 7:
myBrush = Brushes.Red;
break;
case 8:
myBrush = Brushes.LightBlue;
break;
case 9:
myBrush = Brushes.Pink;
break;
case 10:
myBrush = Brushes.Violet;
break;
case 11:
myBrush = Brushes.Violet;
break;
case 12:
myBrush = Brushes.LimeGreen;
break;
}
e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString(), e.Font, myBrush, e.Bounds, StringFormat.GenericTypographic);
e.DrawFocusRectangle();
}
in pratica vorrei stampare le righe della listBox con colori diversi, e funziona, l'unico problema è che il font degli elementi della listbox non è quello standard ma lo impostato un po' più grande:
codice:
riassunto.Font = new Font("Arial", 14.5f);
e quando mi stampa la listBox i campi appaiono tagliati in altezza,
credo che il problema stia qui:
codice:
e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString(), e.Font, myBrush, e.Bounds, StringFormat.GenericTypographic);
e.DrawFocusRectangle();
non riesco a trovare il modo per aumentare manualmente la dimensione del rettangolo dove viene visualizzato il testo...
qualche suggerimento?
ciao