Q&A

  • 컴포넌트 구합니다.
콤보 박스의 Item에 텍스트가 아닌 텍스트와 이미지가 들어가는

컴포넌트를 구합니다.

(Source포함이고요....)

아시는 분 있으면 알려주세요.. 꼭, 꼭, 꼭....

2  COMMENTS
  • Profile
    글쎄요. 1999.05.10 23:16
    영문으로 되 있는 데 참고하시는 데 그리 어려움이 없을 겁니다.

    그럼 좋은 하루 되셔요.

    //////////

    TI: Inserting graphics in Owner Drawn ListBoxes and ComboBoxes



    The ability to place graphics inside ListBoxes and ComboBoxes

    can improve the look of your application and set your user

    interface apart from the others.



    Q: How do I stick graphics in a Listbox or ComboBox???



    Here is an step-by-step example.....



    1. Create a form.



    2. Place a ComboBox and Listbox component on your form.



    3. Change the Style property of the ComboBox component to

    csOwnerDrawVariable and the Style property of the ListBox to

    lbOwnerDrawVariable.



    An Owner-Draw TListBox or TComboBox allows you to display

    both objects (ex. graphics) and strings as the items. For

    this example, we are adding both a graphic object and a

    string.



    4. Create 5 variables of type TBitmap in the Form's VAR

    section.



    5. Create a Procedure for the Form's OnCreate event.



    6. Create a Procedure for the ComboBox's OnDraw Event.



    7. Create a Procedure for the ComboBox's OnMeasureItem.



    8. Freee the resources in the Form's OnClose Event.





    {START OWNERDRW.PAS}

    unit Ownerdrw;



    interface



    uses

    SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,

    Forms, Dialogs, StdCtrls;



    type

    TForm1 = class(TForm)

    ComboBox1: TComboBox;

    ListBox1: TListBox;

    procedure FormCreate(Sender: TObject);

    procedure FormClose(Sender: TObject; var Action: TCloseAction);

    procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;

    Rect: TRect; State: TOwnerDrawState);

    procedure ComboBox1MeasureItem(Control: TWinControl; Index: Integer;

    var Height: Integer);

    procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;

    Rect: TRect; State: TOwnerDrawState);

    procedure ListBox1MeasureItem(Control: TWinControl; Index: Integer;

    var Height: Integer);

    private

    { Private declarations }

    public

    { Public declarations }

    end;



    var

    Form1: TForm1;

    TheBitmap1, TheBitmap2, TheBitmap3, TheBittmap4,

    TheBitmap5 : TBitmap;

    implementation



    {$R *.DFM}



    procedure TForm1.FormCreate(Sender: TObject);

    begin

    TheBitmap1 := TBitmap.Create;

    TheBitmap1.LoadFromFile('C:delphiimagesbuttonsglobe.bmp');

    TheBitmap2 := TBitmap.Create;

    TheBitmap2.LoadFromFile('C:delphiimagesbuttonsvideo.bmp');

    TheBitmap3 := TBitmap.Create;

    TheBitmap3.LoadFromFile('C:delphiimagesbuttonsgears.bmp');

    TheBitmap4 := TBitmap.Create;

    TheBitmap4.LoadFromFile('C:delphiimagesbuttonskey.bmp');

    TheBitmap5 := TBitmap.Create;

    TheBitmap5.LoadFromFile('C:delphiimagesbuttonstools.bmp');

    ComboBox1.Items.AddObject('Bitmap1: Globe', TheBitmap1);

    ComboBox1.Items.AddObject('Bitmap2: Video', TheBitmap2);

    ComboBox1.Items.AddObject('Bitmap3: Gears', TheBitmap3);

    ComboBox1.Items.AddObject('Bitmap4: Key', TheBitmap4);

    ComboBox1.Items.AddObject('Bitmap5: Tools', TheBitmap5);

    ListBox1.Items.AddObject('Bitmap1: Globe', TheBitmap1);

    ListBox1.Items.AddObject('Bitmmap2: Video', TheBitmap2);

    ListBox1.Items.AddObject('Bitmap3: Gears', TheBitmap3);

    ListBox1.Items.AddObject('Bitmap4: Key', TheBitmap4);

    ListBox1.Items.AddObject('Bitmap5: Tools', TheBitmap5);



    end;



    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);

    begin

    TheBitmap1.Free;

    TheBitmap2.Free;

    TheBitmap3.Free;

    TheBitmap4.Free;

    TheBitmap5.Free;

    end;



    procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;

    Rect: TRect; State: TOwnerDrawState);

    var

    Bitmap: TBitmap;

    Offset: Integer;

    begin

    with (Control as TComboBox).Canvas do

    begin

    FillRect(Rect);

    Bitmap := TBitmap(ComboBox1.Items.Objects[Index]);

    if Bitmap <> nil then

    begin

    BrushCopy(Bounds(Rect.Left + 2, Rect.Top + 2, Bitmap.Width,

    Bitmap.Height), Bitmap, Bounds(0, 0, Bitmap.Width,

    Bitmap.Height), clRed);

    Offset := Bitmap.width + 8;

    end;

    { display the text }

    TextOut(Rect.Left + Offset, Rect.Top, Combobox1.Items[Index])

    end;

    end;



    procedure TForm1.ComboBox1MeasureItem(Control: TWinControl; Index:

    Integer; var Height: Integer);

    begin

    height:= 20;

    end;



    procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;

    Rect: TRect; State: TOwnerDrawState);

    var

    Bitmap: TBitmap;

    Offset: Integer;

    begin

    with (Control as TListBox).Canvas do

    begin

    FillRect(Rect);

    Bitmap := TBitmap(ListBox1.Items.Objects[Index]);

    if Bitmap <> nil then

    begin

    BrushCopy(Bounds(Rect.Left + 2, Rect.Top + 2, Bitmap.Width,

    Bitmap.Height), Bitmap, Bounds(0, 0, Bitmap.Width,

    Bitmap.Height), clRed);

    Offset := Bitmap.width + 8;

    end;

    { display the text }

    TextOut(Rect.Left + Offset, Rect.Top, Listbox1.Items[Index])

    end;

    end;



    procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;

    var Height: Integer);

    begin

    heeight:= 20;

    end;



    end.

    {END OWNERDRW.PAS}



    {START OWNERDRW.DFM}

    object Form1: TForm1

    Left = 211

    Top = 155

    Width = 435

    Height = 300

    Caption = 'Form1'

    Font.Color = clWindowText

    Font.Height = -13

    Font.Name = 'System'

    Font.Style = []

    PixelsPerInch = 96

    OnClose = FormClose

    OnCreate = FormCreate

    TextHeight = 16

    object ComboBox1: TComboBox

    Left = 26

    Top = 30

    Width = 165

    Height = 22

    Style = csOwnerDrawVariable

    ItemHeight = 16

    TabOrder = 0

    OnDrawItem = ComboBox1DrawItem

    OnMeasureItem = ComboBox1MeasureItem

    end

    object ListBox1: TListBox

    Left = 216

    Top = 28

    Width = 151

    Height = 167

    ItemHeight = 16

    Style = lbOwnerDrawVariable

    TabOrder = 1

    OnDrawItem = ListBox1DrawItem

    OnMeasureItem = ListBox1MeasureItem

    end

    end

    {END OWNERDRW.DFM}



  • Profile
    김영대 1999.05.10 22:27
    김장섭 wrote:

    > 콤보 박스의 Item에 텍스트가 아닌 텍스트와 이미지가 들어가는

    > 컴포넌트를 구합니다.

    > (Source포함이고요....)

    > 아시는 분 있으면 알려주세요.. 꼭, 꼭, 꼭....



    안녕하세요 김영대입니다

    그런 기능이라면 직접 코딩하셔도 몇줄 안됩니다

    아래 예제가 있는데

    CB_GroupName 는 TComboBox 이고요

    Image_group 는 이미지가 들어있는 조그만 TImage 입니다





    procedure TWinUserForm.CB_GroupNameDrawItem(Control: TWinControl;

    Index: Integer; Rect: TRect; State: TOwnerDrawState);

    begin

    with CB_GroupName.Canvas do

    begin

    FillRect(Rect); {clear the rectangle}

    BrushCopy(Bounds(Rect.Left, Rect.Top, Image_group.Picture.Bitmap.Width, Image_group.Picture.Bitmap.Height), Image_group.Picture.Bitmap,

    Bounds(0,0, Image_group.Picture.Bitmap.Width, Image_group.Picture.Bitmap.Height), clRed);

    TextOut(Rect.Left+21, Rect.Top+3, CB_GroupName.Items[Index]);

    end;

    end;



    • 송수정
    • 1999.05.11 10:01
    • 1 COMMENTS
    • /
    • 0 LIKES
    • 이정욱
      1999.05.11 11:01
      한델(http://www.delphi.co.kr) 강의실에 가보시면 인쇄에 관한 강좌가 있습니다. 참고하시구요.. TPrint...
    • 엠마
    • 1999.05.11 09:04
    • 1 COMMENTS
    • /
    • 0 LIKES
    • 하윤철
      1999.05.11 18:02
      엠마 wrote: > 테이블에 insert한후에 조회하면은 insert한 자료는 조회가 되지 않습니다. > 테이블에 데...
    • 강경중
    • 1999.05.11 07:08
    • 2 COMMENTS
    • /
    • 0 LIKES
    • 안치봉
      1999.05.11 08:09
      강경중 wrote: > 델파이의 폼에 콤포넌트를 추가하면 > 콤포넌트 마다 고유의 Taborder가 있습니다. > ...
    • 강경중
      1999.05.12 03:13
      안치봉 wrote: > 강경중 wrote: > > 델파이의 폼에 콤포넌트를 추가하면 > > 콤포넌트 마다 고유의 Tabo...
    • 강경중
    • 1999.05.11 06:53
    • 1 COMMENTS
    • /
    • 0 LIKES
    • 이정욱
      1999.05.11 10:08
      에러를 가로챈다기 보다 무시하게 하면 됩니다. Try Except문으로 처리하세요. 델파이환경에서 Break on ...
    • 강경중
    • 1999.05.11 06:47
    • 1 COMMENTS
    • /
    • 0 LIKES
    • 이정욱
      1999.05.11 11:03
      ImageList의 속성(Property)를 보시면 그림의 크기를 정하는곳이 있습니다. Width와 Height이죠. 그림은 ...
    • 누군지
      1999.05.11 10:12
      이런 종류의 질문이....??? 스스로 노력을 하다가 문제가 생겼을 때 질문을 해야하는것이 적어도 성의가...
    • 영이...
    • 1999.05.11 03:09
    • 1 COMMENTS
    • /
    • 0 LIKES
    • 이정욱
      1999.05.11 20:32
      안녕하세요? 제가 DB는 모르지만 언어적으로 해결을 하시려면... 하나씩 기억했다가 사용하면 어떨까요? ...
    • 왕초보
    • 1999.05.11 02:55
    • 2 COMMENTS
    • /
    • 0 LIKES
    • 이정욱
      1999.05.11 20:38
      CM_EXIT 라는 컴포넌트 내부 메세지를 가로채면 됩니다. procedure CMExit(var Message: TCMExit); mess...
    • 왕초보
      1999.05.11 21:54
      친절한 답변 감사드립니다... 이정욱 wrote: > CM_EXIT 라는 컴포넌트 내부 메세지를 가로채면 됩니다....
    • 이호선
    • 1999.05.11 01:57
    • 1 COMMENTS
    • /
    • 0 LIKES
    • 이정욱
      1999.05.11 20:50
      BitBtn1.Glyph.LoadFromFile의 메소드가 잘 먹히는데요? 아래는 테스트 해본 코드입니다... var ...
    • 왕초보
      1999.05.11 02:54
      Tfield의 EditMask에다가 #라고 쓰십시오...이게 무슨 뜻인지..? "#"으로만 editmask를 잡으면 1,234 와 ...
    • 하윤철
      1999.05.11 17:29
      죄송합니다... TField에 EditFormat과 DisplayFormat 속성이 있을겁니다. DisplayFormat은 보여주는 ...
    • 김장섭
    • 1999.05.10 20:57
    • 2 COMMENTS
    • /
    • 0 LIKES
    • 글쎄요.
      1999.05.10 23:16
      영문으로 되 있는 데 참고하시는 데 그리 어려움이 없을 겁니다. 그럼 좋은 하루 되셔요. ////////// TI...
    • 김영대
      1999.05.10 22:27
      김장섭 wrote: > 콤보 박스의 Item에 텍스트가 아닌 텍스트와 이미지가 들어가는 > 컴포넌트를 구합니다...
    • 땡글이
    • 1999.05.10 20:44
    • 1 COMMENTS
    • /
    • 0 LIKES
    • 신인재
      1999.05.10 21:37
      treeview의 Q&A를 한델(http:/www.delphi.co.kr)자료실에 올려 놓겠습니다. 참고 하세요... 땡글이 wro...
    • 김봉재
    • 1999.05.10 19:58
    • 2 COMMENTS
    • /
    • 0 LIKES
    • 글쎄요.
      1999.05.10 23:24
      DeleteFiles함수입니다. 세번째 인자가 True이면 서브디렉토리까지 지워주고 아니면 현 디렉토리만 지웁니...
    • 안치봉
      1999.05.10 21:36
      김봉재 wrote: > 창이 두개 있는 화일 매니저같은(?)것을 만들어 보려고 합니다... > 여기서 각각의 화일...
    • 북해
    • 1999.05.10 18:20
    • 1 COMMENTS
    • /
    • 0 LIKES
    • 이정욱
      1999.05.10 19:37
      모 전적으로 맞는것은 아니지만 제 생각을 말씀드리죠. 일단, 비베는 MS 에서 나온 개발툴이죠. 우리가 생...
    • 이정욱
      1999.05.10 10:41
      패스워드 같은것을 저장하시려면 Encrypt 컴포넌트를 사용하시면 됩니다. 물론 저장은 텍스트형식으로 그...
    • 안명호
    • 1999.05.09 22:53
    • 1 COMMENTS
    • /
    • 0 LIKES
    • 안치봉
      1999.05.10 00:15
      안명호 wrote: > MS 의 SPY++ 이나 Borland 의 WinSight32 같이 > 다른 프로그램에서 발생하는 메시지...
    • 안명호
    • 1999.05.09 21:16
    • 1 COMMENTS
    • /
    • 0 LIKES
    • 안치봉
      1999.05.10 00:15
      안명호 wrote: > 윈도우즈에서 특정 프로그램이 실행 되는지 알아 보려면 어떻게 > 해야 하나요... > 프...