The surface is label, actually MEMO

zhaozj2021-02-16  95

In the project, you need such a control:

The usual state is like a label. When the mouse is double-click to get the editable state, after the editable status is lost, it will be restored to the horizontal state such that there is a lot of software, mainly for the text box on the graphical interface, but I am looking for Ah, I haven't found it, I have to write one by myself:

1: Basic principle

Using a Label control and an MEMO control simulation. The MEMO control is time to hide when the mouse double-click Label, display and modify the location and size of MEMO, and assign the label's CAPTION to the Text. Finally, when MEMO lost focus, hide Memo.

Two: difficult

When editing MEMO, you should also return to the usual state when you click on other regions. Because the transfer of the focus, the OneXIT event cannot be captured. The final solution is to use capture cm_mouseeleave, WM_KILLFOCUS messages, setcapture in cm_mouseeleave, and determine the position of the mouse in the onmousedown event, if you are in the control: setfocus (null); WM_KILLFOCUS Doing hidden Memo et al.

Three: How to use

1, add components (TNOTELABEL, TFLOATMEMO)

2. Place several TNOTELABELs and a TFLOATMEMO on the Form and set the TNOTELABEL's EditMemo property to TFLoatMemo. Or in the program, you can do it.

Four: Implement code

Oh, listed out, please refer to it, please correct (email: wu_07@sina.com)

/ / -------------------------------------------------------------------------------------------- --------------------------- # iFndef floatmemoh # Define floatmemoh // --------------- -------------------------------------------------- ---------- # cDE

#include

#include

#include

/ / -------------------------------------------------------------------------------------------- ---------------------------

Class Package Tfloatmemo: Public TMEMO

