Click here to Skip to main content
13,297,799 members (50,333 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I'm busy with a little app for my kiddie to practice math. I'm doing ok with generating some simple add and subtract sums, but the user interface is so not funky or appealing to a kid.

Using VS2010,, Windows Forms Application - I'm not familiar with much else than this - so guess best to stick with what I know

Any ideas on backgrounds, cool ways to display scores, animations, sounds etc that are easily implemented would be much appreciated (more by my son than me :))


Posted 6-Aug-12 10:41am
richcb 6-Aug-12 15:43pm
Patterncooler has easily adjustable backgrounds you can use.
Richard.Berry100 6-Aug-12 15:58pm
Ey richcb - that is soooo cool!!! Thanks so much! Already it looks so much better. Sure my kiddie is going to love it!
Richard.Berry100 6-Aug-12 18:56pm
How risky is it to donate to his website?
richcb 7-Aug-12 10:04am
I have not ever done it personally, but it is legitimate as far as I know. It was recommended to me by an instructor at school.
I really appreciate that you want to do it all by yourself, not to buy or download. This is what a real farther does! How else could you earn respect and educate your children on positive model?
My 5 for the question, and best wishes.
Richard.Berry100 6-Aug-12 16:01pm
Thanks Sergey - I think you must be a great dad then!
Thank you,.. trying to... the projects we did is just a small of it.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

It is in general a lot simpler to design custom user interfaces with WPF than WinForms. Its not that different in code behind, but the possibilityes are endless.

There is also Blend witch were created for designers...

BTW: Blend is designed to work together with WPF, and you can make some applications with is, that would have been extroardinary much work in WinForms. Take a look at these tow applications:

WPF Grand Prix[^]

WPF Rubik's Cube[^]

The last example is actually in VB.NET.

Richard.Berry100 6-Aug-12 16:15pm
Thanks Kenneth - I suspected there was probably a better way of doing this than Win Forms. I'm not a professional developer, and most of the apps I do are more database related. I've been keen to change to C# instead of vb, but every time I start an app in C#, I end up getting frustrated with syntax and for the sake of getting the job done fast, I end up in vb again. What is the future of WPF? Metro? I know nice looking user interfaces make people think you can write great code, but whats really best? Be interested to hear your opinion!
Let me note that, for your purpose, you can afford to ignore questionable future of any library. You got it now, use it. Use your sense of value -- you won't be able to predict crazy market-driven future where some good technologies may arise and some lousy win, and later better approach will be re-created anyway, but not always preserving your investment. Just do it. Nobody will break your instance of the OS you are using right now, after all, and it will continue to work for you on your computer. It's better to be ready for everything.

