delphi2007 教程

delphi2007 教程

首页 新随笔 联系 聚合 管理
  1013 Posts :: 0 Stories :: 28 Comments :: 0 Trackbacks
如何设置comboBox下拉框的大小,并在下拉框中画上类式excel的表格??? VCL组件开发及应用
http://www.delphi2007.net/DelphiVCL/html/delphi_20061221121414222.html
今天面试出了这么一个题目考我。  
  1、设置combobox下拉框的宽度和高度(需要调用API)  
  2、在combobox下拉框中画上类似excel的表格,表格形式如下:  
      ID     学校     专业  
      01     北大     计算机应用  
      02     清华     数学  
      03     交大     英语  
   
  哪位大虾知道,出手帮忙一下啊,兄弟我不胜感激,在线等

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

设置Item的高度?  
  ListBox.Style   :=   lbOwnerDrawFixed;  
  ListBox.ItemHeight   :=   50;  
  或  
  ListBox.Perform(LB_SETITEMHEIGHT,   0,   50);  
 

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

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

第一个问题,别人都说了  
   
  第二个问题,给你一段演示的代码  
   
  临时写的,自己看明白了,改改就可以了  
  unit   Unit1;  
   
  interface  
   
  uses  
      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.  
 

下拉项是下面的表格形式:  
      ID     学校     专业  
      01     北大     计算机应用  
      02     清华     数学  
      03     交大     英语  
 

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

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

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

学习

 
            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的源码.

UP了

posted on 2009-01-04 16:52 delphi2007 阅读(2067) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。