Click here to Skip to main content
15,917,061 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
i have used the following code to slide a form but its not working ..and i have been told to use coredll.dll to implement that function in windows mobile..since i am not much familiar with that ..could u help me ..i tried google but i am not able to understand a bit...

C#
01	using System.Runtime.InteropServices;
02	 
03	    public partial class form1 : Form
04	    {
05	/*  Constants */
06	        const int AW_SLIDE = 0X40000;
07	        const int AW_HOR_POSITIVE = 0X1;
08	        const int AW_HOR_NEGATIVE = 0X2;
09	        const int AW_BLEND = 0X80000;
10	        const int AW_VER_POSITIVE = 0X4;
11	        const int AW_VER_NEGATIVE = 0X8;
12	        [DllImport("user32")]
13	        static extern bool AnimateWindow(IntPtr hwnd, int time, int flags);
14	 public form1()
15	        {
16	            InitializeComponent();
17	        }
18	 
19	        private void form1_Load(object sender, EventArgs e)
20	        {
21	            
22	            ///* Animate form */
23	             
24	            AnimateWindow(this.Handle, 500, AW_SLIDE | AW_VER_NEGATIVE);
25	}
Posted
Updated 4-Mar-12 20:11pm
v2
Comments
ajit_machhe 5-Mar-12 0:14am    
are you developing windows mobile application ? or window application ?
if you are using window application WPF will help you better..
Member 8648589 5-Mar-12 0:50am    
i am using windows mobile application
ajit_machhe 5-Mar-12 0:58am    
am sorry dear i can't help then..
Member 8648589 5-Mar-12 2:24am    
its ok ..thanxx anyway
Sergey Alexandrovich Kryukov 5-Mar-12 2:15am    
Forms do perfectly fine, please see my answer.
--SA

1 solution

You don't need P/Invoke! This is bad, kills multiplatform compatibility.

Better keep using pure .NET, but do it properly. This is complete source code:

C#
using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace SlideForm {
    
    public partial class MyForm : Form {

        const int Step = 1;
        const int Steps = 500;
        const int DelayMs = 20;        
        const string buttonName = "&Animate";

        public MyForm() {
            Button button = new Button();
            button.Text = buttonName;
            this.Controls.Add(button);
            button.Click += (sender, eventArgs) => { StartAnimation(); }
        } //MyForm

        void StartAnimation() {
            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += (sender, eventArgs) => {
                for (int count = 0; count < Steps; ++count) {
                    this.Invoke(new Action<Form>((Form form) => {
                        form.Left += Step;
                    }), this);
                    System.Threading.Thread.Sleep(DelayMs);
                } //loop
            }; //worker.DoWork
            worker.RunWorkerAsync();
        } //StartAnimation

    } //class MyForm

} //namespace SlideForm


I developed the code in few minutes for you. It works, tested.

For the purpose of having all code in one file (except entry point which is the same as auto-generated when a project is created from template), the designer is not used. In many cases, this is the best way do to Forms development. ;-)

Animation works, but there is something else to do: 1) prevent button event when animation is in progress; 2) abort animation when a form is being closed. Those are small things, I would leave it for your home exercise.

Good luck,
—SA
 
Share this answer
 
v7
Comments
ProEnggSoft 5-Mar-12 2:26am    
Very good example. I have tested it in LINQPad. Its working very well. My 5.
Sergey Alexandrovich Kryukov 5-Mar-12 2:30am    
Sure, how else? :-) Thank you.
--SA

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