转换形式在c#中 [英] Transitions form in c#

查看:62
本文介绍了转换形式在c#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当form1过渡到form2并且第一次运行时的form1是一种移动形式时,我怎样才能使form1()成为转换(如powerpoint中的幻灯片的转换)我想要其他像形状,封面(在powerpoint)

  public  main()
{
InitializeComponent();
}

private bool go;
private int dx = 1 ;
private void main_Load( object sender,EventArgs e)
{
\
}

protected 覆盖 void OnPaint(PaintEventArgs e)
{
if (go)
{
.Location = 点( this .Location.X + dx, this .Location.Y);
if (Location.X < 10 || Location.X > 1400
{
go = false ;
dx = -dx;
}
其他
{
.Invalidate ();
}
}
}

private void button1_Click( object sender,EventArgs e)
{
go = true ;
this .Invalidate();
}

解决方案

编辑:



这是WinForms C#中的一个示例项目,它使用System.Timers.Timer显示动画一堆表单:[ ^ ]。来源包括在内。它是使用FrameWork 4.5在Visual Studio 2013中编写的。



使用Alt-M启动动画,使用Alt-N将其关闭,或者单击返回关闭动画的主要表格。



结束编辑



首先,使用Windows Forms(或WPF,或任何其他技术堆栈)成为C#编程的初学者并没有错:我们都是初学者一次:)



但是,我很清楚你现在对C#和Windows Forms编程感到很困惑。我建议你买一本好书并查看基础知识。



对于Windows Forms中的动画,CodeProject上有一个很好的资源,你可以下载代码,学习和从以下地方学习:[ ^ ] 。



对于简单的动画效果,比如移动表格,使用计时器没有任何问题:但是,取决于你是什么对象的内容移动,移动速度等等,你可能会观察到一点点口吃......取决于你电脑的CPU /显卡,显示器分辨率,内存等等。



如果您的Windows窗体具有复杂的栅格(位图)背景,并且内部控件具有自己的栅格背景,并且您在使用计时器移动窗体时改变窗体的不透明度设置:即使您将Form的'DoubleBuffer属性设置为'为true,您可能会看到visu动画效果不佳。



一般情况下,Windows Forms不适合任何类型的流畅动画;为此你应该考虑WPF,甚至像XNA一样的游戏引擎。


请看我对这个问题的评论。



要对图形进行一些更改,可以使用计时器,但我不建议它;使用线程在循环中更改数据更加简单,但有一些延迟;你现在可以使用 System.Diagnostics.StopWatch 进行实时检查。即使您使用计时器,也不要使用 System.Windows.Forms.Timer 来查看周期性的任何内容:此计时器的准确性对于此类效果来说太糟糕了。使用其他计时器类型。但是对于其他计时器,与线程完全一样,您将需要解决UI线程调用问题。您不能从非UI线程调用与UI相关的任何内容。相反,您需要使用 Invoke System.Windows.Threading的方法。 Dispatcher (对于Forms或WPF)或 System.Windows.Forms.Control (仅限表单)。



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

Control.Invoke()与Control.BeginInvoke()

使用Treeview扫描仪和MD5的问题



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

如何在vb.net中的另一个线程上运行keydown事件

在启用禁用+多线程后控制事件没有触发



这不难做,但定时器涉及其他风险,所以,总的来说,一个单独的线程更安全,更容易。



有关图形渲染和失效方法的解释,特别是使用单独的线程(或计时器,就此而言,请看我过去的答案:

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...))

如何加快我的vb.net应用程序?

在C#.net鼠标滚轮中缩放图像

在面板上捕获绘图

mdi子表单之间的绘制线



-SA

how can I make form1()be transitions (like transitions of slide in powerpoint) when the form1 transition to form2 and when the form1 in the first running this is kind of moving form put I want other like shape,cover (in powerpoint)

public main()
{
   InitializeComponent();
}

private bool go;
private int dx = 1;
private void main_Load(object sender, EventArgs e)
{
   \ 
}
        
protected override void OnPaint(PaintEventArgs e)
{
   if (go)
   {
      this.Location = new Point(this.Location.X + dx, this.Location.Y);
      if (Location.X < 10 || Location.X > 1400)
      {
         go = false;
         dx = -dx;
      }
      else
      {
         this.Invalidate();
      }
   }
}
       
private void button1_Click(object sender, EventArgs e)
{
   go = true;
   this.Invalidate();
}

解决方案

edit:

Here's a sample project in WinForms C# that shows animating a bunch of Forms using a System.Timers.Timer: [^]. The source is included. It was written in Visual Studio 2013, using FrameWork 4.5.

Use Alt-M to start the animation and Alt-N to turn it off, or click back on the Main Form to turn off animation.

end edit

First, there's nothing wrong with being a beginner with programming in C#, using Windows Forms (or WPF, or any other technology stack): we were all beginners once :)

However, it's clear to me you are quite confused about C# and Windows Forms programming at this point in time. I suggest you get a good book and review the basics.

For animation in Windows Forms there is an excellent resource here on CodeProject you can download the code, study, and learn, from: [^].

For animations effects of a simple nature, like moving a Form, there is nothing wrong with using a Timer: but, depending on the content of what object you are moving, and how fast you move it, etc., you may observe a little stutter ... depending on your computer's CPU/Graphics card, monitor resolution, memory, etc.

If you have a Windows Form with a complex raster (bit-map) background, and internal Controls that have their own raster backgrounds, and you are varying the Opacity setting of the Form while you move it with a Timer: even if you set the Form's 'DoubleBuffer Property to 'true, you may see visually poor results in the animation.

In general, Windows Forms is not a good vehicle for any kind of smooth animation; for that you should consider WPF, or even a game-engine, like XNA.


Please see my comment to the question.

To do some changes in the graphics, you can use a timer, but I would not advise it; it's much simpler to use the thread changing the data in cycles, with some delay; you can check up real time at the moment is rendering, using System.Diagnostics.StopWatch. Even if you use a timer, never use System.Windows.Forms.Timer for anything which is supposed to look periodic: the accuracy of this timer is too bad for such effects. Use other timer types. But with other timers, exactly as with threads, you will need to solve the UI thread invocation problem. 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.

This is not hard to do, but timers involves other risks, so, overall, a separate thread is much safer and easier.

For explanation of graphics rendering and invalidation approaches, in particular, with a separate thread (or a timer, for that matter), please see my past answers:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...)),
How to speed up my vb.net application?,
Zoom image in C# .net mouse wheel,
capture the drawing on a panel,
Drawing Lines between mdi child forms.

—SA


这篇关于转换形式在c#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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