如何实现一个OwnerDraw的具体例子,这个对高手应该很简单,可我很菜;
若有:发到:[email protected] 多谢

解决方案 »

  1.   

    一个菜单自绘制的范例:
    http://www.csdn.net/Develop/Read_Article.asp?Id=3488
      

  2.   

    To: technofantasy(www.applevb.com) :
    我有点看不懂哪个例子,可否一个简单的,示意就行! 比如对  ComboBox 的项目实现自绘;我真的初学者,谢谢!
      

  3.   

    只是实现自绘的功能就可以了,不需要太复杂,复杂了我看不懂!
    谢谢!!
    最好用ComBoBox 来实现
      

  4.   

    将Combobox的Style属性设为csOwnerDrawFixed,假定Imagelist1中有几个图标为Combobox加入字串
    procedure TForm1.FormCreate(Sender: TObject);
    var  i: integer;
    begin
     for i:=0 to imagelist1.Count-1 do
       Combobox1.Items.Add(inttostr(i));
    end;在OnItemDraw事件画图标及文本
    procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    begin
     Combobox1.Canvas.FillRect(Rect);
     imagelist1.Draw(Combobox1.Canvas,Rect.left,rect.top,index);
     combobox1.canvas.TextOut(rect.Left+20,rect.top, inttostr(index));
    end; 
      

  5.   

    给你一个范例,比较匆忙:procedure TForm1.ComboBox1MeasureItem(Control: TWinControl; Index: Integer;
      var Height: Integer);
    begin
      //改变列的高度
      Height := 24;
    end;procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    var
      s:string;
      rc:TRect;
    begin
      //获得Index所在的行的内容
      s := (Control as TCombobox).Items.Strings[Index];
      with (Control as TCombobox).Canvas do
      begin
        Brush.Color := clRed;
        Brush.Style := bsSolid;
        rc.Left := rect.Left;
        rc.top := rect.Top;
        rc.Right := rc.Left +24;
        rc.Bottom := rc.top + 24;
        //填充背景
        ComboBox1.Canvas.FillRect(rc);
        //输出文字
        Brush.Style := bsClear;
        Pen.Color := clBlue;
        Pen.Style := psSolid;
        ComboBox1.Canvas.TextOut(30,8,s);
      end;
    end;
      

  6.   

    对于控件地OWNERDRAW有两个主要事件,一个是OnMeasureItem,这个事件在设定Item的尺寸前调用,你可以在该事件里面设定Item的高度,上面的范例将combobox中的Item高度设定为24。
    在onDrawItem事件中,Control是要绘制的控件,Index是要绘制的控件的Item索引,rect是绘制区域,State是Item状态,基本上你只需要获得rect以及控件地canvas,然后在canvas上面自由绘制九可以了。