Question

I have use for the TControlBar component in my current project but I'm having issues with the control drawing extra rows when I'm moving the bands around,

basically what I want is the ControlBar to always only have 1 Row which is of fixed Height, and where the bands can't escape it while being dragged.

How can I achieve this ?

Was it helpful?

Solution 2

I solved this months ago by basically deriving my own component from the TPanel class and implementing a drag solution of child panels to mimic the behavior I wanted.

This is the most basic principle I used to implement the desired effect :

var oldPos : TPoint;

procedure TMainForm.ControlMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer);

begin

   if Button = mbLeft then
     if (Sender is TWinControl) then
     begin
      inReposition:=True;
      SetCapture(TWinControl(Sender).Handle);
      GetCursorPos(oldPos);
      TWinControl(Sender).BringToFront;
     end else
        ((Sender as TLabel).Parent as TQPanelSub).OnMouseDown((Sender as TLabel).Parent as TQPanelSub,Button,Shift,X,Y)


end;


procedure TMainForm.ControlMouseMove(Sender: TObject; Shift: TShiftState; X: Integer; Y: Integer);
var
  newPos: TPoint;
  temp : integer;

begin

  if (Sender is TWinControl) then begin

    if inReposition then
    begin

      with TWinControl(Sender) do
      begin
        GetCursorPos(newPos);
        Screen.Cursor := crSize;
        (* Constrain to the container *)
        Top := 0;
        temp := Left - oldPos.X + newPos.X;
        if (temp >= 0) and (temp <= (Parent.Width - Width))
        then Left := temp;
        oldPos := newPos;
      end;

    end;

  end else
    ((Sender as TLabel).Parent as TQPanelSub).OnMouseMove((Sender as TLabel).Parent as TQPanelSub,Shift,X,Y);

end;

procedure TMainForm.ControlMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer);
begin

   if inReposition then
  begin
    Screen.Cursor := crDefault;
    ReleaseCapture;
    inReposition := False;
  end;

end;

This is just the basis that I wanted from the TControlBar which infact is a horribly written component.

OTHER TIPS

You can do a workaround for this:

procedure TForm1.ControlBar1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var R:TRect;
    Pt:TPoint;

begin
  Pt:=ControlBar1.ClientToScreen(Point(0,Y));
  R.Left:=Pt.X;
  R.Top:=Pt.Y;
  R.Right:=Pt.X+ControlBar1.Width;
  R.Bottom:=Pt.Y;
  ClipCursor(@R);
end;

procedure TForm1.ControlBar1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  ClipCursor(nil) ;
end;

With that you can restrict the mouse movement to allow only vertical positioning of the Bands.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top