4

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 ?

Peter
  • 2,977
  • 1
  • 17
  • 29
  • 1
    Hmm, does anyone know how to use the `OnBandInfo` event and then especially the `RowCount` parameter? When set to 1, it doesn't seem to limit the row count as I would expect. – NGLN Jan 17 '13 at 11:58
  • I also had little to no result from fiddling with the OnBandInfo. I've also figured that setting maxHeight Constraint of the ControlBar would at least in some way change how the bands are being drawn but no result there since the band still drops into a new row, it just isn't visible. – Peter Jan 17 '13 at 12:09
  • 1
    `RowCount` property of OnBandInfo definitely isn't the answer here because it only controls over how many rows the band actually spans over as opposed to actually controlling the number of rows that the band can dock into. – Peter Jan 17 '13 at 13:02

2 Answers2

0

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.

Fenistil
  • 3,734
  • 1
  • 27
  • 31
  • I'm against any global restrictions, furthermore mouse restrictions cause a terrible end user experience and I can't have that, not to mention the unpredictable results in case of a Fatal Error or a crash. – Peter Jan 25 '13 at 11:21
0

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.

Peter
  • 2,977
  • 1
  • 17
  • 29