Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Chnage Cursor to some animated image in windows application
 

Chnage Cursor to some animated image in windows application

Hi
I am performing some db operaion through code. I want to change Mouse cursor to some animated image.

Please tell me how can i do this,
Progress2007  Tuesday, August 25, 2009 4:31 PM
.Net does not seem to support animated or color cursors. You will have to try to do it the unmanaged way.

http://msdn.microsoft.com/en-us/library/ms648045%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/ms648393%28VS.85%29.aspx

Basically, use LoadImage() to load the animated cursor image, and then you call for SetCursor() to set it.
MCP
  • Marked As Answer byProgress2007 Friday, September 11, 2009 8:40 AM
  •  
webJose  Friday, September 04, 2009 3:09 PM
Hi,

Create a separate form and set its border property none. place an animated loading GIF image on that work , and use the following code for displying and closing the animated form.
 public partial class LoadingForm : Form
    {
        // Threading
        static LoadingForm ms_LoadingForm = null;
        static Thread ms_oThread = null;
        

        public LoadingForm()
        {
            InitializeComponent();
            //this.Parent = Program._MainForm;
        }

        static public void SetMessage(String strMsg)
        {
            ms_LoadingForm.lblMsg.Text = strMsg;
   
        }

        // ************* Static Methods *************** //

        // A static method to create the thread and 
        // launch the SplashScreen.
        static public void ShowSplashScreen()
        {
            // Make sure it's only launched once.
            if (ms_LoadingForm != null)
                return;
            Cursor.Current = Cursors.WaitCursor;
            ms_oThread = new Thread(new ThreadStart(LoadingForm.ShowForm));
            ms_oThread.IsBackground = true;
            ms_oThread.SetApartmentState(ApartmentState.STA); // = ApartmentState.STA;
            ms_oThread.Start();
        }

        // A property returning the splash screen instance
        static public LoadingForm SplashForm
        {
            get
            {
                return ms_LoadingForm;
            }
        }
        

        // A private entry point for the thread.
        static private void ShowForm()
        {
            ms_LoadingForm = new LoadingForm();
            Application.Run(ms_LoadingForm);
        }

        // A static method to close the SplashScreen
        static public void CloseForm()
        {
            try
            {
                if (ms_LoadingForm != null && ms_LoadingForm.IsDisposed == false)
                {
                    // Make it start going away.
                    //ms_LoadingForm.m_dblOpacityIncrement = -ms_LoadingForm.m_dblOpacityDecrement;
                    if (ms_LoadingForm.InvokeRequired)
                    {
                        ms_oThread.Abort();
                        ms_oThread.Join(); // wait for thread to terminate 
                    }
                    else
                    {
                        ms_LoadingForm.Close();
                    }
                }
                ms_oThread = null;	// we don't need these any more.
                ms_LoadingForm = null;

            }

            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                ms_oThread.Abort();
                ms_oThread = null;	// we don't need these any more.
                ms_LoadingForm = null;

            }
            finally
            {
                Cursor.Current = Cursors.Default;
                ms_oThread = null;	// we don't need these any more.
                ms_LoadingForm = null;
            }
        }

    }
To disply and hide the animated form use the follwing code.
Before DB operation load the animated form.

LoadingForm.ShowSplashScreen();
Application.DoEvents();

After completing the DB operation close the animated form by using this code.
LoadingForm.CloseForm();
Application.DoEvents();

Thanks ...

Malik M.Shahid  Tuesday, August 25, 2009 8:56 PM
VB.NET -

Me.Cursor = Cursors.WaitCursor

C#.NET -

this.Cursor = Cursors.WaitCursor;


Thanks

Someone is back..... "OMIE" is back !!! Tell a friend !
Omie  Wednesday, August 26, 2009 4:39 AM
VB.NET -

Me.Cursor = Cursors.WaitCursor

C#.NET -

this.Cursor = Cursors.WaitCursor;


Thanks

Someone is back..... "OMIE" is back !!! Tell a friend !

Hi i don;t want to use default cursor of windows forms. I want to use some moving images in window application.Please suggest me how can i do this
Progress2007  Wednesday, August 26, 2009 5:19 AM
Add gif file in resources. Put a Picture Box on form. When doing work, set that picturebox.visible=true and set image=loading image.

Or create a new borderless form. Add picture box to it. Set its image to loading image. set opacity of form = 0. when doing work, show it. use ShowDialog to make it modal and prevent access to main form. close that form when work is done.

If work lasts for long then it will show main form as not responding for a while. To avoid this, start background work in other thread.

Malik M.Shahid has shown something. Did you try his code ?

[ also, please specify whether you're using vb.net or c# ]





Thanks

Someone is back..... "OMIE" is back !!! Tell a friend !
Omie  Wednesday, August 26, 2009 5:35 AM
Add gif file in resources. Put a Picture Box on form. When doing work, set that picturebox.visible=true and set image=loading image.

Or create a new borderless form. Add picture box to it. Set its image to loading image. set opacity of form = 0. when doing work, show it. use ShowDialog to make it modal and prevent access to main form. close that form when work is done.

If work lasts for long then it will show main form as not responding for a while. To avoid this, start background work in other thread.

Malik M.Shahid has shown something. Did you try his code ?

[ also, please specify whether you're using vb.net or c# ]





Thanks

Someone is back..... "OMIE" is back !!! Tell a friend !

I am doing it in VB.NET
Progress2007  Wednesday, August 26, 2009 4:30 PM
.Net does not seem to support animated or color cursors. You will have to try to do it the unmanaged way.

http://msdn.microsoft.com/en-us/library/ms648045%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/ms648393%28VS.85%29.aspx

Basically, use LoadImage() to load the animated cursor image, and then you call for SetCursor() to set it.
MCP
  • Marked As Answer byProgress2007 Friday, September 11, 2009 8:40 AM
  •  
webJose  Friday, September 04, 2009 3:09 PM

You can use google to search for other answers

Custom Search

More Threads

• Color attributes with checkbox.appearance=appearance.button
• Remove the icon from the system tray programmatically
• COM Interopt - is it all STA or single threaded?
• 3rd party libraries - what's your opinion?
• Custom Control and Designer Refresh issues
• Resize panel in winform
• Why won't my properties show up in the designer?
• Combo box bound to my.setting string
• problems with modifying name property
• WebBrowser Control