Delphi realizes form control free manipulation

Source: Internet
Author: User
Tags ini

In the process of doing MIS project, it is sometimes necessary for the user to implement the form control layout, for example, the hotel management needs to layout the dining table position. To achieve this, you must do three things:

1. Set the cursor shape into the edge of the control;

2, change the control size and position;

3. Save the position and status of the form control, and then reset the information for the form the next time it starts. The specific steps are as follows:

1, modify the control cursor. Just when you enter the control, the screen's cursor property is set to the corresponding shape, and the control has a onmousemove event that can be invoked in this event. I've encapsulated it as a function as follows:

procedure Cursorcontrol (Control:tcontrol; Shift:tshiftstate; X, Y, Prec:integer);
Begin
//cursor at leftmost of control
if (X<=prec) and (Y>prec) and (Y<control.height-prec) then control.cursor: = CrS The Izewe
//cursor is at the far right of the control
else if (X>=control.width-prec) and (Y>prec) and (Y<control.height-prec) then Cont Rol. Cursor: = Crsizewe
//cursor is at the top side of the control
else if (X>prec) and (X<control.width-prec) and (Y<=PREC) then controls. Cursor: = Crsizens
//cursor in upper left corner of control
else if (X<=prec) and (Y<=prec) then control.cursor: = Crsizenwse
/ /cursor in the upper-right corner of the control
else if (X>=control.width-prec) and (Y<=prec) then control.cursor: = CRSIZENESW
//cursor at the bottom of the control else if (X>prec) and (X<control.width-prec) and (Y>=control.height-prec) then control.cursor: = Crsizens
The cursor is in the lower-left corner of the control
else if (X<=prec) and (Y>=control.height-prec) then control.cursor: = CRSIZENESW
//cursor in the lower-right corner of the control br> else if (X>=control.width-prec) and (Y> =control.height-prec) then
control.cursor: = Crsizenwse
//cursor in the client area of the control (move the entire control)
else if (x>5) and (y> 5) and (x<control.width-5) and (y<control.height-5) then control.cursor: = Crsizeall
Else control.cursor: = CrD efault;//restores the default cursor
end;

2, modify the size and position of the form control. One of the easiest ways to do that is to send the appropriate message to the control. I've also encapsulated it into a function that can be invoked in the OnMouseDown event of a control. The function is as follows:

procedure Manipulatecontrol (Control:tcontrol; Shift:tshiftstate; X, Y, Prec:integer);
Var
sc_manipulate:word;//saves the corresponding message value
begin
//cursor at the leftmost of the control
if (X<=prec) and (Y>prec) and (Y<con Trol. HEIGHT-PREC) then sc_manipulate: = $F 001
//cursor at the far right of the control
else if (X>=control.width-prec) and (Y>prec) and (Y <CONTROL.HEIGHT-PREC) then sc_manipulate: = $F 002
//cursor on the top side of the control
else if (X>prec) and (x<control.width-p REC) and (Y<=PREC) THEN BEGIN
Sc_manipulate: = $F 003
//cursor in the upper-left corner of the control
else if (X<=prec) and (Y<=prec Then sc_manipulate: = $F 004
//cursor in the upper-right corner of the control
else if (X>=control.width-prec) and (Y<=prec) then Sc_manipula TE: = $F 005
//cursor on the lower side of the control
else if (X>prec) and (X<control.width-prec) and (Y>=control.height-prec) then Sc_manipulate: = $F 006
//cursor in lower left corner of control
else if (X<=prec) and (Y>=control.height-prec) then sc_manipulate: = $F 007
//cursor in the lower-right corner of the control
else if (x> =control.width-prec) and (Y>=control.height-prec) then sc_manipulate: = $F 008
//cursor in the client area of the control (move the entire control)
Else if (x>5) and (y>5) and (x<control.width-5) and (y<control.height-5) then sc_manipulate: = $F 009
Else sc_m Anipulate: = $F 000;    
If Shift=[ssleft] then
begin
ReleaseCapture
Control.perform (Wm_syscommand, sc_manipulate, 0);//Send change cursor message to control
end;
End;

3, save and restore the form control size and position. By traversing the component components of the form and then writing their location and size attribute values to the INI file, the form can be recovered by reading the INI file the next time the forms are started. There are many online solutions for this solution, and there are ready-made controls that can be implemented without writing a single line of code, and I'm no longer tired of that. Interested friends not to try. All code is tested under Win2000/delphi7.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.