| |

VerySource

 Forgot password?
 Register
Search
View: 1548|Reply: 3

Continue to ask: Why is it so difficult to draw a rectangular frame on the window. depressed

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-11 20:30:01
| Show all posts |Read mode
Here is the code,
void __fastcall TForm1 :: FormCreate (TObject * Sender)
{
Brush-> Style = bsClear;
}
// ---------------------------------------------
void __fastcall TForm1 :: FormMouseDown (TObject * Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
   if (Shift.Contains (ssLeft))
   bMouseDownFlag = true;
   pt.x = X;
   pt.y = Y;
}
// ------------------------------------------------ ---
void __fastcall TForm1 :: FormMouseMove (TObject * Sender, TShiftState Shift,
      int X, int Y)
{
if (bMouseDownFlag)
{
this-> Refresh ();
this-> Canvas-> MoveTo (pt.x, pt.y);
this-> Canvas-> LineTo (pt.x, Y);
this-> Canvas-> MoveTo (pt.x, Y);
this-> Canvas-> LineTo (X, Y);
this-> Canvas-> MoveTo (X, Y);
this-> Canvas-> LineTo (X, pt.y);
this-> Canvas-> MoveTo (X, pt.y);
this-> Canvas-> LineTo (pt.x, pt.y);
}
}
// ---------------------------------------
void __fastcall TForm1 :: FormMouseUp (TObject * Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
    if (bMouseDownFlag)
    {this-> Refresh ();
    this-> Canvas-> Rectangle (pt.x, pt.y, X, Y);
    bMouseDownFlag = false;}
}
Depressed, the problem now is that if you remove the code Brush-> Style = bsClear in FormCreate, then the function of drawing a rectangle on the form can be completely realized, and every time a new rectangle is drawn, the previous rectangle drawn will be erased.
But after adding the code Brush-> Style = bsClear; in FormCreate, the problem came, first 1. There are many overlapping traces in the process of drawing a rectangle, 2. Each time a new rectangle is drawn, the previous rectangle drawn first will not be erased.
Why is this happening? How to deal with it. I want to add the code Brush-> Style = bsClear in FormCreate to draw a rectangle in the form, and overcome the two problems above, please help
Thank you
Reply

Use magic Report

0

Threads

16

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-4-8 18:00:01
| Show all posts
Use pmXor to draw once to erase the original, and then draw it again, and use the rectangle directly without using lineto several times
So it ’s better to change your move
Reply

Use magic Report

0

Threads

12

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-4-9 03:30:01
| Show all posts
Brush-> Style = bsClear
To
Brush-> Style = bsBlod
Reply

Use magic Report

0

Threads

5

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-4-9 16:15:50
| Show all posts
Wow    ! I am also the only one who still uses this software.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list