如何将动画应用于控件? [英] How to apply animations to the controls?

查看:109
本文介绍了如何将动画应用于控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.....如何将动画设置为除滑动,滚动,混合,居中之外的控件。

实际上我有一个面板,在我的应用程序中首先看不见,当我点击在一个按钮上它必须来自某个点并且在窗体上的另一个点处可见,并且当面板在窗体上移动时必须可以看到飞行效果.....

任何想法

解决方案

你必须自己动手。创建一个动画线程。它应该是循环中的一些变化序列,您可以在其中更改控件的一个属性。启动此线程以启动动画。现在,如何使用此线程处理UI线程?您不能从非UI线程调用与UI相关的任何内容。相反,您需要使用 Invoke System.Windows.Threading的方法。 Dispatcher (对于Forms或WPF)或 System.Windows.Forms.Control (仅限表单)。



您将在我过去的答案中找到有关其工作原理和代码示例的详细说明:

Control.Invoke()与Control.BeginInvoke() [ ^ ],

使用Treeview扫描仪和MD5的问题 [ ^ ]。



另请参阅有关线程的更多参考资料:

如何让keydown事件在不同的操作上运行vb.net中的线程 [ ^ ],

在启用禁用+多线程后控制事件未触发 [ ^ ]。



如果您还要为某些控件中呈现的某些图形设置动画,请查看我过去的答案:

如何加速我的vb.net应用程序? [ ^ ],

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

在面板上捕获绘图 [ ^ ],

mdi子表单之间的绘制线 [ ^ ]。



-SA

Hi.....how to set the animations to controls except slide,roll,Blend,centre.
actually i have a panel which is invisible at first in my application,when i click on a button it must comes from some point and visible at some another point on the form and the flying effect must visible when panel moves on the form.....
Any Idea

解决方案

You have to do it yourself. Create an animation thread. It should be some sequence of changes in a loop where you change one more of the control's property. Start this thread to start animation. Now, how can you work with the UI thread using this thread? 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[^].

If you also want to animate some graphics rendered in some controls, please see my past answers:
How to speed up my vb.net application?[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^].

—SA


这篇关于如何将动画应用于控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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