How do I set the size of the ComboBox drop-down box and draw a type Excel worksheet in the drop-down box ???

Source: Internet
Author: User
Tags textout
How do I set the size of the ComboBox drop-down box and draw a type Excel worksheet in the drop-down box ??? Development and Application of VCL Components
Http://www.delphi2007.net/DelphiVCL/html/delphi_20061221121414222.html
Today, I got an exam on this subject.
1. Set the width and height of the ComboBox drop-down box (you need to call the API)
2. Draw a table similar to excel in the ComboBox drop-down box. The form is as follows:
Id school major
01 Peking University Computer Application
02 Tsinghua mathematics
03 Jiaotong University English

Which of the following prawns knows how to help? I am very grateful, brother. I am online.

Combox. Height: = 10;
Combox. Width: = 100;

Combox. Items. Add ('id' + #9 + 'school' + #9 + 'professional ')

Set the height of item?
ListBox. Style: = lbownerdrawfixed;
ListBox. itemheight: = 50;
Or
ListBox. Perform (lb_setitemheight, 0, 50 );

Generate a tstring object. assign a value to the item.

Thanks for your help, but you have misunderstood that the ComboBox item is the table I mentioned above.

The first question has been answered by others.

The second question, I will give you a demonstration Code

Write it temporarily. You can understand it and change it.
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)
Combox1: 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: = 'peking University ';
Arraytest [0]. ZY: = 'plmm ';
Combobox1.items. Add ('01 ');

Arraytest [1]. ID: = '02 ';
Arraytest [1]. XX: = 'peking University ';
Arraytest [1]. ZY: = 'make ';
Combobox1.items. Add ('02 ');

Arraytest [2]. ID: = '03 ';
Arraytest [2]. XX: = 'bad school ';
Arraytest [2]. ZY: = '**';
Combobox1.items. Add ('03 ');

Combobox1.itemindex: = 0;
End;

End.

The drop-down items are shown in the following table:
Id school major
01 Peking University Computer Application
02 Tsinghua mathematics
03 Jiaotong University English

To: wudi_1982 !)
The first problem is to set the width and height of the item so that the drop-down box can have the upper/lower and left/right scroll bars

The above code forgets a sentence. You need to set it as follows:

Combobox1.style: = csownerdrawfixed;

My current problem is only left. How can I call the API to set the width and height of the ComboBox drop-down box so that a scroll bar appears ????

Learning


Setwindowpos (combobox1.handle, 0, 0, 0,
200, // you can set the width here
600, // height
Swp_nomove or swp_nozorder or swp_noactivate or swp_noredraw or
Swp_hidewindow );

As for the scroll bar
Vertical, when the content of your list is greater than the total number, it will automatically appear
Horizontally, on the basic ComboBox, I don't know how to add

If you fully implement your functions, inherit from the tcombobox class, and write a new component, you can refer to the source code of VCL.

Up

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.