今天面试出了这么一个题目考我。
1、设置combobox下拉框的宽度和高度(需要调用API)
2、在combobox下拉框中画上类似excel的表格,表格形式如下:
  ID  学校  专业
  01  北大  计算机应用
  02  清华  数学
  03  交大  英语哪位大虾知道,出手帮忙一下啊,兄弟我不胜感激,在线等

解决方案 »

  1.   

    Combox.height:=10;
    ComBox.Width:=100;ComBox.Items.add('ID'+#9+'学校'+#9+'专业')
      

  2.   

    设置Item的高度?
    ListBox.Style := lbOwnerDrawFixed;
    ListBox.ItemHeight := 50;

    ListBox.Perform(LB_SETITEMHEIGHT, 0, 50);
      

  3.   

    生成Tstring对象,赋值后传给Item即可
      

  4.   

    楼上几位感谢你们的帮忙,可你们误解了,combobox的Item就是我上面所说的表格
      

  5.   

    第一个问题,别人都说了第二个问题,给你一段演示的代码临时写的,自己看明白了,改改就可以了
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      tTest=record
        id :string[2];
        xx : string[4];
        zy : string[4];
      end;
      TForm1 = class(TForm)
        ComboBox1: TComboBox;
        procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
          Rect: TRect; State: TOwnerDrawState);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        arrayTest : array[0..2] of tTest;
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    begin
      with (Control as TComboBox).Canvas do
      begin
        
        TextOut(rect.Left ,rect.Top,arrayTest[Index].id);
        TextOut(rect.Left+30,rect.Top,arrayTest[Index].xx);
        TextOut(rect.Left+70,rect.Top,arrayTest[Index].zy);
        Pen.Color := clBlack;
        MoveTo(rect.Left,rect.Top);
        LineTo(rect.Right,rect.Top);    MoveTo(rect.Left,rect.Bottom);
        LineTo(rect.Right,rect.Bottom);    MoveTo(Rect.Left + 26,Rect.Top);
        LineTo(rect.Left+26,rect.Bottom);     MoveTo(Rect.Left + 65,Rect.Top);
        LineTo(rect.Left+65,rect.Bottom);
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
        ComboBox1.Items.Clear;
        arrayTest[0].id := '01';
        arraytest[0].xx := '北大';
        arrayTest[0].zy := 'plmm';
        ComboBox1.Items.Add('01');    arrayTest[1].id := '02';
        arraytest[1].xx := '北大';
        arrayTest[1].zy := 'make';
        ComboBox1.Items.Add('02');    arrayTest[2].id := '03';
        arraytest[2].xx := '烂校';
        arrayTest[2].zy := '**';
        ComboBox1.Items.Add('03');    ComboBox1.ItemIndex := 0;
    end;end.
      

  6.   

    to:wudi_1982(闲半年了,要挣点钱过年了!) 
        第一个问题是设置item的宽度和高度,能让下拉框有上/下,左/右滚动条
      

  7.   

    上面的代码忘记了一句,你要做如下设置ComboBox1.Style := csOwnerDrawFixed;
      

  8.   

    我现在的问题只剩下,如何调用API可以设置ComBoBox下拉框的宽度和高度使之,有滚动条出现????
      

  9.   


         SetWindowPos(ComboBox1.Handle, 0, 0, 0,
         200,//这里可以设置宽度
         600,//高度 
         SWP_NOMOVE or SWP_NOZORDER or SWP_NOACTIVATE or SWP_NOREDRAW or
          SWP_HIDEWINDOW);至于滚动条
       垂直的,当你的列表内容大于总数的时候,就自动出现了
      水平的,在基本的combobox上,不知道怎么加如果像完全实现你的功能,从TCombobox类继承,写一个新组件,你可以参考一下VCL的源码.