I solved the problem, heh I musta been tired to not see this before. The 
TPanels were on a TScrollBox which had a scrollbar. When the scrollbar was 
at position > 0, the TPanels created would be placed incorrectly. So all I 
had to do is set the position to 0 then set the bounds on the TPanels. The 
control works like a charm now =)

----- Original Message ----- 
From: Richard R
To: 'Delphi-Talk Discussion List'
Sent: Tuesday, September 20, 2005 9:12 AM
Subject: gaps makes me gasp


I am developing a custom control that creates a gradient from 1-255 colors. 
My design works out great but there is a problem. I recently added a "Add" 
and "Delete" function to this so users can add and delete colors. However 
the placement of each TPanel containing the color is getting wacked out. It 
seems that after 5 or 6 color panels are created, the last panel get placed 
with a huge gap from the previous one and I dont know what is causing it. 
The formula to place the panels nice and neet is asize * idx + 2, it works 
out for a few panels then starts making huge gaps, any suggestions?

procedure TtsxGradientBar.AddColor(Sender: TObject);
var
  asize, idx: integer;
begin
  if (FNbrColors = High(Byte)) then
    exit;
  asize:= 0;
  // 25 is the width or height of the scroll bar depending on orientation
  case Orientation of
    dVertical:
      asize:= FScrollBox.Width - 25;
    dHorizontal:
      asize:= FScrollBox.Height - 25;
  end;
  idx:= FNbrColors; // current number of colors (or tpanels)
  FNbrColors:= FNbrColors + 1; // increase the number of colors and tpanels
  SetLength(FPanels, FNbrColors); // increase size of the tpanel array
  FPanels[idx]:= TPanel.Create(FScrollBox);
  FPanels[idx].Parent:= FScrollBox;
  FPanels[idx].ParentColor:= False;
  // this is where i run into a problem. About 5 to 6 tpanels are properly 
aligned but any more and
  // a huge gap gets placed between the last panel and the previous one. Any 
suggestions?
  case Orientation of
    dVertical:
      FPanels[idx].SetBounds(2, idx * asize + 2, asize, asize);
    dHorizontal:
      FPanels[idx].SetBounds(idx * asize + 2, 2, asize, asize);
  end;
  FPanels[idx].Color:= RGB(Random(255), Random(255), Random(255));
  FPanels[idx].Caption:= '';
  FPanels[idx].OnMouseDown:= pMouseDown;
  FPanels[idx].OnMouseUp:= pMouseUp;
  MakeGradient; // this just creates an array of colors of the gradient 
effect
  Paint; // this paints a preview of the gradient effect on the main control
end; 
__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to