Sorry if i wasnt to clear here is a step by step account of how to
reproduce my problem and other detailed info about it
1) add a tabcontrol and then a tabpage to a form
2) add a custom contorl to the tabpage (a normal control eg label will
work as well but i
am using a custom control)
3) add functionality that allows you to drag the control/label (i just
use the controls
mousedown to start DoDragDrop, and then use the drag_enter/move events
of the tabpage to
make it drag)
4) now set a background image, some big image say 1mb and 1024x768 and
drag the
contorl/label, you should see that it is slow to paint the control
when dragging
HOW CAN I MAKE THE PAINTING SMOOTH?
I have tried double buffer overriding onpaintbackground etc.. but that
is not the solution
as if i add my control to a panel and then set the panels
backgroundimage to a large image
the painting is smooth!!!! So the panel does something to make
painting smooth that the
tabpage does not. The solution i have come across is detailed below
however it has a weird
problem which i will list below. For now use the following steps to
produce my problem
Start a new project
1) inherit from tabpage and produce a custom tabpage class with the
code below
public class MyTab : TabPage
{
public Image imagex;
public MyTab()
{
}
protected override void OnPaint(PaintEventArgs e)
{
if(imagex!=null)
{
e.Graphics.DrawImageUnscaled(imagex, 0, 0, imagex.Width,
imagex.Height);
}
base.OnPaint (e);
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
base.OnPaintBackground (pevent);
}
}
2) add tabcontrol to form and add the inherited tabpage to it
3) add user control to tabpage then add functionality to drag the
control
4) make an Image object in the and set it to a large image in the form
class name it
LARGE_IMAGE
e.g. Image LARGE_IMAGE = Image.FromFile(@"C:\image.jpg");
5) add 4 buttons to the form which the following in their click events
Button 1
========
tabpage.imagex = LARGE_IMAGE;
Button 2
========
tabpage.imagex = null;
Button 3
========
tabpage.BackGroundImage = LARGE_IMAGE;
Button 4
========
tabpage.BackGroundImage = null;
6) OK now that everythings ready we can begin the test! If you press
Button 1 you will see
that when you drag the control the image appears underneath it however
the painting isnt
very smooth but is smoother than in the first example above where you
set the
backgroundimage. Now if you press Button 2 so the tabpage.imagex is
set to null. painting
should be smooth again as no background is set. (Forget about the
backimage getting erased
and painting when u move the control i understand why that is
happening that is not the
Problem).
Now press Button 3 to set the tabpage's backgroundimage and drag the
control around it is
slow to paint now press button 4 to set the backgroundimage to null.
OK THIS IS THE WEIRD
PART, Press Button 1 and tabpage.imagex should paint SMOOTH!!!!! IT is
fine now.
I cant understand why this happens? It only paints smooth after
setting and unsetting the
tabpage's backgroundimage. I have tried doing the following
tabpage.BackGroundImage = LARGE_IMAGE;
tabpage.BackGroundImage = null;
tabpage.imagex = LARGE_IMAGE;
in the constructor of the inherited tabpage but that does not make it
smooth, i have added
the 3 lines of code to a seperate button again to no change. It seems
i have to add the
code to different buttons only then will it work!!! WIERD.
Please please can anyone shed any light on this situation? I want
smooth painting on the
tabpage with out pressing mulitples buttons LOL
"Bram" <bv*****@nospam.skynet.be> wrote in message news:<40***********************@news.skynet.be>...
Hi,
I (probably we) do not understand the 'dragging' part of your problem.
Could you explain it a little deeper, with a steps list or so like,
1. create a new form
2. add a tabcontrol, DockStyle.Fill
3. add a tabpage
4. set a background image of about 5 MB
and so on
I tried to reproduce your problem, but I don't experience any slowdowns.
Not at design-time, not at run-time.
Greetings,
Bram.