Hello everybody.
I made a list box with the owner draw variable property enabled and handled both draw and measure item events to customize it.
the problem is:
I used a gradient brush for the selection but the color changes from the top of the list box to its bottom.:confused: I wish to make one gradient color for all the items like this.
http://img198.imageshack.us/img198/1360/illustrationn.png
I also wish to implement hot tracking with the same color.
The code I used:
private: System::Void listBox1_DrawItem(System::Object^ sender, System::Windows::Forms::DrawItemEventArgs^ e)
{
if ((e->State & DrawItemState::Selected) == DrawItemState::Selected)
{
Graphics^ G = listBox1->CreateGraphics();
System::Drawing::Drawing2D::LinearGradientBrush^ myBrush = gcnew System::Drawing::Drawing2D::LinearGradientBrush(ClientRectangle,Color::Azure, Color::Violet, System::Drawing::Drawing2D::LinearGradientMode::Vertical);
System::Drawing::Drawing2D::LinearGradientBrush^ myBrush2 = gcnew System::Drawing::Drawing2D::LinearGradientBrush(ClientRectangle,Color::LightBlue, Color::White, System::Drawing::Drawing2D::LinearGradientMode::Horizontal);
System::Drawing::Pen^ P = gcnew System::Drawing::Pen(myBrush2);
e->Graphics->FillRectangle(myBrush, e->Bounds);
e->Graphics->DrawRectangle(P,e->Bounds);
System::Drawing::Font^ F = gcnew System::Drawing::Font( "Microsoft Sans Serif",8 );
e->Graphics->DrawString("Size: 600.4 MB Last Modified::12/12/2012",F, Brushes::Black, e->Bounds.X+1, e->Bounds.Y+20);
e->Graphics->DrawString("Type: Folder Extension:ELF",F, Brushes::Black, e->Bounds.X+1, e->Bounds.Y+40);
e->Graphics->DrawString("C:\\Files\\Folders\\Some Folder",F, Brushes::Green, e->Bounds.X+1, e->Bounds.Y+60);
}
else
{
e->Graphics->FillRectangle(Brushes::White, e->Bounds);
System::Drawing::Pen^ Pe = gcnew System::Drawing::Pen(Color::White); e->Graphics->DrawRectangle(Pe,e->Bounds);
}
try
{
System::Drawing::Font^ F = gcnew System::Drawing::Font( "Microsoft Sans Serif",12 );
e->Graphics->DrawString(listBox1->Items[e->Index]->ToString(),F, Brushes::Blue, e->Bounds.X, e->Bounds.Y);
e->DrawFocusRectangle();}
catch(Exception^ ex){}
}
private: System::Void listBox1_MeasureItem(System::Object^ sender, System::Windows::Forms::MeasureItemEventArgs^ e) {
e->ItemHeight += 65;
e->Index::get();
}
I appreciate any help.
Thanks alot.