ListBox - FocusRectangle selber zeichnen
-
Hallo,
ich möchte die ListBox individuell gestallten. Dafür beeinflusse ich bereits Font und Hintergrundfarbe. Gerade unter Windows Vista ist die selektierte Zeile aber bei Font::Bold schlecht zu erkennen, aufgrund des dunklen Blaus.
Ich würde gerne die Zeile selber zeichnen.
private: System::Void listBox1_DrawItem(System::Object^ sender, System::Windows::Forms::DrawItemEventArgs^ e) { e->DrawBackground(); if( e->Index >= 0 ) { SolidBrush^ StringBrush = gcnew SolidBrush( Color::Black ); SolidBrush^ BackColor = gcnew SolidBrush( Color::AntiqueWhite ); Drawing::Font^ StringFont = gcnew Drawing::Font( listBox1->Font->Name, listBox1->Font->Size, listBox1->Font->Style, listBox1->Font->Unit ); int index = 0; if( e->Index % 2 != 0 ) index = 1; switch( index ) { case 0: StringBrush->Color = Color::Red; break; case 1: StringBrush->Color = Color::Blue; break; } e->Graphics->FillRectangle( BackColor, e->Bounds ); e->Graphics->DrawString( listBox1->Items[e->Index]->ToString(), StringFont, StringBrush, e->Bounds, StringFormat::GenericDefault ); //e->DrawFocusRectangle(); } }
So mache ich es bisher. Die einzige Frage ist:
Wie kann ich die Koordinaten des selektierten Index in Erfahrung bringen?EDIT:
if( (e->State & DrawItemState::Selected) == DrawItemState::Selected ) e->Graphics->FillRectangle( BackColor, e->Bounds );
Okay, war erschreckend einfach ... ^^