[SOLVED] ComboBox Appearance with Wide Bitmaps lazarus / 31-LCL ---------------------------------------------------------------------- Windsurfer · 2014-04-22 15:13 I am using a combobox to display bitmap images rather than text. (This is in a context where pictures are more useful than text.) the bitmaps are read from a laz resource. Using qt and GTK2 the combo box appears as in the attachment. (This is qt. GTK2 is slightly different.) Should the slider disappear? I am using lazarus 1.2 with Linux Mint 16 on a PC. All is 64 bit. ---------------------------------------------------------------------- taazz · 2014-04-22 22:29 what slider? ---------------------------------------------------------------------- Windsurfer · 2014-04-23 08:50 The slider or thumb that usually appears to the right of the combobox. However, I just noticed up/down arrows appearing at the top and bottom of the control, when I click on it. So, it appears to be working, but not as I expected. Pic1 shows the initial appearance, Pic2 shows the appearance when first selected, Pic3 shows the appearance when an item is selected. Pic2 is the one that now puzzles me. I can see no reason for the blank items at the top. I would appreciate any comments that help me correct the blank items in Pic2. The code is: Code: [Select]Procedure TfrmMainScreen.cbSymbolsDrawItem(Control: TWinControl;   Index: Integer; ARect: TRect; State: TOwnerDrawState); var   ComboBox: TComboBox;   symBitmap: TBitmap; begin   ComboBox := (Control as TComboBox);   symBitmap := TBitmap.Create;   try     symBitmap.LoadFromLazarusResource(MySymbols[index]);     with ComboBox.Canvas do     begin       ARect := Bounds(ARect.Left, Arect.Top, Arect.Left + 50, Arect.Top + 15);       FillRect(ARect);       if symBitmap.Handle <> 0 then Draw(ARect.Left, ARect.Top, symBitmap);     end;   finally     symBitmap.Free;   end; End; The initialization is: Code: [Select] MySymbols :=  TStringList.Create;   MySymbols.Add('linessquares');   MySymbols.Add('linescircles');   MySymbols.Add('line');   MySymbols.Add('squares');   MySymbols.Add('circles');   MySymbols.Add('points');  {$I ../WindSirf64/WindSirf64.lrs} The MySymbols string list is freed when the form is closed. Edit: The FormActivate event should, I believe, clear the combobox items. Code: [Select]Procedure TfrmMainScreen.FormActivate(Sender: TObject); Var   I: Integer; Begin   cbSymbols.Clear;   For I := 0 To 5 Do     cbSymbols.Items.Add('');   cbSymbols.ItemIndex := 0; End; ---------------------------------------------------------------------- howardpc · 2014-04-23 09:51 Quote from: Windsurfer on April 23, 2014, 10:50:43 amPic2 is the one that now puzzles me. I can see no reason for the blank items at the top. Code: [Select]  ...     with ComboBox.Canvas do     begin       ARect := Bounds(ARect.Left, Arect.Top, Arect.Left + 50, Arect.Top + 15); Why do you need to alter the ARect parameters you are given? You need to ensure that you draw the top of each bitmap at the correct Y offset. If the bitmaps were stored in an imagelist, you would write code something like this: Code: [Select]  procedure TForm1.cbSymbolsDrawItem(Control: TWinControl; Index: Integer;   ARect: TRect; State: TOwnerDrawState); var   cnv: TCanvas;   itemHeight: integer; begin   if not (Control is TComboBox) then Exit;   cnv:=TComboBox(Control).Canvas;   itemHeight:=Size(ARect).cy;   cnv.FillRect(ARect);   ImageList1.Draw(cnv, 0, index*itemHeight, index); end; ---------------------------------------------------------------------- Windsurfer · 2014-04-23 11:59 Thanks HowardPC I will try as you suggest, and report back. I did try an ImageList, but had problems with png files, so changed to bitmaps and a resource file. ---------------------------------------------------------------------- Windsurfer · 2014-04-23 12:36 Hi HowardPC, I need to play with the code a little more. It displays an image, but not all of them. When I store the png images in the Imagelist, the images only appear as 16x16 px images. This is why I redefined the size of ARect and used a resource file. ---------------------------------------------------------------------- howardpc · 2014-04-23 12:59 TImageList has writeable Height and Width properties. You are by no means restricted to only 16x16 pixel images. The only restriction is that all images in the list must share the same dimensions. So if you want to store images of various sizes you need more than one imagelist. ---------------------------------------------------------------------- Windsurfer · 2014-04-23 16:24 Thanks HowardPC, this is so simple! It appears that the image size should be set in the ImageList before graphics are loaded, or maybe I did not click 'Apply'. I ended with this code in FormCreate: Code: [Select]  cbSymbols.Items.Clear;   For I := 0 To 5 Do     cbSymbols.Items.Add('');   cbSymbols.ItemIndex := 0;  and this code in the DrawItem event: Code: [Select]Procedure TfrmMainScreen.cbSymbolsDrawItem(Control: TWinControl;   Index: Integer; ARect: TRect; State: TOwnerDrawState); var   cnv: TCanvas; begin   if not (Control is TComboBox) then Exit;   cnv:=TComboBox(Control).Canvas;   //Add 2 to Left and Top to centre 50 x18 image   Imagelist1.Draw(cnv, ARect.Left+2, ARect.Top+2, index); End;