User: alciro    User
 Original    Translate to:  Deutsch  English  Français  中文  
 

Programación en C++ Builder

 Arrays (arrays)
 Pointers
3. Example of class in c + +
8. AnsiString class methods
 C + + projects
 Packages, distribute an application without installation
 Exchange or bubble sorting
 String string.h functions

11.3. Derived from TControl

OnClick

Event occurs when you make a click on a control.

__property Classes:: TNotifyEvent OnClick = {read = FOnClick, write = FOnClick};

 void __fastcall TForm1:: CheckBox1Click (TObject * Sender)
{
PageControl1-> ActivePage-> Visible = CheckBox1-> Checked;
} 


OnDblClick

Event occurs when performing a double click a control.

 __property Classes:: TNotifyEvent OnDblClick = {read = FOnDblClick, write = FOnDblClick}; 

This example Notifies the user That WAS the form double-clicked.

 void __fastcall TForm1:: FormDblClick (TObject * Sender) 

{
Application-> MessageBox ("You double-clicked the form", "Double-Click Message", MB_OK);
}


OnDragDrop

Happens when the user completes the drag and drop to draw an object on the form (it drops the object in the control releasing the mouse button). You can respond to this event when the form is ready to support drag and drop.

 typedef void __fastcall (__closure * TDragDropEvent) (System:: TObject * Sender, System:: TObject * Source, int X, int Y);
__property TDragDropEvent OnDragDrop = {read = FOnDragDrop, write = FOnDragDrop}; 

The parameters X and Y are the coordinates of the mouse position on the control.


OnDragOver

It happens when you move the mouse pointer over the control while drawing the object with the mouse. You can respond to this event when the form is ready to support drag and drop.

 enum {TDragState dsDragEnter, dsDragLeave, dsDragMove}
typedef void __fastcall (__closure * TDragOverEvent) (System:: TObject * Sender, System:: TObject * Source, int X, int Y, TDragState State, bool & Accept);
__property TDragOverEvent OnDragOver = {read = FOnDragOver, write = FOnDragOver}; 

TdragState indicates the state of control in relation to another control. The possible cases are:

Value Meaning
dsDragEnter
The mouse enters the control.
dsDragMove
As the mouse moves over the control.
dsDragLeave
The mouse leaves the control.


OnMouseDown

Occurs when the user clicks a mouse button when the mouse pointer is over the control.

 enum {TMouseButton mbLeft, mbRight, mbMiddle};

enum {Classes__1 ssShift, ssAlt, ssCtrl, ssLeft, ssRight, ssMiddle, ssDouble};
typedef TShiftState September;

typedef void __fastcall (__closure * TMouseEvent) (System:: TObject * Sender, TMouseButton Button, Classes:: TShiftState Shift, int X, int Y);

__property TMouseEvent OnMouseDown = {read = FOnMouseDown, write = FOnMouseDown}; 

Shift parameters respond to the shift keys and mouse buttons. Shift keys are the Shift, Ctrl and Alt X and Y are the pixel coordinates of the mouse pointer in the client area of ​​the sender.

Following the example Requires a form with a four-paneled bar status. (Set the Width of the status panels to 150 Before running this example). When the user presses a mouse button, moves the mouse, and releases the mouse button, a rectangle is drawn on the form. When the mouse button is released, the rectangle appears on the form's canvas. Its top-left and bottom-right corners Are defined by the location of the mouse pointer When the user pressed and released the mouse button. While the user drags the mouse, the location of the top, left, bottom, and right sides of the rectangle Are Displayed in the status bar.

 int startx, StartY / / Declare at the top of the form's unit

/ / Use this code as the OnMouseDown event handler of the form:

void __fastcall TForm1:: Button1MouseDown (TObject * Sender, Button TMouseButton, TShiftState Shift, int X, int Y) {
	StartX = X;
	StartY = Y;
}

/ / Use this code as the OnMouseUp event handler of the form:

void __fastcall TForm1:: FormMouseUp (TObject * Sender, Button TMouseButton, TShiftState Shift, int X, int Y) {
	Form1-> Canvas-> Rectangle (StartX, StartY, X, Y);
	StatusBar1-> Panels [0] -> Text = "";
	StatusBar1-> Panels [1] -> Text = "";
	StatusBar1-> Panels [2] -> Text = "";
	StatusBar1-> Panels [3] -> Text = "";

}

