Click here to Skip to main content
15,884,473 members

Graphic is deleted when is moved.

Таньо Тодоров Иванов asked:

Open original thread
Hello!
I have a tryed from several days to solve my problem but without any result, so will ask here.

I have creage a graphic object and draw on it some shapes, like lines, rectangles etc.
I do not write any code in the Paint event and all code is just in the MouseUp, Down and Move Events.

-=The problem is=-
When i move, minimize, resize the picture, a partfrom the graphic is erased...
The same efect is when a window is on top of the program..

Here i will give you the code from my events to see what i'm doing for a line object:
----------------------------------------------------------
C#
<pre lang="xml">
private void pbx_MouseDown(object sender, MouseEventArgs e)
        {
            PenList.Color = MainForm.btnColor1.BackColor;
            PenList.Width = float.Parse(MainForm.tbxSize.Text);

            StartPoint = e.Location;
            EndPoint = StartPoint;

            MouseIsDown = true;
        } 

----------------------------------------------------------
C#
private void pbx_MouseMove(object sender, MouseEventArgs e)
       {
           EndPoint = e.Location;
           PenList.Color = MainForm.btnColor1.BackColor;
           PenList.Width = float.Parse(MainForm.tbxSize.Text);
           if (e.Button == MouseButtons.Left)
           {
               if (MainForm.btnLine.Checked && MouseIsDown == true)
               {
                                 ControlPaint.DrawReversibleLine(Picture.PointToScreen(StartPoint), Picture.PointToScreen(EndPoint), Color.Black);
                   EndPoint = new Point(e.X, e.Y);
                   ControlPaint.DrawReversibleLine(Picture.PointToScreen(StartPoint), Picture.PointToScreen(EndPoint), Color.Black);
               }
           }

----------------------------------------------------------
C#
private void pbx_MouseUp(object sender, MouseEventArgs e)
        {
            MouseIsDown = false;
            EndPoint = e.Location;
            PenList = MainForm.CustomPen;
            PenList.Color = MainForm.btnColor1.BackColor;
            PenList.Width = float.Parse(MainForm.tbxSize.Text);
       
            if (MainForm.btnLine.Checked)
            {
                Graphic.DrawLine(PenList, StartPoint, EndPoint);
            }
        }


Thanks.
Tags: C#, Windows, Graphics, Forms, Drawing

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900