{

Private:

TNotifyEvent fonmouselave;

TNOTIFYEVENT FONLOSEFOCUS;

Message void __fastcall cmmouselave (tMME & MSG);

Message void __fastcall WMKILLFOCUS (TMESSAGE & MSG);

protected:

Virtual void __fastcall loaded;

PUBLIC:

__fastcall tfloatmemo (tComponent * Owner);

BOOL B;

__publish:

Begin_MESSAGE_MAP

Message_handler (cm_mouseeleave, tmessage, cmmouseelease)

Message_handler (WM_KILLFOCUS, TMESSAGE, WMKILLFOCUS)

END_MESSAGE_MAP (TControl)

__property classes :: TNOTIFYEVENT ONMOUSELEAVE = {read = fonmouseeleave, Write = fonmouseeleave}

__property classes :: TNOTIFYEVENT onlinefocus = {read = fonlosefocus, Write = FONLOSEFOCUS}

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

#ENDIF

/ / -------------------------------------------------------------------------------------------- --------------------------- # include

#pragma HDRSTOP

#include "floatmemo.h"

#pragma package (smart_init)

/ / -------------------------------------------------------------------------------------------- ---------------------------

// ValidcTrcheck IS Used To Assure That The Components Created Do Not Have

// ann of Pure Virtual functions.

//

Static Inline Void Validctrcheck (Tfloatmemo *)

{

New Tfloatmemo (NULL);

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

__fastcall tfloatmemo :: tfloatmemo (tcomponent * oowner)

: TMEMO (OWNER)

{

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Namespace floatmemo

{

Void __fastcall package register ()

{

Tcomponentclass classes [1] = {__classid (tfloatmemo)};

RegisterComponents ("Additional", Classes, 0);

}

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tfloatmemo :: loaded (void)

{

This-> CTL3D = FALSE;

This-> visible = false;

THIS-> CURSOR = Crarrow;

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tfloatmemo :: cmmouselave (tMMouseLelave (TMESSAGE & MSG)

{

TMEMO :: Dispatch (& MSG);

IF (fonmouseLeave) FonmouseLeave (this);

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tfloatmemo :: WMKILLFOCUS (TMESSAGE & MSG)

{

TMEMO :: Dispatch (& MSG);

IF (FONLOSEFOCUS) FONLOSEFOCUS (THIS);

}

/ / -------------------------------------------------------------------------------------------- ----------------------------------------------------- -------------------------------------------------- ---- # i iDef notlabelh # Define NoteLabelh // ---------------------------------------------------------------------- ------------------------------------- # include # include

#include

#include

#include "floatmemo.h"

/ / -------------------------------------------------------------------------------------------- ---------------------------

Class Package TNOTELABEL: Public TCUSTOMLABEL

{

Private:

Tfloatmemo * feditmemo;

Void __fastcall setEDitmemo (tfloatmemo * MEMO);

Dynamic void __fastcall dblclick (void);

Void __fastcall editmemouselave (TOBJECT * Sender);

Void __fastcall EditMemomouseup (Tobject * Sender, TMouseButton Button, TshiftState Shift, INT X, INT Y);

Void __fastcall editmemolosefocus (TOBJECT * Sender);

protected:

Void __fastcall paint (void);

Virtual void __fastcall loaded;

Message void __fastcall WMSETTEXT (TMESSAGE & MSG);

PUBLIC:

__fastcall TNOTELABEL (Tcomponent * Owner);

__publish:

__property tfloatmemo * editmemo = {read = feditmemo, Write = setEditmemo};

__property align = {Default = 0};

__property alignment = {default = 0};

__Property Anchors = {Default = 3};

__Property AutoSize = {Default = 0};

__property bidimode;

__property capen;

__Property color = {default = -2147483643};

__property constraints;

__property Dragcursor = {Default = -12};

__Property Dragkind = {Default = 0};

__Property DragMode = {Default = 0};

__Property enabled = {default = 1};

__property focuscontrol;

__property font;

__Property ParentBidimode = {Default = 1};

__property parentcolor = {default = 1};

__property PARENTFONT = {Default = 1}; __Perty Parentshowhint = {Default = 1};

__property popupmenu;

__Property Showaccelchar = {Default = 1};

__Property Showhint;

__property transparent = {default = 0};

__Property Layout = {Default = 0};

__Property Visible = {Default = 1};

__Property WordWrap = {Default = 0};

__property onclick;

__property onContextPopup;

__property ondblclick;

__property ondragdrop;

__Property OnDragover;

__property oneunddock;

__property oneunddrag;

__property onmousedown;

__property onmousemove;

__property onmouseup;

__property onmounter;

__property onmouselave;

__property onstartdock;

__property onstartdrag;

Begin_MESSAGE_MAP

Message_handler (WM_SETTEXT, TMESSAGE, WMSETTEXT)

END_MESSAGE_MAP (TControl)

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

#ENDIF

/ / -------------------------------------------------------------------------------------------- --------------------------- # include

#pragma HDRSTOP

#include "notlabel.h"

#pragma package (smart_init)

/ * Standard DrawText Flags * /

#define lv_ml_dt_flags (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)

#define lv_fl_dt_flags (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)

#define lv_sl_dt_flags (DT_TOP | DT_EDITCONTROL | DT_SINGLINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)

/ / -------------------------------------------------------------------------------------------- ---------------------------

// ValidcTrcheck IS Used To Assure That The Components Created Do Not Have

// ann of Pure Virtual functions.

//

Static Inline Void ValidcTrcheck (TNOTELABEL *)

{

New TNOTELABEL (NULL);

}

/ / -------------------------------------------------------------------------------------------- ---------------------------__ fastcall TNotelele :: TNOTELABEL (Tcomponent * Owner)

: TCUSTOMLABEL (OWNER)

{

AutoSize = false;

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Namespace NoteLabel

{

Void __fastcall package register ()

{

Tcomponentclass classes [1] = {__ClassID (TNOTELABEL)};

RegisterComponents ("Additional", Classes, 0);

}

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tnotelabel :: Paint (void)

{

Canvas-> font = font;

Canvas-> brush-> color = color;

IF (Transparent)

SetBkmode (canvas-> handle, transparent);

Else

{

Setbkmode (canvas-> handle, opaque);

Canvas-> FillRect (RECT (0, 0, Width, Height);

}

Drawtextex (canvas-> handle, caption.c_str (), caption.Length (), & RECT (0, 0, Width

, Height, LV_ML_DT_FLAGS, NULL);

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tnotelabel :: WMSETTEXT (TMESSAGE & MSG)

{

Tcontrol :: Dispatch (& MSG);

Invalidate ();

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tnotelabel :: setEDitmemo (tfloatmemo * MEMO)

{

Feditmemo = MEMO;

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tnotelabel :: dblclick ()

{

IF (FeditMemo! = NULL)

{

FeditMemo-> onmouseup = EditMemomouseUp;

FeditMemo-> onmouseeleave = EditMemomouseLeave;

FeditMemo-> Onlosefocus = EditMEMOLosefocus;

Feditmemo-> boundsRect = BoundSRect;

Feditmemo-> text = caption;

Feditmemo-> show ();

:: setfocus (femitmemo-> handle);

FeditMemo-> SelectAll ();

}

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tnotelabel :: loaded ()

{

//

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tnotelabel :: EditMEMOLosefocus (Tobject * Sender)

{

TMEMO * CTL = Dynamic_cast

Sender;

IF (CTL == 0) Return;

CTL-> hide ();

CAPTION = CTL-> text;

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tnotelabel :: EditMemomouseLeave (TOBJECT * SENDER)

{

TwinControl * CTL = Dynamic_cast

Sender;

IF (CTL == 0) Return;

IF (getCapture ()! = CTL-> Handle) SetCapture (CTL-> Handle);

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tnotelabel :: EditMemomouseup (Tobject * Sender, TMousebutton Button, TshiftState Shift, Int x, int y)

{

TwinControl * CTL = Dynamic_cast

Sender;

IF (CTL == 0) Return;

IF (! PtinRect (0, 0, CTL-> Width, CTL-> Height), Point (X, Y)))

{

Releasecapture ();

:: setfocus (null);

}

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

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

New Post(0)