/ / Use this code as the OnMouseMove event handler of the form:

void __fastcall TForm1:: FormMouseMove (TObject * Sender, TShiftState Shift, int X, int Y)
{
if (Shift.Contains (ssLeft)) / / make sure button is down
{
if (Y> StartY) {
	StatusBar1-> Panels [0] -> Text = "Top:" + IntToStr (StartY)
	StatusBar1-> Panels [2] -> Text = "Bottom:" + IntToStr (Y);
}
else {
	StatusBar1-> Panels [0] -> Text = "Top:" + IntToStr (Y);
	StatusBar1.Panels [2]. Text = "Bottom:" + IntToStr (StartY)
}
if (X> StartX) {
	StatusBar1-> Panels [1] -> Text = "Left:" + IntToStr (StartX)
	StatusBar1-> Panels [3] -> Text = "Right:" + IntToStr (X);
}
else {
	StatusBar1-> Panels [1] -> Text = "Left:" + IntToStr (X);
	StatusBar1-> Panels [3] -> Text: = "Right:" + IntToStr (StartX)
}
}
} 


OnMouseMove

Occurs when the user moves the mouse while the mouse pointer is over the control.

 enum {Classes__1 ssShift, ssAlt, ssCtrl, ssLeft, ssRight, ssMiddle, ssDouble};
typedef TShiftState September;

typedef void __fastcall (__closure * TMouseMoveEvent) (System:: TObject * Sender, Classes:: TShiftState Shift, int X, int Y);

__property TMouseMoveEvent OnMouseMove = {read = FOnMouseMove, write
= FOnMouseMove}; 

Shift parameters respond to the shift keys and mouse buttons. Shift keys are the Shift, Ctrl and Alt X and Y are the pixel coordinates of the mouse pointer in the client area of ​​the sender.

Following the two labels when to code updates the mouse pointer is moved. You Have The code assumes two labels on the form, and lbVert lbHorz. If you attach this code to the OnMouseMove event of a form, lbHorz Continually displays the horizontal position of the mouse pointer, and lbVert Continually displays the vertical position of the mouse pointer while the pointer is over the form.

 void __fastcall TForm1:: FormMouseMove (TObject * Sender, TShiftState Shift, int X, int Y)
{
	char xPos [10];
	char yPos [10];

	itoa (X, xPos, 10);
	itoa (Y, yPos, 10);

	lbHorz-> Caption = xPos;
	lbVert-> Caption = yPos;
} 


OnMouseUp

Occurs when the user releases the mouse button is pressed cusando mouse pointer is over the control.

 enum {TMouseButton mbLeft, mbRight, mbMiddle};

enum {Classes__1 ssShift, ssAlt, ssCtrl, ssLeft, ssRight, ssMiddle, ssDouble};
typedef TShiftState September;

typedef void __fastcall (__closure * TMouseEvent) (System:: TObject * Sender, TMouseButton Button, Classes:: TShiftState Shift, int X, int Y);

__property TMouseEvent OnMouseUp = {read = FOnMouseUp, write = FOnMouseUp}; 

Shift parameters respond to the shift keys and mouse buttons. Shift keys are the Shift, Ctrl and Alt X and Y are the pixel coordinates of the mouse pointer in the client area of ​​the sender.

The Following code draws a rectangle When the user presses a mouse button, moves the mouse, and releases the mouse button. When the mouse button is released, the rectangle appears on the form's canvas. Its top-left and bottom-right corners Are defined by the location of the mouse pointer When the user pressed and released the mouse button.

 int startx, StartY / / Declare in interface section of form's unit

void __fastcall TForm1:: FormMouseDown (TObject * Sender, Button TMouseButton, TShiftState Shift, int X, int Y)
{
	StartX = X;
	StartY = Y;
}
void __fastcall TForm1:: FormMouseUp (TObject * Sender, Button TMouseButton, TShiftState Shift, int X, int Y)
{
	Form1-> Canvas-> Rectangle (StartX, StartY, X, Y);
} 
Loading
copyright © 2007-2024  www.alciro.org  All rights reserved.         
Share |