Implement the movement of the control, change the size (Delphi implementation)

zhaozj2021-02-17  52

Implement the movement of the control, change the size (Delphi implementation)

Mainly use Perform method Function Perform (Msg: Cardinal; WPARAM, LPARAM: longint): longint; This method can also be applied in other environments using functions similar to Win32API.

Using Delphi to create an application, join a PANEL1 in a form, save to main.pas; ​​then move in Panel1 mouse, the mouse is added to the event; mouse movement: Control the shape of the cursor Procedure TFORM1.PANEL1MOUSEMOVE (Sender: Tobject; Shift: TshiftState; x, y: integer; begin if (x> = 0) and (x <= 3) THEN BEGIN IF (Y> = 0) and (y <= 3) Then Panel1.cursor: = Crsizenwse; if (y> 3) And (Y = panel1.Height-3) and (y <= panel1. Height) THEN PANEL1.CURSOR: = CrsizENESW; END ELSE IF (x> 3) and (x = 0) and (y <= 3) Then Panel1.cursor: = Crsizens; if (y> 3) and (y = panel1.Height-3) And (y <= panel1.width) Then Panel1.cursor : = Crsizens; ELSE IF (x> = panel1.width-3) and (x <= panel1.width) THEN BEGIN IF (Y> = 0) and (y <= 3) THEN PANEL1.CURSOR: = CrsizENESW; IF (Y> 3) And (Y = panel1.Height-3) And (y <= panel1.width) Then Panel1.cursor: = Crsizenwse; End;

Mouse Press: Control Panel's size or position procedure tForm1.Panel1Mousedown (Sender: Tobject; button: tmousebutton; shift: tshiftstate; x, y: integer; begin ReleaseCapture; if (x> = 0) and (x <= 3) ) THEN BEGIN FILE: // Left upper corner change Size if (Y> = 0) and (y <= 3) Then Panel1.Perform (WM_SYSCOMMAND, $ F004, 0); file: // Left side IF (Y> 3 And (Y = panel1.height-3) and (y <= panel1.height) Then Panel1.Perform (WM_SYSCOMMAND, $ F007, 0); END ELSE IF (x> 3) and (x = 0) AND (Y < = 3) THEN Panel1.Perform (WM_SYSCOMMAND, $ F003, 0); file: // Mobile control if (y> 3) and (Y = Panel1.Height-3) THEN PANEL1.PERFORM (WM_SYSCOMMAND, $ F006, 0); ELSE IF (x> = panel1.width -3) AND (x <= panel1.width) Then Begin file: // Right corner IF (Y> = 0) and (y <= 3) Then Panel1.Perform (WM_SYSCOMMAND, $ F005, 0); File: / / Right Side IF (Y> 3) And (Y = panel1.Height-3) And (y <= panel1.width) Then Panel1.Perform (WM_SYSCOMMAND, $ F008, 0); END ; END; mainly using the Perform method is appendix 1. All code is as follows:

Unit main;

Interface

Uses Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, ExtCtrls

type TForm1 = class (TForm) Panel1: TPanel; procedure Panel1MouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure Panel1MouseMove (Sender: TObject; Shift: TShiftState; X, Y: Integer) PRIVATE {Private Declarations} end; var form1: tform1;

IMPLEMENTATION

{$ R * .dfm}

Procedure TForm1.Panel1Mousedown (Sender: Tobject; Button: TMouseButton; Shift: TshiftState; x, y: integer; begin ReleaseCapture; if (x> = 0) and (x <= 3) Then Begin if (y> = 0) And (y <= 3) THEN PANEL1.PERFORM (WM_SYSCOMMAND, $ F004, 0); if (Y> 3) and (Y = panel1.height-3) and (y <= panel1.height) Then Panel1.Perform (WM_SYSCOMMAND, $ F007, 0); ELSE IF (x> 3) and (x = 0) and (y <= 3) Then Panel1.Perform (WM_SYSCOMMAND, $ F003, 0); if (Y> 3) and (Y = panel1.Height-3) and (y <= panel1.width) THEN PANEL1.PERFORM (WM_SYSCOMMAND, $ F006, 0); ELSE IF (x> = panel1. Width-3) and (x <= panel1.width) THEN BEGIN IF (Y> = 0) and (y <= 3) THEN PANEL1.PERFORM (WM_SysCommand, $ F005, 0); if (y> 3) and ( Y = panel1.height-3) and (y <= panel1.width) Then Panel1.Perform (WM_SysCommand, $ F008 , 0); END;

Procedure TForm1.Panel1Mousemove (Sender: Tobject; Shift: TshiftState; x, y: integer); begin if (x> = 0) and (x <= 3) THEN BEGIN IF (Y> = 0) AND (Y <= 3) ........................................................................... .. .HEIGHT) THEN Panel1.cursor: = CrsizENESW; END ELSE IF (x> 3) And (x = 0) and (y <= 3) Then Panel1.cursor: = Crsizens; IF (Y> 3) and (Y = panel1.Height-3) and (y <= panel1.width).. Cursor: = Crsizens; ELSE IF (x> = panel1.width-3) and (x <= panel1.width) THEN BEGIN IF (Y> = 0) and (y <= 3) THEN PANEL1.CURSOR: = CrsizENESW ; If (y> 3) and (y = panel1.Height-3) And (y <= panel1.width) Then Panel1.cursor: = CrsizenWse; end; end; Appendix 2.Api sendMessage () introduction SendMessage === User32.LiblResult SendMessage

HWND HWND, // Handle of Destination Window Uint Msg, // Message To Send WParam WPARAM, // First Message Parameter Lparam Lparam // Second Message Parameter

2001.9.27

转载请注明原文地址:https://www.9cbs.com/read-29367.html

New Post(0)