By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,868 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

Wierd problem

P: n/a
I have a peculiar problem,

I have a tabpage with a label control on it. When i set a background
image to the tabpage and drag the label around it has paint issues in
that it is slow, granted the image i am using is 5mb!!! HOWEVER...

I have inherited the tabpage created an Image reference in it, and
overrriden the onPaint method to draw the image

now if i press a button that sets the background image of the control
and drag it works really slow, however if i then set the backimage to
null and set my own image reference IT works FINE!!! No issues even a
5MB image. If i just set my own internal image first it isnt smooth
however setting it after the backimage ON/OFF does cause it to work.
However i cant set and unset the background image in code as that
does not make it work properly it has to happen in that order and via
a button etc. Could it be something todo with focus????

Could someone explain to me why this is happening? As i am unable to
understand what is happening, and a solution to my problem?
Thanks!!!!!!!!
Below is the code to my tabpage
public class TabWork : TabPage
{

public Image imagex;

public TabWork()
{

}

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);
}

}
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
"CMEDIA_SOUND" <ze*******@yahoo.co.uk> wrote in message
news:80**************************@posting.google.c om...
I have a peculiar problem,

I have a tabpage with a label control on it. When i set a background
image to the tabpage and drag the label around it has paint issues in
that it is slow, granted the image i am using is 5mb!!! HOWEVER...

I have inherited the tabpage created an Image reference in it, and
overrriden the onPaint method to draw the image

now if i press a button that sets the background image of the control
and drag it works really slow, however if i then set the backimage to
null and set my own image reference IT works FINE!!! No issues even a
5MB image. If i just set my own internal image first it isnt smooth
however setting it after the backimage ON/OFF does cause it to work.
However i cant set and unset the background image in code as that
does not make it work properly it has to happen in that order and via
a button etc. Could it be something todo with focus????

Could someone explain to me why this is happening? As i am unable to
understand what is happening, and a solution to my problem?
Thanks!!!!!!!!
Below is the code to my tabpage
public class TabWork : TabPage
{

public Image imagex;

public TabWork()
{

}

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);
}

}

Nov 15 '05 #2

P: n/a
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.

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.