As to WPF and the future, let me tell you one important thing: the main drive is going out of Windows. WPF is almost not related to Windows API. And Microsoft and third parties actively work at post-Windows OS (Microsoft's code name "Midory"), where .NET (SLR, more exactly) will be the only platforms, right on top of HAL. I don't consider Windows 8 as anything serious, not even mentioning Metro (they can blow it as everything to make it a commercial success, but it won't make it serious).

From the other hand, these days only the Forms is multi-platform. I can run some of my Forms application on Linux, Mac OS X and more, because SLR is implemented for them (this is mostly Mono), and Forms is not standard, but ported, too, as well as ADO.NET and some other non-standard libraries.

That's why I described both Forms and WPF approach in my answer. WPF is easier to develop, in your case. You decide...
You are right, but I dedicate a more detailed answer on both Forms and WPF. Please see.
Nice sample applications referenced, a 5.
Kenneth Haugland 6-Aug-12 16:42pm
Thanks :)
Richard.Berry100 6-Aug-12 18:07pm
@Kenneth - The GP example is great, but a little beyond my current capability! Looks awesome though!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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[^],
Control events not firing after enable disable + multithreading[^].

To avoid flicker in animated or interactive rendering, always use double buffering:[^].

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:[^].

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:[^].

On top of it, you could have animations. Please see:[^].

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…

Richard.Berry100 6-Aug-12 17:01pm
WOW! I dont think if I went to University I would get so much excellent knowledge offered to me in a matter of minutes! My son does appreciate simple things - we walk in the bush, and make a simple bow and arrow from a tree branch and a string - he loves it more than all these fancy toys full of bling and fancy noises! He's not doing great in math at school, so I'm gonna start with something basic for the beta version :) I will (thanks only to your answers, try a WPF app :) - and you make a good point - work with whats available now, but as a non-professional, whats quick to learn, and not going to be obsolete in a year's time means a lot to me..
Ok... I just opened a new WPF project and I get a window called MainWindow.xaml - Now what! (I dont expect you to answer that - just wanted to show my level of (or lack thereof) development expertise :)
Kenneth Haugland 6-Aug-12 17:05pm
There would be a toolbox, and you can draw controls just like you did in WinForms.
That is true, but using Canvas is more high level, where the developer works immediately with visual UI elements, no need to pay attention for rendering detail and a lot more...
Richard.Berry100 6-Aug-12 19:07pm
LOL - ok found it - looks a lil different - thanks!
First of all, let me express how much I appreciate your bow and arrow thing. This is much more important and useful for development than all that computing, especially in early age. Knife, modeling clay, paper, rope, thread, needle, wooden sticks, paintbrush -- those things are the best and will always be the best.

And computer games can be just plain harmful; I know too many sad cases... But prohibition can cause the opposite effect, so it makes no sense. The only remedy I know it to attract attention to "real things". And the real things are simpler and deeper at the same time. And of course, "the real thing" is something which takes effort and requires creative approach. This way, few hours in a row spend at, say, a a single sand castle, maybe a simple one, can bring a lot more skills development and -- important -- the sense of accomplishment, than months dying behind a keyboard in attempts to pass idiotic game "levels".

However, computer work is also very creative and can be introduced when a child can read from screen (I am not talking watching pictures or animated cartoon which can come very early), and as a distinct step, when a child gets close enough in motoric skill to handle a keyboard. (I would prefer if it comes as a result of exercise with a rope, a pencil, a piece of paper though.) The same sense of accomplishment would come from making computer drawing (by the way, buy a pressure sensitive tablet -- modest investment more valuable then 100 timer more powerful computer), and, eventually... programming. (If your son ever comes to it, you will be competing, it looks like... :-). I have one simple criterion for creative and useful activity -- if it creates some artifacts. For example, drawing can result into a drawing file, which you both would like to store and preserve. If you create something you want to preserve -- even something simple -- you are doing right thing.

Now, you are more then welcome to ask further questions, but I'll probably answer later. You should understand the volume of attention I can devote to each question is limited, but of course I prefer answer interesting questions, and yours are interesting to me, because I appreciate your interest in your activities with children. To answer your "now what?" question, the answer will be: "it depends on what do you want". The activity is very similar to Forms: you add some objects to the window or XAML code. You give the object some names (adding "Name" attributes in XAML elements, manually; this is what is different from Forms; as objects are not created as named members by default), and it would generate code to make those objects accessible for your code. You can add handlers ("+=") to object events to handle them (clicks, mouse moved, keyboard presses, etc.) That's it, basically. Perhaps you need from looking at some simple samples and read some overviews. Almost nothing is too difficult. Besides, you are the one who can afford giving up difficult problems and base your work on what you can certainly do -- it makes perfect sense.

You should understand that real "professionals" did exactly that -- nobody taught them (or us) Forms, WPF, etc. We just look on what is available on the platform. These days, documentation is much, much better than it was a decade or two ago.

And, as I gave you two answers, please consider accepting them formally (green button). If won't limit you on asking additional questions, on this page or separately. Just remember, if you want me to attend to some of your post, you will need to notify me by commenting on any of my post using "Reply".

Good luck,
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Now, about the sounds. There are many layers for that.

