Click here to Skip to main content
15,881,248 members
Home / Discussions / C#
   

C#

 
GeneralRe: Multi-threading Pin
Heath Stewart29-Jan-04 12:55
protectorHeath Stewart29-Jan-04 12:55 
GeneralDatabase Problem, PLEASE HELP Pin
gls2ro29-Jan-04 4:24
gls2ro29-Jan-04 4:24 
Generalconvert web form to windows form Pin
OmegaSupreme29-Jan-04 4:19
OmegaSupreme29-Jan-04 4:19 
GeneralRe: convert web form to windows form Pin
Colin Angus Mackay29-Jan-04 14:40
Colin Angus Mackay29-Jan-04 14:40 
GeneralRe: convert web form to windows form Pin
OmegaSupreme29-Jan-04 23:43
OmegaSupreme29-Jan-04 23:43 
GeneralRe: convert web form to windows form Pin
Kentamanos29-Jan-04 19:22
Kentamanos29-Jan-04 19:22 
GeneralRe: convert web form to windows form Pin
OmegaSupreme29-Jan-04 23:48
OmegaSupreme29-Jan-04 23:48 
GeneralWeird problem Pin
cmedia29-Jan-04 3:57
susscmedia29-Jan-04 3:57 
I am getting a weird problem with the tabpage here is a step by step account of how to reproduce my problem


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











GeneralRe: Weird problem Pin
hxxbin29-Jan-04 11:59
hxxbin29-Jan-04 11:59 
GeneralDrawing a rectangle Pin
thomasa29-Jan-04 3:24
thomasa29-Jan-04 3:24 
GeneralRe: Drawing a rectangle Pin
Heath Stewart29-Jan-04 4:06
protectorHeath Stewart29-Jan-04 4:06 
GeneralRe: Drawing a rectangle Pin
thomasa29-Jan-04 23:38
thomasa29-Jan-04 23:38 
GeneralRe: Drawing a rectangle Pin
Heath Stewart30-Jan-04 3:16
protectorHeath Stewart30-Jan-04 3:16 
GeneralRe: Drawing a rectangle Pin
thomasa2-Feb-04 0:39
thomasa2-Feb-04 0:39 
GeneralRe: Drawing a rectangle Pin
thomasa2-Feb-04 2:04
thomasa2-Feb-04 2:04 
GeneralRe: Drawing a rectangle Pin
Heath Stewart2-Feb-04 2:47
protectorHeath Stewart2-Feb-04 2:47 
GeneralSorting in cyclic order Pin
Shree29-Jan-04 2:26
Shree29-Jan-04 2:26 
GeneralRe: Sorting in cyclic order Pin
Heath Stewart29-Jan-04 3:57
protectorHeath Stewart29-Jan-04 3:57 
GeneralRe: Sorting in cyclic order Pin
Shree29-Jan-04 6:07
Shree29-Jan-04 6:07 
GeneralVoice in C# AGAIN Pin
Abkarino29-Jan-04 1:00
Abkarino29-Jan-04 1:00 
GeneralRe: Voice in C# AGAIN Pin
Heath Stewart29-Jan-04 2:35
protectorHeath Stewart29-Jan-04 2:35 
GeneralCall Webservice from windows client problem Pin
Mazdak28-Jan-04 23:56
Mazdak28-Jan-04 23:56 
GeneralRe: Call Webservice from windows client problem Pin
Heath Stewart29-Jan-04 3:20
protectorHeath Stewart29-Jan-04 3:20 
GeneralRe: Call Webservice from windows client problem Pin
Mazdak29-Jan-04 4:54
Mazdak29-Jan-04 4:54 
GeneralRe: Call Webservice from windows client problem Pin
Heath Stewart29-Jan-04 6:52
protectorHeath Stewart29-Jan-04 6:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.