473,569 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Animation and windows progs

Hello,

I'm new to c# and have created an animation which draws directly
to the window, it uses the code below which all works. I would
like to know if this is the 'correct' way to do it - or would an
experienced c# programmer do it another way?

This part defines the screen and the graphics pad I'm drawing to:
Graphics screen = CreateGraphics( );
Graphics drawpadg = Graphics.FromIm age(drawpad);

Next, the background and the frames of animation
Bitmap back =
(Bitmap)Bitmap. FromStream(this .GetType().Asse mbly.GetManifes tResourceStream ("WindowsApplic ation1.skygroun d.gif"));
Bitmap lemframes =
(Bitmap)Bitmap. FromStream(this .GetType().Asse mbly.GetManifes tResourceStream ("WindowsApplic ation1.lemwalk. gif"));

Clear the pad I draw to
drawpadg.Clear( this.BackColor) ;

Copy the background and then the frame of animation to the draw pad.
drawpadg.DrawIm age(back, new Rectangle(0, 0, 400, 120), 0,
0, 400, 120, GraphicsUnit.Pi xel);
drawpadg.DrawIm age(lemframes, new Rectangle(x+lo[f], y,
lw[f], 46), lx[f], 0, lw[f], 46, GraphicsUnit.Pi xel);

Finally copy the draw pad to the screen
screen.DrawImag e(drawpad, 0, 0);

Then I dispose of everything afterwards (like a good little c# coder
:o)

I also want to start developing an application which allows you to
scroll around an image, and which lets you resize the window (and have
the scroll bars update). I cannot get the scroll bars to appear by
playing with the properties - how should I be doing this please?

Ta, James

Dec 28 '05 #1
3 2077
James,

It's hard to say if this is "right" or not.

I don't see you disposing of anything anywhere (the graphics instance,
the bitmaps, the streams, anything), so I can't say if that's correct.

On top of that, where is this code? Are you overriding your OnPaint
method, or in the Paint event handler? If it is not in either of these
places, then you aren't going to have a very smooth animation.

Finally, you can probably make this better. Since you are painting
every frame, you probably could pre-load the frames of the animation, so
that you don't have to incur the cost of loading while drawing.

Hope this helps.
"James" <c_********@yah oo.co.uk> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hello,

I'm new to c# and have created an animation which draws directly
to the window, it uses the code below which all works. I would
like to know if this is the 'correct' way to do it - or would an
experienced c# programmer do it another way?

This part defines the screen and the graphics pad I'm drawing to:
Graphics screen = CreateGraphics( );
Graphics drawpadg = Graphics.FromIm age(drawpad);

Next, the background and the frames of animation
Bitmap back =
(Bitmap)Bitmap. FromStream(this .GetType().Asse mbly.GetManifes tResourceStream ("WindowsApplic ation1.skygroun d.gif"));
Bitmap lemframes =
(Bitmap)Bitmap. FromStream(this .GetType().Asse mbly.GetManifes tResourceStream ("WindowsApplic ation1.lemwalk. gif"));

Clear the pad I draw to
drawpadg.Clear( this.BackColor) ;

Copy the background and then the frame of animation to the draw pad.
drawpadg.DrawIm age(back, new Rectangle(0, 0, 400, 120), 0,
0, 400, 120, GraphicsUnit.Pi xel);
drawpadg.DrawIm age(lemframes, new Rectangle(x+lo[f], y,
lw[f], 46), lx[f], 0, lw[f], 46, GraphicsUnit.Pi xel);

Finally copy the draw pad to the screen
screen.DrawImag e(drawpad, 0, 0);

Then I dispose of everything afterwards (like a good little c# coder
:o)

I also want to start developing an application which allows you to
scroll around an image, and which lets you resize the window (and have
the scroll bars update). I cannot get the scroll bars to appear by
playing with the properties - how should I be doing this please?

Ta, James

Dec 28 '05 #2
Hi Nicholas.