First, this is very simple and useful interface people rarely use: sound a fixed frequency for a fixed period of time. This is enough to make a simple simulated musical instrument or something like that (but you will need to play sound in a separate thread, which is not a problem in this case). This is done via System.Console.Beep(int frequency, int duration); please see:[^].

As to the musical instruments, you can play a predefined set of those using MIDI. Now, this is already polyphonic. To use it with .NET, you will need a MIDI wrapper. CodeProject is a good source:
C# MIDI Toolkit[^],
Wrapper Library for Windows MIDI API[^],
Developing MIDI applications with DirectMusic[^].

Now, you can play a sound file:[^].

Ultimately, you can create any waveform dynamically and play it. Please see:

C# Synth Toolkit - Part I[^],
C# Synth Toolkit - Part II[^],
recording and play using Waveform audio interface[^],
Using MCI to control multimedia[^].

This is a very interesting application where you can "play" an image you can draw in screen — really interesting:
Draw into sound[^].

And the last but not least — you can synthesize the human voice, which is quite easy, as you have a ready-to-use engine. Please see:[^].

You will find a code sample in the MSDN help article referenced above.

Best wishes,
Kenneth Haugland 6-Aug-12 17:00pm
Well, small question turned large. I like this :) a 5.
Thank you, Kenneth. Well, quite naturally it turns large. If one want to get anything good, especially for children...
Kenneth Haugland 6-Aug-12 17:08pm
Ill guess he/she would be a little too young to deal with complex numbers:

But it is also in WPF :)
Did you do it from scratch? Just from parsing the expression from screen? If so, I don't like it, because there is a much more fruitful way: to use CodeDOM and C#/VB.NET (more exactly, .NET language) code as a ready-do-use calculator. It takes just Reflection with dynamically compiled assemblies and -- the difficult part -- using Application Domains and hence IPC, because you cannot unload a loaded assembly, only a whole application domain; but they are isolated, so IPC is needed to communication. This is yet another unwritten article I have the code ready.
Kenneth Haugland 6-Aug-12 17:59pm
"Did you do it from scratch? Just from parsing the expression from screen?"
All the coding is done from scratch, I did know about CodeDom, but looks interestig.
Yes, for exercise in parting and further stuff this could be interesting, but I prefer using existing languages and compilers. This is amazing that the compilers come for free with the (redistributable) .NET Framework, so using them during run time is a right thing to do. .NET guarantee their presence during run time.
Kenneth Haugland 6-Aug-12 18:35pm
Im a bit confused... What do you mean the code should look like? I cant immidieatly see the connection with CodeDOM..
The input language for your tool can be simply one of .NET languages. You can even hide some framing code (using, class declaration, etc.), so the code will be like this:

Complex x = 3*i + 4, y = 3.2i - 12;
Complex z = x * y;

This is how my code works. The application takes this code, add header and footer C# or VB.NET code, complies. (In case of errors, the lines number are translated taking the shift into consideration, so the application put a cursor on an error position correctly.) In case of success, runs it in a special environment, returns data to the Application Domain where the UI is (IPC) and UI presents the result of, say Print operations. A calculator, but the input language is the existing .NET language. No parsing, no nothing.
Richard.Berry100 6-Aug-12 17:35pm
@Kenneth - no kiddin!
@Sergey - Mmm thats a nice idea - midi - I'm a part time musician and have already done an app to play back midi files, so that should be pretty simple to copy some code across! (MCI - i used winmm.dll - sure i got vb code from Code Project - so anyone reading this.. Just search midi for vb code)
You guys must be very young and very bright.... Coz u bending my poor little brain now - maybe I should stick to rock n roll n dirt bikes and pack the pc away! (But no.. cant do that now) thanks so much hey. Its goindg to take me some time to go through all the links - I'll reply
You know, I play classical guitar as an amateur and take musical theory pretty seriously, so I've created some simple MIDI codes to study in the field of harmony and related stuff, using one of the MIDI wrappers I referenced above. It worked for me right away and was pretty useful. Unlike more primitive methods, you can create polyphonic sequences right away and play them asynchronously to your code.

