表格上的简易图形-儿童应用 [英] Easy Graphics on a form - kids app

查看:67
本文介绍了表格上的简易图形-儿童应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我正忙于为我的小朋友练习数学的小应用程序.我可以生成一些简单的加法和减法求和,但是用户界面不太时髦,也不吸引孩子.

使用VS2010,vb.net,Windows窗体应用程序-除了这些我不熟悉-因此最好猜测一下我所知道的内容

关于背景的任何想法,很容易实现的显示乐谱,动画,声音等炫酷方法的方法,将不胜感激(我的儿子比我更多:))

谢谢

Richard

Hello

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, vb.net, 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 :))

Thanks

Richard

推荐答案

与WinForms相比,使用WPF设计自定义用户界面通常要简单得多.后面的代码并没有什么不同,但是可能性是无限的.

还有为设计师设计的Blend女巫...


顺便说一句:Blend旨在与WPF一起使用,并且您可以使用is创建一些应用程序,这在WinForms中是非常繁琐的工作.看看这些拖曳应用程序:

WPF大奖赛 [ WPF Rubik的多维数据集 [
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.

[/Edit]


首先,要教你的孩子对非时髦的东西感兴趣.这样,您将发送一个重要的信息:最有趣的东西比外壳要深得多.使您的应用程序真的有趣,而不是由于时髦的颜色和形状.如果您需要教育好品味,首先要自己学习好品味.这并不容易,但是当您掌握了它(我不知道告诉您已经准备好了,但是很多人从来没有来过它:-)),您就会知道自己可以做什么.

现在,回到技术问题.这是一个很大的话题.所有图形均在处理Windows消息WM_PAINT时呈现.该窗口在图形上不存储任何信息,因此,如果表单的一部分被另一个窗口关闭,然后再次显示,它将再次向您发送消息.要处理它,您需要重写方法OnPaint或处理事件Paint.不要重复常见的错误:在事件参数中使用传递给您的System.Drawing.Graphics实例,不要创建实例.

对于动画或交互行为,您需要使用Control.Invalidate更改渲染中使用的数据并使场景无效.您可以将Invalidate与参数(RegionRectangle)一起使用,以仅使一部分场景无效,并避免过度重绘,以提高性能.

使用这些技术,您可以在自定义控件(包括Form)中渲染任意图像并实现动画.

在mdi子表单之间画线 [在面板上捕获图形 [ Paint是一种哪种好玩的方法? (DataGridViewImageCell.Paint(...)) [ Control.Invoke()与Control.BeginInvoke() [ ^ ],
Treeview扫描仪和MD5的问题 [如何获取keydown事件在vb.net中的不同线程上操作 [启用禁用+多线程后控件事件不会触发 [ ^ ].

为避免动画或交互式渲染中出现闪烁,请始终使用双重缓冲:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered.aspx [ ^ ].

您可以使用另一种有趣的东西:非矩形控件,包括表单.要拥有它们,您只需要将其属性Region分配给某些非矩形Region实例.请参阅:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.region.aspx [ ^ ].

这不是那么简单,需要一些练习.我建议不要害怕.谈到您的我儿子比我更多":您永远不会对这个东西感兴趣,您对自己并不真正感兴趣.因此,巨大的毅力和完美主义根本不是一件坏事.

但是,如果从Forms切换到WPF,则有一个更简单的选择. WPF中的想象水平不同,但是我之前提到的几乎所有内容都已经为您完成:动画,渲染,缩放/平移等等.基本上,除了处理事件外,您还可以简单地拥有Canvas的实例,在其上放置各种对象,然后将它们移动.请参阅:
http://msdn.microsoft.com/en-us/library/system. windows.controls.canvas.aspx [ ^ ].

最重要的是,您可以制作动画.请参阅:
http://msdn.microsoft.com/en-us/library/ms752312.aspx [ ^ ].

当然,您始终可以使用线程进行自制动画,以对更复杂的运动进行建模.您需要使用UI线程调用机制以与上述相同的方式进行操作.

这只是WPF的一种方法,但看起来它是最接近您想要的方法.

现在,它会发出声音.您知道,对于这个论坛,我的答案已经太大了.首先考虑一下,问您后续问题.声音更简单,并且不依赖于UI库.让我稍后再找时间写些关于它们的信息...

—SA
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


现在,关于声音.为此有很多层.

首先,这是一个非常简单实用的界面,人们很少使用:在固定的时间段内以固定的频率发出声音.这足以制作一个简单的模拟乐器或类似的东西(但是您需要在单独的线程中播放声音,在这种情况下这不是问题).这是通过System.Console.Beep(int frequency, int duration);完成的,请参见:
http://msdn.microsoft.com/en-us/library/4fe3hdb1.aspx [ ^ ].

对于乐器,您可以使用MIDI播放一组预定义的乐器.现在,这已经是复音了.要将其与.NET一起使用,您将需要MIDI包装器. CodeProject是一个很好的来源:
C#MIDI工具包 [ Windows MIDI API的包装器库 [使用DirectMusic开发MIDI应用程序 [ http://msdn.microsoft.com/en-us/library/system.media. soundplayer.aspx [ ^ ].

最终,您可以动态创建任何波形并进行播放.请参阅:

C#Synth工具包-第一部分 [ C#Synth工具包-第二部分 [使用波形音频界面进行录制和播放 [ ^ ],
使用MCI控制多媒体 [ ​​吸引声音 [ http://msdn.microsoft.com/en-us/library/system.speech. synthesis.aspx [ ^ ].

您可以在上面引用的MSDN帮助文章中找到代码示例.

最好的祝福,
—SA
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:
http://msdn.microsoft.com/en-us/library/4fe3hdb1.aspx[^].

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:
http://msdn.microsoft.com/en-us/library/system.media.soundplayer.aspx[^].

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:
http://msdn.microsoft.com/en-us/library/system.speech.synthesis.aspx[^].

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

Best wishes,
—SA


这篇关于表格上的简易图形-儿童应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