delphitcustomcontrol

Using TControlBar, how do I limit the movement of the bands to a single row?


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 ?


Solution

  • 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.