In my project, I want move a toolbutton to a previous position, I just use
the following code:
//Move AExchangee to position ToIndex
procedure MoveTo(AExchangee: TToolButton; ToIndex: Integer);
var
tlb: TToolBar;
begin
Assert(AExchangee.Parent is TToolBar);
tlb := TToolBar(AExchangee.Parent);
AExchangee.Left := tlb.Buttons[ToIndex].Left;
end;
Sometimes it works ok, but in some cases, it disarrange the order of other
buttons! What's the problem? How can I do it correctly? Thanks for any
help.
Regards,
George
> Sometimes it works ok, but in some cases, it disarrange the order of
> other buttons! What's the problem? How can I do it correctly? Thanks
> for any help.
I'm bothered of this problem. If I cannot solve it, I have to throw
TToolBar away and use a 3-party toolbar control. But the latter is risky
because I have to rewrite a lot of source code but time is limited, and I'm
not sure if the replacer is reliable & good enough. Can somebody give some
constructive suggestions?
Regards,
George
Could it work if you had another, hidden toolbar, and to insert, you
reparent every button after the insertion point to the hidden toolbar, add
your new button, then put back the buttons from the hidden toolbar in
reverse order.
> Could it work if you had another, hidden toolbar, and to insert, you
> reparent every button after the insertion point to the hidden toolbar,
> add your new button, then put back the buttons from the hidden toolbar
> in reverse order.
>
I've tried this. It may works, but it does not always work. It seems that
the new position is related to both the original position in te hidden
toolbar and the existing buttons on the target toolbar, but I can not find
out the regulation.
George
> AExchangee.Left := tlb.Buttons[ToIndex].Left;
Suggest you try:
AExchangee.Left := tlb.Buttons[ToIndex].Left - 1;
When you set the left position precisely on the required spot there will
momentarily be two buttons at the same position - which one will win when it
comes to settling the order?
Untested, but sounds plausible. :)
--
Regards,
Chris Luck