Perfect three cases of Borland C ++ Builder visual control

zhaozj2021-02-16  51

Perfect three cases of Borland C Builder visual control

Wang Guanghong

The author has accumulated a little experience in programming, communicating with you, and improves together.

One. Let PageControl's tabsheet "bounce out"

Effect

People who have used PageControl know that the header of the PageControl ActivePage is more "flat", there is no "pop-up" three-dimensional effect, the author has improved the effect of "pop-up".

Add the following code in the OnDrawTab event:

Void __fastcall tsqlbuilderform :: PageControl1drawTab

TCUSTOMTABCONTROL * Control, Int TabINDEX, Const Treat & Re,

Bool Active

{

Byte Red0, Red1, Green0, Green1, Blue0, Blue1

IF (Active)

{

RED0 = 0;

RED1 = 15;

Green0 = 55;

Green1 = 200;

BLUE0 = 135;

Blue1 = 240;

}

Else

{

RED0 = 51;

RED1 = 101;

Green0 = 91;

Green1 = 200;

Blue0 = 91;

BLUE1 = 200;

}

INTH;

H = Rect.bottom - Rect.top - 2;

BYTE CLR, CLG, CLB;

Int CLTMP;

INT i = 0;

FLOAT C = 0.4; // Light position

Setbkmode (Control-> canvas-> handle, transparent);

For (; i

{

CLTMP = Red0 floor (Double) I / DOUBLE (H) * (Double) (Red1 - RED0) 0.5) / C;

IF (CLTMP <0) CLTMP = 0;

Else IF (CLTMP> 255) CLTMP = 255;

CLR = Byte (CLTMP);

CLTMP = Green0 Floor (Double) I / Double (H) * (Double) (Green1 - Green0) 0.5) / C;

IF (CLTMP <0) CLTMP = 0;

Else IF (CLTMP> 255) CLTMP = 255;

CLG = BYTE (CLTMP);

CLTMP = Blue0 Floor (Double) I / Double (H) * (Double) (Blue1 - Blue0) 0.5) / C;

IF (CLTMP <0) CLTMP = 0;

Else IF (CLTMP> 255) CLTMP = 255;

CLB = Byte (CLTMP);

Control-> canvas-> pen-> color = tcolor (RGB (CLR, CLG, CLB);

Control-> Canvas-> Moveto (Rect.Left 1, Rect.top i 1);

Control-> canvas-> lineto (Rect.right - 2, Rect.top i 1);

}

For (; i

CLTMP = Red0 Floor (Double) (H-I) / Double (H) * (Double) (Red1 - RED0) 0.5);

IF (CLTMP <0) CLTMP = 0;

Else IF (CLTMP> 255) CLTMP = 255;

CLR = Byte (CLTMP);

CLTMP = Green0 Floor ((Double) (H-I) / Double (H) * (Green1 - Green0) 0.5);

IF (CLTMP <0) CLTMP = 0;

Else IF (CLTMP> 255) CLTMP = 255;

CLG = BYTE (CLTMP);

CLTMP = Blue0 Floor ((Double) (H-I) / DOUBLE (H) * (Blue1 - Blue0) 0.5);

IF (CLTMP <0) CLTMP = 0;

Else IF (CLTMP> 255) CLTMP = 255;

CLB = Byte (CLTMP);

Control-> canvas-> pen-> color = tcolor (RGB (CLR, CLG, CLB);

Control-> Canvas-> Moveto (Rect.Left 1, Rect.top i 1);

Control-> canvas-> lineto (Rect.right - 2, Rect.top i 1);

}

Ansistring str = pageControl1-> Pages [Tabindex] -> CAPTION;

INT OFFSET = 0;

IF (pageControl1-> images! = null&&! Active) {

Graphics :: Tbitmap * bmp = new graphics :: tbitmap

TimageList * img = Dynamic_cast (pageControl1-> images);

Img-> getBitmap (pageControl1-> pages [Tabindex] -> ImageIndex, BMP); Control-> Canvas-> DRAW (Rect.Left 2, Rect.top 1, BMP);

OFFSET = BMP-> Width-10;

DELETE BMP; BMP = NULL;

}

Control-> canvas-> Textout (Rect.right - Rect.Lect.right - Control-> Canvas-> TextWidth (STR)) / 2,

