OnPaint - when moving the Form manually

G

Gidi

Hi,

I've a winform with no borders, and i still want to let the user the ability
to move the form, since i didn't find any property that allows that, i wrote
the following (simple) code:

private void MainForm_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown == true)
{
this.Location = new System.Drawing.Point(e.X, e.Y);
}
}

private void MainForm_MouseDown(object sender, MouseEventArgs e)
{

if (e.Button == MouseButtons.Left)
{
isMouseDown = true;
}

}

private void MainForm_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}


Now, when i move my form, i get it spread on all over the screen until i
release my mouse click.
I know that the answer is somewhere with OnPaint or something like that...

how can i fix that?

Thanks,
Gidi.
 
P

Peter Duniho

Gidi said:
[...]
Now, when i move my form, i get it spread on all over the screen until i
release my mouse click.
I know that the answer is somewhere with OnPaint or something like that...

how can i fix that?

It's unlikely your issue has anything to do with the Paint event. Of
course, unless you post a concise-but-complete code example it's
impossible to know for sure. But if you are seeing latent images of
your window from its previous locations, repainting the window itself
cannot possibly fix that. The only way for those latent images to be
made to go away is for the _other_ windows where those images have been
drawn to themselves be redrawn.

If those windows are not in your own process, then the issue isn't
something you can do anything about. And in fact, normally what you are
describing won't happen, except on lower-performance computers, which
almost no one has anymore. So without a proper code example, it's not
obvious at all why you're seeing what you're seeing, never mind how to
fix it (assuming you can at all).

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top