I am disposing of everything afterwards:

back.Dispose();
screen.Dispose( );
drawpadg.Dispos e();
lemframes.Dispo se();

The code is in the timer tick, and you're totally right in that I do
load the animation every frame which I know is wasteful and I intend to
correct that soon (ie to load the images in the public Form1(), but one
problem at a time :o)

Thanks

James

Dec 30 '05 #3
James wrote:
Hi Nicholas.

I am disposing of everything afterwards:

back.Dispose();
screen.Dispose( );
drawpadg.Dispos e();
lemframes.Dispo se();

The code is in the timer tick, and you're totally right in that I do
load the animation every frame which I know is wasteful and I intend to
correct that soon (ie to load the images in the public Form1(), but one
problem at a time :o)

Thanks

James


A (IMHO) better approach would be to just Invalidate your control in the
timer tick (and possibly increment a counter value/update the animation
variables) and paint everything in the OnPaint handler. This way, your
control will repaint properly when partially invalidated etc. And you
should not implement your own doublebuffering unless really needed. Look
at the Control.SetStyl e() and ControlStyles.D oubleBuffer instead.

HTH

Stefan
Dec 30 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3441
by: Brian Angliss | last post by:
I'm relatively new to scripting in JavaScript, so I'm not too surprised I'm having difficulty scripting up an animation effect for my personal site. What I'm trying to do is the following: When I go onMouseOver on a button in a nav bar, I want that button to switch to a different image while at the same time another blank image changes as...
6
1850
by: J. J. Cale | last post by:
Hi all I get different speeds from this animation in IE6 and Mozilla. Mozilla 1.7.3 runs this much faster than IE . I'm trying to get the results that Mozilla returns. IE is too slow!! Anyone know why? Is my code flawed and one browser is interpreting it correctly? Any help will be appreciated. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML...
3
5622
by: Stanislaw Findeisen | last post by:
Does anyone know how to create file shortcuts in Windows? The only way I know is like: --------------------------------------------------------------- import win32com.client wScriptShellObject = win32com.client.Dispatch("WScript.Shell") shortcutName = unicode("shortcut.lnk", "utf8")
3
3079
by: NL | last post by:
Hi, Does anybody know how to turn off the animation Windows does with a window as it's minimized/maximized to the taskbar? I have an app which, when minimized, syncs to any other open instances of the app and tells them to minimize. If I have more than a couple instances open, the user ends up waiting quite a while for all of windows to...
2
1304
by: Noor | last post by:
Hi All How some application shows animation to show if some progress/processing is going on. like especially in the end of some wizard, the application shows animation on a form, animation like we see when copying of files is being done. is that done by showing some animated gif? If an animated gif then how to display an animated gif...
7
3979
by: matt | last post by:
Hallo, I have to create a simple sprite movement; in VB6 I used the API BitBlt and all was very good. Using the NET graphical methods (not API) , the result is slow. Do you have a NET example about BitBlt and the sprite movement , because I'm a little in trouble in implementing it
3
2669
by: | last post by:
Can someone point me to some good info on how to do somoe simple animation on a form. Specifically, I want to have some tiles that when they are clicked, they flip over in place and reveal a number. Obviously the flipping part should be animated and the user interface should not have to wait for the tile animation to complete before another...
4
3651
by: =?Utf-8?B?dmluZWV0?= | last post by:
In WPF (even with considerable improvement in version 3.5), while running multiple animations in a single window, The performance of one animation suffers a lot. for example, i have two image transitions on two independent Canvases on a Grid. 1. is simple, slide transformation running, continously from left to right with multiple images....
4
13906
by: Sin Jeong-hun | last post by:
Most applications, including Windows Explorer, show some sort of 'wait' dialog with animation when a lengthy operation is going on. For example, When the Windows Explorer is searching for something, it shows a small dialog with a moving flashlight. I examined the explorer.exe and found that that was an avi file. Now that, I would like to do...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.