But with simple Beep, you can already play frequencies in between the equal-temperament tones, simulate effects of continues frequency change, etc, very limited though...

Again, you are welcome to ask further questions.

And perhaps accept the answer formally.
Richard.Berry100 6-Aug-12 18:44pm
Lots in common! (I think I did accept answer? and vote too?)
Perhaps this should be in the Lounge or something - lots of subjects.
I use midi to playback midi files for live performance. Windows GS synth sounds are bad... I have foobar2k, which I use to convert midi to wav, then flv to convert wav to MP3 (small file) and use wimm.dll to play. Would be very interested to find way to play midi file properly in VB (not C#:() especially sysex messsages, bank changes etc, and to choose a different sound source to windows (i.e soundfont *.sf file)
Yes you accepted it -- thank you. I don't know about a vote; it you did it, your did -- I see two votes.
If you mean some of our views, yes, I'm please to see a lot in common. Playing MIDI with VB.NET or C#, no matter what, is quite possible thanks to the MIDI wrappers I've used and referenced above. I haven't use very advanced features of MIDI, but...

Are you familiar with microtonal music? 24 tones in octave in Arabic and Turkish systems, there are also some Indian systems (some are 60-tones), some Chinese and Japanese systems I don't really know, etc. Among other things, there are temperaments other than equal, like just intonation, etc. Some can help to alleviate the problem if not perfectly harmonic intervals stemmed from the sacrifice of precise harmonic interval to equality of tonal keys use in modern Western equal temperament.

So, one Arabic guy asked me if we could play Arabic Maqam modes using MIDI. I answered negatively, because MIDI is designed strictly for 12-tone equal temperament, but on second thought, I suggested that non-equal tones and even quoter tones can be simulated using MIDI pitch wheel feature. The documentation is not quite clear about it, the exact shift in tonal cents are not quite clear from documentation or may depend, but the problem is interesting to try to solve.

Richard.Berry100 25-Aug-12 9:54am
Hello Sergey

Sorry for the late reply :).

I have not experimented in micro-tonal music.

I did look into Equal Temperament tuning - one of my guitars has some intonation issues, and I found that by NOT using a tuner for all strings I get better results...

This was some of the info I looked at:

Equal Temperament is a musical tuning system that divides the Octave into 12 geometrically equal steps.
Each step is one semitone. When moving up one step, the frequency (or pitch) increases by 2^(1/12). Using this system, the Octave (12 semitones) is perfect, because 2^(12/12) = 2^1 = 2, an exact doubling of frequency. But the Fifth (seven semitones) is 2^(7/12) = 1.498 times the root. A perfect fifth, on the other hand is exactly 1.5 times. The difference is small, but it is significant. If you want to hear this, play the 6th string 7th fret harmonic. Now stop the string at the 7th fret and play the assisted harmonic at the 19th fret (effectively the new 12th fret). This note will sound very slightly flatter than the 7th fret harmonic. In Equal Temperament tuning, the slightly flat note is the correct pitch.

The best way to tune:

• Use a concert A tuning fork to tune the 5th string to A. You may use the 5th or 12th fret harmonics if you like, as octaves (and double octaves) are perfect. When the 5th string is tuned, don't alter it again!
• Play the 7th fret E on the 5th string (the stopped note, not the harmonic!!)
• Tune the open 6th string to this note (one octave down). If you prefer, you can use the 12th fret harmonic for unison tuning.
• Again play the 7th fret E on the 5th string
• Tune the open 1st string to this note (one octave up). If you prefer, you can use the 19th fret assisted harmonic on Master String 5 for unison tuning.
• Play the 5th fret D on the 5th string
• Tune the open 4th string to this note (by unison)
• Play the 2nd fret B on the 5th string
• Tune the open 2nd string to this note (one octave up). If you prefer, you can use the 14th fret assisted harmonic on Master String 5 for unison tuning.
• Play the 10th fret G on the 5th string
• Tune the open 3rd string to this note (by unison)
The advantage of this method is that any slight detuning tendency is not passed cumulatively from string to string, as every string is tuned directly to the Master String. However, you should only use this method if your 5th string passed the 12th fret harmonic test described above. If your 4th or 6th string is more accurate, the method can easily be adapted, but as concert A tuning forks are the most readily available, the A-string is best.

