怎样在comboBox里放入图片(回者有分),急

mikesome 2002-09-16 04:34:53
就好像oicq选头像的那个comboBox,
...全文
37 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kingcaiyao 2002-09-16
  • 打赏
  • 举报
回复
当然Form中ImageList中必须要有图片。
kingcaiyao 2002-09-16
  • 打赏
  • 举报
回复
这简单啦,你可在OnDrawItem事件中画,不过前提是你必须将ComboBox1的Style设置成csOwnerDrawVariable,另外在桌面上放一个ImageList,详细请看代码:
#include <vcl.h>
#pragma hdrstop
#include "ComboBoxWithIcon.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
const int Margin=2;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{

for(int i=0;i<100;i++)
{
ComboBox1->Items->Add("KK"+IntToStr(i));

}
}
void __fastcall TForm1::ComboBox1DrawItem(TWinControl *Control, int Index,
TRect &Rect, TOwnerDrawState State)
{
ComboBox1->Canvas->FillRect(Rect);
ImageList1->Draw(ComboBox1->Canvas,Rect.Left+Margin,Rect.Top+Margin,Index,true);
String Text=ComboBox1->Items->Strings[Index];
int off=(Rect.Bottom-Rect.Top-ListBox1->Canvas->TextHeight(Text))/2;
ComboBox1->Canvas->TextOut(Rect.Left+ImageList1->Width+Margin*2,Rect.Top+off,Text);


}
void __fastcall TForm1::ComboBox1MeasureItem(TWinControl *Control,
int Index, int &Height)
{
Height=ImageList1->Height+Margin*2;
}
lingbin 2002-09-16
  • 打赏
  • 举报
回复
BCB6有一个ComboBoxEx控件,你只要设置它的Images和Style为csExDropDowny就可以了。
gfh21cn 2002-09-16
  • 打赏
  • 举报
回复
自己画,好像是可以自己画的
creativezj 2002-09-16
  • 打赏
  • 举报
回复
首先,设置ComboBox的Style属性为sOwnerDrawFixed 或者csOwnerDrawVariable.然后在OnDrawItem事件里用画它的Canvas就行了!!

13,870

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