First and foremost, teach you kids to take interest in non-funky stuff. This way, you will send an important message: most interesting things lie much deeper then the outer shell. Make your application
really interesting, not due to funky colors and shapes. If you need to educate good taste, first learn good taste by yourself. This is not easy, but when you get it (I don't know hot to tell you are ready though, many never ever come to it :-)), you will know yourself what you can do.
Now, back to technical issues. This is a pretty big topic. All graphics is rendered in handling of the Windows message WM_PAINT. The window does not store any information on the graphics, so if a part of a form is closed by the other window, and then shown again, it will send you the message again. To handle it, you need to override the method
OnPaint
or handle the event
Paint
. Don't repeat the common mistake: use the instance of
System.Drawing.Graphics
passed to you in the event arguments, don't create an instance.
For animated or interactive behavior, you need to change data used in rendering and invalidate the scene using
Control.Invalidate
. You can use
Invalidate
with parameters (
Region
or
Rectangle
) to invalidate only a part of the scene and avoid excessive redrawing, to improve performance.
Using these techniques, you can render arbitrary image in custom controls (including
Form
) and implement animation.
Drawing Lines between mdi child forms[
^],
capture the drawing on a panel[
^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[
^].
For animation, you will need to develop a moving scenario using a separate thread. Basically, you need to have some data representing the scene or its parameters. In the thread, you should change this data step by step. On each step, you need to notify the UI thread on the change, so the scene could be fully or partially re-drawn, via a call to
Invalidate
. The problem is that you cannot call anything related to UI from non-UI thread. Instead, you need to use the method
Invoke
or
BeginInvoke
of
System.Windows.Threading.Dispatcher
(for both Forms or WPF) or
System.Windows.Forms.Control
(Forms only).
You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[
^],
Problem with Treeview Scanner And MD5[
^].
See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[
^],
Control events not firing after enable disable + multithreading[
^].
To avoid flicker in animated or interactive rendering, always use
double buffering:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered.aspx[
^].
There is one more interesting thing you can use: non-rectangular controls, including forms. To have them, you simply need to assign its property
Region
to some non-rectangular
Region
instance. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.region.aspx[
^].
This is not so simple and will need some practice. I would advise not to afraid it. Speaking of your "more by my son than me": you would never interest your son in this stuff you are not really interested by yourself. So, huge perseverance and perfectionism is not a bad thing at all.
There is a simpler alternative though, if you switch to WPF from Forms. There are different levels of imagine in WPF, but almost everything I mentioned before is already done for you: animation, rendering, zooming/panning and a lot more. Basically, instead of handling events, you can simply have an instance of the
Canvas
, put all kinds of objects on it and move them around. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.aspx[
^].
On top of it, you could have animations. Please see:
http://msdn.microsoft.com/en-us/library/ms752312.aspx[
^].
Of course, you can always do self-made animation, to model more complex motion, with thread. You need to do it the same way I described above, with UI thread invocation mechanism.
This is just one WPF approach, but it looks like it's the closest to what you want.
Now, it leaves for sounds. You see, my answer is already too big for this forum. Consider this first, ask you follow-up questions. Sounds are easier and do not depend on the UI library. Let me find some more time later, to write about them…
—SA