RAD Studio VCL Reference
|
Translates a given point from client area coordinates to global screen coordinates.
Use ClientToScreen to convert a point whose coordinates are expressed locally to the control to the corresponding point in screen coordinates. In client area coordinates (0, 0) corresponds to the upper left corner of the control's client area. In screen coordinates (0, 0) corresponds to the upper left corner of the screen.
Use ScreenToClient along with ClientToScreen to convert from one control's coordinate system to another control's coordinate system. For example,
P := TargetControl.ScreenToClient(SourceControl.ClientToScreen(P));
P = TargetControl->ScreenToClient(SourceControl->ClientToScreen(P));
converts P from coordinates in SourceControl to coordinates in TargetControl.
C++ Examples:
/* The following example is taken from the docking demo. It shows how set permissions to dock dockable objects onto a docking site. */ void __fastcall TMainForm::LeftDockPanelDockDrop(TObject *Sender, TDragDockObject *Source, int X, int Y) { //OnDockDrop gets called AFTER the client has actually docked, //so we check for DockClientCount = 1 before making the dock panel visible. TPanel *panel = dynamic_cast<TPanel *>(Sender); if (panel->DockClientCount == 1) ShowDockPanel(panel, True, NULL); panel->DockManager->ResetBounds(True); //Make DockManager repaints it's clients. } void __fastcall TMainForm::LeftDockPanelDockOver(TObject *Sender, TDragDockObject *Source, int X, int Y, TDragState State, bool &Accept) { Accept = (dynamic_cast<TDockableForm*>(Source->Control) != NULL); if (Accept) { // Modify the DockRect to preview dock area. Types::TPoint TopLeft = LeftDockPanel->ClientToScreen(Point(0, 0)); Types::TPoint BottomRight = LeftDockPanel->ClientToScreen( Point(this->ClientWidth/3, LeftDockPanel->Height)); Source->DockRect = Types::TRect(TopLeft, BottomRight); } } void __fastcall TMainForm::LeftDockPanelUnDock(TObject *Sender, TControl *Client, TWinControl *NewTarget, bool &Allow) { //OnUnDock gets called BEFORE the client is undocked, in order to optionally //disallow the undock. DockClientCount is never 0 when called from this event. TPanel *panel = dynamic_cast<TPanel *>(Sender); if (panel->DockClientCount == 1) ShowDockPanel(panel, False, NULL); } void __fastcall TMainForm::LeftDockPanelGetSiteInfo(TObject *Sender, TControl *DockClient, TRect &InfluenceRect, TPoint &MousePos, bool &CanDock) { //if CanDock is true, the panel will not automatically draw the preview rect. CanDock = DockClient->ClassNameIs("TDockableForm"); if (!CanDock) { ShowMessage(L"GetSiteInfo CanDock went bad!"); } }
Delphi Examples:
{ The following example is taken from the docking demo. It shows how set permissions to dock dockable objects onto a docking site. } procedure TMainForm.LeftDockPanelDockDrop(Sender: TObject; Source: TDragDockObject; X, Y: Integer); begin //OnDockDrop gets called AFTER the client has actually docked, //so we check for DockClientCount = 1 before making the dock panel visible. if (Sender as TPanel).DockClientCount = 1 then ShowDockPanel(Sender as TPanel, True, nil); (Sender as TPanel).DockManager.ResetBounds(True); //Make DockManager repaints it's clients. end; procedure TMainForm.LeftDockPanelDockOver(Sender: TObject; Source: TDragDockObject; X, Y: Integer; State: TDragState; var Accept: Boolean); var ARect: TRect; begin Accept := Source.Control is TDockableForm; if Accept then begin //Modify the DockRect to preview dock area. ARect.TopLeft := LeftDockPanel.ClientToScreen(Point(0, 0)); ARect.BottomRight := LeftDockPanel.ClientToScreen( Point(Self.ClientWidth div 3, LeftDockPanel.Height)); Source.DockRect := ARect; end; end; procedure TMainForm.LeftDockPanelUnDock(Sender: TObject; Client: TControl; NewTarget: TWinControl; var Allow: Boolean); begin //OnUnDock gets called BEFORE the client is undocked, in order to optionally //disallow the undock. DockClientCount is never 0 when called from this event. if (Sender as TPanel).DockClientCount = 1 then ShowDockPanel(Sender as TPanel, False, nil); end; procedure TMainForm.LeftDockPanelGetSiteInfo(Sender: TObject; DockClient: TControl; var InfluenceRect: TRect; MousePos: TPoint; var CanDock: Boolean); begin //if CanDock is true, the panel will not automatically draw the preview rect. CanDock := DockClient is TDockableForm; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|