No tiene que ser exactamente en este caso, siempre que existan determinados. El tamaño de este CheckListBox con Altura = 137, ancho = 149.
Al primero que quiero hacer es utilizar la barra que pone de relieve el tamaño del texto del texto y no el tamaño de ItemHeight, porque soy el cálculo de la distancia entre los elementos de línea dentro del componente.
A modo de ejemplo:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, CheckLst, XPMan; type TForm1 = class(TForm) gbTributo: TGroupBox; chklistTributo: TCheckListBox; Button1: TButton; procedure chklistTributoDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var iItem: Integer; begin with chklistTributo do begin ItemHeight := (Height div Items.Count); iItem := ItemHeight; ItemHeight := iItem -1; end; end; procedure TForm1.chklistTributoDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var iTotalItem: Integer; //Criei uma função para não repetir codigos sem necessidade function RetornaCoordenadas(chkLtBox: TCheckListBox; iTotItem: Integer):Integer; begin with chkLtBox do begin case iTotItem of //Verifica o total de itens para calcular o Rect.Top do checklistbox 08: Result := 01; 07: Result := 03; 06: Result := 05; 05: Result := 07; 04: Result := 09; 03: Result := 16; 02: Result := 27; 01: Result := 60; end; end; end; // begin with (Control as TCheckListBox).Canvas do begin //Font.Color := clBlack; Brush.Style := bsSolid; iTotalItem := chklistTributo.Items.Count; //Conta a quantidade de itens dentro do ListBox e manda para variavel TextOut(Rect.Left + 4, Rect.Top + (RetornaCoordenadas(chklistTributo,iTotalItem)),(Control as TCheckListBox).Items[Index]); end; end; procedure TForm1.Button1Click(Sender: TObject); var i : integer; begin with chklistTributo do begin for i := -1 + Items.Count downto 0 do if Selected then Items.Delete(i) ; end; end; end.
O DFM
[/]
object gbTributo: TGroupBox Left = 8 Top = 24 Width = 153 Height = 154 Caption = 'Tributo' TabOrder = 0 object chklistTributo: TCheckListBox Left = 2 Top = 15 Width = 149 Height = 137 Align = alClient BevelInner = bvNone BevelOuter = bvNone BorderStyle = bsNone Color = clBtnFace ItemHeight = 16 Items.Strings = ( 'Test' 'Test2' 'Test3' 'Test4' 'Test5') Style = lbOwnerDrawFixed TabOrder = 0 OnDrawItem = chklistTributoDrawItem end end object Button1: TButton Left = 168 Top = 72 Width = 75 Height = 25 Caption = 'Del Item' TabOrder = 1 OnClick = Button1Click end
Así que esta forma de trabajar allí, más es difícil saber cuántos elementos tienen con CheckListBox. Y si me voy a poner el clavo Reparate las coordenadas de Rect.Top como la cantidad de elementos. (Esto no es factible)[/]Como aquí en Brasil no pude conseguir a nadie que me ayude, por lo que estoy buscando la ayuda de otras naciones.Gracias a quien me pueda ayudar.Adriano.
Descuple, estou using Google o tradutor