Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
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)
C#
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();
}
Posted
Updated 18-Apr-15 12:05pm
v4
Comments
hotthoughtguy 17-Apr-15 13:43pm    
your description is not clear. please explain in detail and clarification required... :)
neveen neveen 17-Apr-15 13:57pm    
I have two form form1 and form2 I want when run my project form1 not show in traditional way I want it show with moving like the transitions slide in powerpoint shape,cover ...
BillWoodruff 17-Apr-15 14:17pm    
You do not want to use the Paint Event this way. Instead create a Timer, and move the Forms with the Timer.
neveen neveen 17-Apr-15 14:22pm    
how ???
gggustafson 17-Apr-15 15:39pm    
Using invalidate within OnPaint is a sure way to have problems. It's like recursion. Remove this.Invalidate. If the button click event triggers the OnPaint then the go variable is unnecessary and should be removed. So far as transitioning from one form to the next, you are not showing the code that you use. Please use Improve Question to show that.

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.
 
Share this answer
 
v2
Comments
neveen neveen 18-Apr-15 10:30am    
BillWoodruff how can I add Animator control to the form is like a timer or what?
BillWoodruff 18-Apr-15 11:18am    
Windows Forms has no built-in "animator control;" while in theory you could write a library (dll) specifically for Form/Control Animation, that's an advanced project.

I have my own library for Form manipulation that simulates a touch-driven interface; if you mouse-down and drag far enough, and fast enough, it will trigger an animation of the Form in one of eight directions. If I can get permission from the client for whom I wrote this code, I will publish it here eventually.

I think your best strategy is to download the code in the article I linked-to and study it.

I will add a very simple animation routine to my solution here within the next twenty-four hours.

cheers, Bill
BillWoodruff 18-Apr-15 13:52pm    
Link to a simple WinForm animation project (including source) added to the solution above. Compiled in Visual Studio 2013, using FrameWork 4.5.
neveen neveen 18-Apr-15 14:16pm    
Thank you for your cooperation
BillWoodruff 18-Apr-15 17:49pm    
Made two changes: revised version accessible with the same link.

1. the topmost secondary Form becomes active when the app starts. required relocating secondary Form activation to the Main Form's 'Shown event

2. after the current Form is fully off-screen, set the currently displayed topmost secondary form to be active.

Note that the secondary Forms must be active in order for alt-M to trigger animation.

cheers, Bill
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
 
Share this answer
 
Comments
neveen neveen 17-Apr-15 17:29pm    
Sergey Alexandrovich ,what all this please understand me when run windows form is show the form in the traditional way, I need different show to this form
Sergey Alexandrovich Kryukov 17-Apr-15 17:53pm    
Not clear. What am I supposed to understand? You use OnPaint. We explained you why you are doing it wrong and I explained how to deal with painting.
Forget "traditional" and "not traditional" ways, it means nothing. If you need something different, please explain, but I tell you: just understanding how to paint is enough. If you don't need paint, don't ask about it, ask about something else. And if you did not understand the answer, ask your follow-up questions.
—SA
BillWoodruff 18-Apr-15 7:48am    
Voted #1: a collage of off-topic, and needlessly confusing verbiage and links.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900