RECT.TOP (Rect.Bottom - Rect.top - Control-> Canvas-> TextHeight (STR)) / 2,

STR);

}

two. Let StringGrid "draw" zebra crossing:

different color

Every line of StringGrid is the same color, and Cell is easier to look at. We can "draw" between the adjacent ROW in the OnDrawcell event, which makes people feel at a glance, no longer look at it.

Void __fastcall tform :: stringgriddrawcell (TOBJECT * SENDER,

Int Acol, Int, Tgrt & Rect, TGRIDDRAWSTATE STATE

{

TstringGrid * SG = Dynamic_cast (Sender);

IF (sg) {

Try

{

IF (Arow> = SG-> fixedrows && acol> = sg-> fixedcols)

{

IF (AROW% 2 == 0)

{

SG-> canvas-> brush-> color = (tcolor) 0x00E6FADC;

}

Else

{

SG-> canvas-> brush-> color = (tcolor) 0x00fbefd5;

}

}

Else {

SG-> canvas-> font-> color = clblack;

SG-> canvas-> brush-> color = (tcolor) 0x00ddddddd;

}

SG-> Canvas-> FillRect (RECT);

DrawText (SG-> canvas-> Handle, SG-> Cells [ACOL] [AROW] .c_str (), -1, (rect *) & Rect, Dt_SingLine | DT_VCenter | DT_Center);

}

Catch (Exception & Exception)

{

Application-> Showexception (& Exception);

Return;

}

}

}

three. Let ComboBox open menu

When using ComboBox, you must click on it

The drop-down menu will open, it is a bit inconvenient. The author inherits ComboBox, making a named AutoComboBox control, when the mouse enters the AutoComboBox area, it will automatically open the drop-down menu.

code show as below:

.h

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

#ifndef AutoComboBOBOXH

#define autocomboBOXH

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

#include

#include

#include

#include

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

Class Package TautoCombox: Public Tcombobox

{

Private:

TTIMER * TIMER;

Rect R;

Void __fastcall newcomboBOBOXWP (TMESSAGE & MSG);

Void __fastcall timetimer (TOBJECT * Sender);

Void __fastcall (__closure * OldcomboBoxwp) (TMESSAGE & Message);

protected:

PUBLIC:

__fastcall tautocomboX (tComponent * Owner); __ fastcall ~ tautocomboX (void);

__publish:

}

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

#ENDIF

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

.cpp

#include

#pragma HDRSTOP

#include "autocomboBOX.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 (TautocomboBox *)

{

New TautocomboBox (NULL);

}

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

__fastcall tautocomboBOBOX :: TAUTOCOMBOBOX (Tcomponent * Owner)

: TcomboBox (Owner)

{

Timer = new TTIMER (this);

Timer-> enabled = false;

Timer-> interval = 200;

Timer-> Ontimer = TIMERTIMER;

OldcomboBoxwp = this-> windowproc;

This-> WINDOWPROC = NewcomboBoxWP;

}

__fastcall tautocomboBOBOX :: ~ TautocomboBox (void)

{

DELETE TIMER;

}

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

Namespace AutoCombox

{

Void __fastcall package register ()

{

TcomponentClass Classes [1] = {__ClassID (TAUTOCOMBOBOX)};

Registercomponents ("WGHSOFT", CLASS, 0);

}

}

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

Void __fastcall tautocombox :: timerTimer (TOBJECT * Sender)

{

Point Pos;

GetCursorpos (& POS);

IF (! (pos.x> r.left && pos.x r.top&& pos.y

this-> DroppedDown = false;

Timer-> enabled = false;

}

}

/ / -------------------------------------------------------------------------------------------- --------------------------- void __fastcall tautocombox :: NewcomboBoxwp (TMESSAGE & MSG)

{

Switch (msg.msg)

{

Case CM_MOUSEENTER:

{

This-> DroppedDown = true;

Msg.result = true;

Break;

}

Case CM_MouseLeave:

{

Point Pos;

Timer-> enabled = true;

GetCursorpos (& POS);

This-> Perform (CB_GetDroppedControlRect, 0, LPARAM (& R));

IF (! (pos.x> r.left && pos.x r.top&& pos.y

this-> DroppedDown = false;

Timer-> enabled = false;

}

Msg.result = true;

Break;

}

Case WM_DESTROY:

{

Break;

}

}

OldcomboBoxWP (MSG);

}

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

New Post(0)