Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    [C#] problema con listBox_DrawItem

    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

  2. #2
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,472

    Moderazione

    Ho spostato la discussione all'interno del forum dedicato a Visual Basic (VBx, VBA, ...) e ai linguaggi per .NET Framework (VB.NET, C#, ...).

    In futuro, poni in questo forum le domande relative a questi linguaggi.

    Ciao!
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.