所有者绘制的列表框,具有热跟踪功能 [英] owner drawn listBox with hot tracking
问题描述
大家好.
我创建了一个列表框,其中启用了所有者绘制变量属性,并处理了绘制和测量项目事件以对其进行自定义.
问题是:
我使用了渐变笔刷进行选择,但是颜色从列表框的顶部到底部都发生了变化.:confused:我希望为所有此类项目制作一种渐变色.
http://img198.imageshack.us/img198/1360/illustrationn.png
我也希望以相同的颜色实现热跟踪.
我使用的代码:
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);
// Draw the focus rectangle around the selected item.
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.
推荐答案
我真的应该集中精力.
我将[ClientRectangle]更改为[e-> Bounds],一切顺利.
但仍然不了解热跟踪:(((
谁能给我逻辑或代码.我发现它与Mouse Enter,Move和Leave事件有关,但无法理解代码.它不是C ++中的.
是的,如何使选择矩形从边缘变圆?:confused:
再次感谢.
I really should have concentrated.
I changed [ClientRectangle] to [e->Bounds] and it went alright.
but still don''t know about Hot-tracking :((
could anybody give me logic or code. I found it''s related to Mouse Enter, Move, and Leave events but couldn''t understand the code. It wasn''t in C++.
and yes, how can I make the selection rectangle rounded from the edges?:confused:
Thanks again.
这篇关于所有者绘制的列表框,具有热跟踪功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!