C#,Delphi,Oracle,MSSQL 개발자블로그
델파이 콤보박스 아이템 사이즈(Item Widths) 늘리기. 본문
콤보박스 사용 시 콤보박스 자체의 크기는 작지만, 내부 항목의 길이는 넓은 경우가 있다.
이 때, 방법은 콤보박스 자체의 크기를 늘리면 되지만, 콤보박스가 올라가는 폼에서 공간이 협소해 콤보박스
자체의 크기를 늘리기 어려울 때가 있다.
이 때, 콤보박스의 크기는 그대로 두고, 내부 아이템의 크기만 늘리는 방법이다.
적용 전과 후의 차이는 다음 캡쳐와 같다.
소스는 다음과 같다.
procedure TForm1.ComboBox_AutoWidth(const theComboBox: TAdvComboBox);
const
HORIZONTAL_PADDING = 15;
var
itemsFullWidth: integer;
idx: integer;
itemWidth: integer;
begin
itemsFullWidth := 0;
// get the max needed with of the items in dropdown state
for idx := 0 to -1 + theComboBox.Items.Count do
begin
itemWidth := theComboBox.Canvas.TextWidth(theComboBox.Items[idx]);
Inc(itemWidth, 2 * HORIZONTAL_PADDING);
if (itemWidth > itemsFullWidth) then itemsFullWidth := itemWidth;
end;
// set the width of drop down if needed
if (itemsFullWidth > theComboBox.Width) then
begin
//check if there would be a scroll bar
if theComboBox.DropDownCount < theComboBox.Items.Count then
itemsFullWidth := itemsFullWidth + GetSystemMetrics(SM_CXVSCROLL);
SendMessage(theComboBox.Handle, CB_SETDROPPEDWIDTH, itemsFullWidth, 0);
end;
end;
출처 : https://www.thoughtco.com/sizing-the-combobox-drop-down-width-1058301
'Programming > Delphi' 카테고리의 다른 글
델파이 프로그래스바 ProgressBar (0) | 2019.06.12 |
---|---|
델파이 Split 함수 (0) | 2019.06.12 |
델파이 Abort와 Exit의 차이점은? (0) | 2019.06.08 |
[경로/에러]컴퓨터에 *.dll이(가) 없어 프로그램을 시작할 수 없습니다. (0) | 2019.06.08 |
델파이 폼 Maximize, Minimize 버튼 숨기기 (0) | 2019.06.08 |