With the development of software technology, the software interface is more and more beautiful, and the operation is more and more convenient.
Looking at the more professional software in the market, we will find that most of them provide form docking function, especially tool software, which basically has more or less docking function.
Nature, Delphi also support docking, and she and VCL close together, for the vast number of Delphi programmers is a great gospel. Let's save the tedious coding time. Focus on the idea of the core process.
Let's review the structure of the VCL and have a Docksite attribute (Boolean) in the Twincontrol class, which is to allow other controls to dock on top of it, and to have a Dragkind attribute in the Tcontrol class. If you want this control to dock on another control, set the Dragkind property to Dkdock. As simple as this, just set the properties, a support docking program is completed.
Of course, the above is just the most basic step, with these two steps, we can continue to write code to achieve more complex functions.
General support docking programs can be docked in the main window up and down, that is to say, in the main window on the edge of the control can be docked better (as long as it is inherited from the Twincontrol), generally we choose Tpanel, in order to facilitate the reader to understand, we can assume that the left side of the main window can be docked , so put a panel with the Align property on the main window, named Leftdockpanel, the 0,docksite property is true, and of course our leftdockpanel should be able to change the size of the alleft. So put a tsplitter on the right side of it and name the Leftsplitter,align property for Alleft. Next is to dock the control, the general program docking controls are forms, so we also build a form, named Dockableform,dragkind property set to the Dkdock,dragmode property set to Dmautomatic (automatic docking).
Now we can run this program, what? Bad effect? Docked forms dock and then disappear!
Oh, I almost forgot, when docked form stops, Delphi produces events that are
1. Ondockover (Sender:tobject; Source:tdragdockobject;
X, Y:integer; State:tdragstate; var accept:boolean);
2. Ondockdrop (Sender:tobject; Source:tdragdockobject;
X, Y:integer);
3. Ongetsiteinfo (Sender:tobject; Dockclient:tcontrol;
var influencerect:trect; Mousepos:tpoint; var candock:boolean);
4. Onstartdock (Sender:tobject;
var dragobject:tdragdockobject);
5. Onenddock (Sender, Target:tobject; X, Y:integer);
6. Onundock (Sender:tobject; Client:tcontrol;
Newtarget:twincontrol; var allow:boolean);