PS: I completed the little maths practice game for my son. It is not very fancy, but he likes it. He is only in Grade 1 (first year of school) so it gives him addition and subtraction sums and score etc I included round buttons as per your reference, and midi sound when the game is running (more as a continuous noise so that other noises in his environment do not distract him) So once again - thanks very much for all your input, much of which I think I will come back to for future versions of his program :)
Richard.Berry100 25-Aug-12 10:05am
Hi Sergey

Sorry for the late reply...

I have not experimented with microtonal music. I would imagine that if you made a software keyboard, were you can play the note, and then increment or decrement the pitch wheel, and used a decent frequency counter (either hardware, or perhaps a software app (FFT?) your could calibrate the various tones by seeing how many pitch wheel increments are needed to get the desired frequency?
Thank you for the advice on tuning; I'll take a look into it. But this is something more practical and related to one simple fact: this is the way you try to compensate for some guitar's imperfections. All guitars I ever tried was not tuning perfectly to the equal or any other temperament due to some (miner or noticeable) defects in freatboard. It's very hard to arrange them perfectly in serial production. Besides, if guitar frets could be adjusted perfectly for some set of strings, using slightly different strings would introduce imperfection. So, if you perfectly tune open strings, the same strings pressed against a fret would not produce the clear sound of Nth semitone from the open one. In your method, you probably try to distribute imperfections more evenly between some range of tone.

I was talking about the fundamental problem related to micro-toning or non-equal temperament. There cannot be such thing as a perfect temperament for all keys in principle. Here is why: the physics of sound perception makes people perceiving the interval expressed by rational numbers as harmonic. First of all, prima, octave, perfect quinta and quarta are perceived as highly harmonic intervals because of the frequency ratio 1, 1/2, 2/3 and 3/4. The same hair in a human ear resonate on both main tone and the physical harmonics of it, that's why. But in equal temperament, all frequency ratio values are irrational numbers, multiples of power(2, 12). So, there are no exact 2/3 and 3/4 ratio; there are approximations of those values in irrational numbers. If you try to change it to exact rational numbers, you will get tuning which does not allow transposition in a different key. Nevertheless, in early Barocco and before, all systems were non-equally tempered, but closer to rational numbers. In other words, to change the key, the musicians had to slightly re-tune the instruments; and harmonic modulation in the same opus was not possible or limited. Right now, the authentic playing comes in fashion (from what I know, in Europe and Russia), which is very, very interesting. Old instruments are restored and reproduced. Interestingly, old instruments had "bad" and "good" notes, and the composers had to take it into account.

Now, microtonal systems offers a compromise. Roughly speaking, the octave can be tuned with the equal temperament, and transposition would be a simple frequency shift, but harmonic intervals could be done "more harmonic" by shifting the micro tone depending on the required interval which carries the musical semantic of the piece. Besides, in Eastern musical tradition (like Arabic or Turkish), close micro tones are often played in wavy sequences, playing the same role as string bending in rock music. (I heard of rock music pieces using some microtonal systems, cannot give you exact references right now.)

In your comment above, if you mean using the sound card directly, you can produce any arbitrary wave form and produce any audible effect, of course. The trick is to create a system based on MIDI, which is much simpler but much more rigid. It's based on equal 12-tone temperament, nothing else. The only way to trick it into any other system I can see is using the wheel, which is the standard effect of MIDI, but using it not for transition effects it was designed for, but for playing different tones, those in between 12-tone semi-tones.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171207.1 | Last Updated 6 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100