Monday, October 25, 2010

delphi programming for instance - can be produced anywhere drag and drop toolbar


In the frequently-used software, such as photoshop, office, delphi, etc., we often can drag the toolbar to conduct operations related to the toolbar ---- will drag out the formation of an independent small window; or the number of toolbar for each combination! (These are the features that we often say that the DOCK), results as shown below:



DELPHI Toolbar

In fact, the use of DELPHI, or other visual programming tools (such as c + + builder, etc.) are easy to implement the above features! Next, we look through a small example of how it is implemented, where the use of programming tools for the Delphi!

Before starting an instance, we should note some stuff! (Some nonsense about the first ^ _ ^)

VCL visual components are supported DOCK features!
In delphi, all inherited from Tcontrol and TWinControl of VCL components, support dock feature.

Basically, the need for dock action requires at least two components, one component being attached to the dock site, the other components attached to the dock site. DELPHI provides visual components, only inherited from the TWinControl the VCL components that have the dock site features, and so long as the VCL components inherited from Tcontrol then have the function attached to the dock site.

* If you want a component inherited from TWinControl a dock site features, so long as the components of the property DockSite can be set to true;
* If necessary a component inherited from TControl attached to the dock site, as long as the property of Drag kind set to dkDock, DragMode property can be set to dmAutomatic,

When the program execution, you can use the mouse to drag the latter to the former components on the device, to dock action. As for the dock of the actual action are encapsulated in components, the user need not control how these actions are carried out.

Immediately begin our examples!

Create a common project (project1), drag pages from the win32 control a CoolBar, a ToolBar, an ImageList to the form1 form, the property is as follows:




Form1

. Caption: example of the realization of a DOCK functions;






CoolBar1 (to be attached to the dock site elements)

. AutoSize: true;
. DockSite: true;
For some better results, you can BorderWidth, EdgeBorders, EdgeInner, EdgeOuter, the associated set!



ToolBar1 (attached to the dock site components)
Right-click on the ToolBar1 components, select New Button, the new number of buttons between them can be New Separator, associated groups separated!

. Caption: tool bar (when the window is displayed independent of the title)
. AutoSize: true;
. DockKind: dkDock;
. DragMode: dmAutomatic;
. Flat: ture; (it look better)
. Images: ImageList1;
Similarly, for some better results, you can BorderWidth, EdgeBorders, EdgeInner, EdgeOuter, the associated set!



ImageList1,
Double-click the control, select Add ..., add the pieces of pictures. This can easily be in these pictures assigns ToolBar Button!



Click the Run button, you drag down your toolbar, you can not immediately see the results now? We have not written a line of code do? ? ? ? This is Delphi's powerful place!



[Next]



In order to better drag and drop, we add the following lines of code! (Mainly CoolBar1 the onDragOver, onDockDrop and UnDock events); source code is as follows (very short, do not think I'm lazy!) (Download the source files packaged with the implementation of the program)

unit sample1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ImgList, ComCtrls, ToolWin;

type
TForm1 = class (TForm)
ImageList1: TImageList;
CoolBar1: TCoolBar;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
procedure CoolBar1DragOver (Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure CoolBar1DockDrop (Sender: TObject; Source: TDragDockObject; X,
Y: Integer);
procedure CoolBar1UnDock (Sender: TObject; Client: TControl;
NewTarget: TWinControl; var Allow: Boolean);
procedure ToolButton1Click (Sender: TObject);
private
(Private declarations)
public
(Public declarations)
end;

var
Form1: TForm1;

implementation

($ R *. DFM)

procedure TForm1.CoolBar1DragOver (Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept: = (source = ToolBar1); file / / specify the conditions to accept drag and drop drag and drop objects to ToolBar1;
end;

procedure TForm1.CoolBar1DockDrop (Sender: TObject; Source: TDragDockObject;
X, Y: Integer);
begin
ToolBar1.AutoSize: = false; file / / when the device onto the dock site components above, and after release the left mouse button, this event will be the implementation of
ToolBar1.Align: = altop; file / / In order to facilitate drag and drop, the width and coolbar1 toolbar1 similar.
ToolBar1.Width: = CoolBar1.Width-1;
end;

procedure TForm1.CoolBar1UnDock (Sender: TObject; Client: TControl;
NewTarget: TWinControl; var Allow: Boolean);
begin
ToolBar1.AutoSize: = true; file / / when the components of a component off the dock site, the matter will be executed
ToolBar1.Caption: =''Toolbar''; file / / set the window size separate toolbar and the title
end;

procedure TForm1.ToolButton1Click (Sender: TObject);
begin
Close; file / / exit program
end;

end.

DOCK features listed below and related events:

OnDragDrop: When the device is drag, this event is executed;
OnDragOver: used to specify the components can be dragged conditions;
OnDockDrop: When the device onto the dock site components above, and after release the left mouse button, this event will be implemented;
OnDockOver: When the components of a device onto the dock site, this event will be implemented;
OnUnDock: When the components of a component off the dock site, the matter will be implemented;
OnGetSiteInfo: to obtain some information components dock site.

Well, drag and drop through a small example of the toolbar, we can immediately appreciate the power of Delphi's ease of use and Office! Later I will continue to write about programming with Delphi for instance the article! Members Delphi enthusiasts, we will Delphi be in the end it! NGA is limited, if any wrong with it, pointed out that users please! Thank you! aatun@163.net






Recommended links:



hal.dll damaged the Problems caused by Ubuntu not boot



Who is knocking THE door of opportunity?



Simple Food And Drink



how to upload put convert kodak playsport video to



Taobao Is Free Of Charge Commitment Charges Due To Question



Recommend Inventory And Barcoding



Quality control in the "Statistics" Several concepts



FLV To IPod



H.264 to AVI



MTS To MP4



Modify the secondary cache can not speed up XP



Ali Mama assets will pass into THE listed company Alibaba



Best Games Board



"Digital Tobacco" to Me



Sail a meteoric rise through media and public relations



Thunder won the Super Rabbit infringement compensable 80000



No comments:

Post a Comment