c# code to change mouse cursor from pointer to "hand" shape on Safari

does anyone have the
c# code to change mouse cursor from pointer to "hand" shape on Safari
srtindallAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

khan_webguruCommented:
With .NET you can easily change the current cursor by using the Cursors class. To change the cursor to a hourglass, we'll be using the WaitCursor:

 
this.Cursor = Cursors.WaitCursor;

Open in new window



To change it back to normal after the application has stopped loading:

 
this.Cursor = Cursors.Default;

Open in new window


Hope this will help you

Regards,

Asif Ahmed Khan
0
khan_webguruCommented:
Hello Bro!

Found another thing please have a look

This example shows how to change the Cursor of the mouse pointer for a specific element and for the application.

This example consists of a Extensible Application Markup Language (XAML) file and a code behind file.


The user interface is created, which consists of a ComboBox to select the desired Cursor, a pair of RadioButton objects to determine if the cursor change applies to only a single element or applies to the entire application, and a Border which is the element that the new cursor is applied to.

 
<StackPanel>
  <Border Width="300">
    <StackPanel Orientation="Horizontal"
                HorizontalAlignment="Center">
      <StackPanel Margin="10">
        <Label HorizontalAlignment="Left">Cursor Type</Label>
        <ComboBox Width="100"
                  SelectionChanged="CursorTypeChanged"
                  HorizontalAlignment="Left"
                  Name="CursorSelector">
          <ComboBoxItem Content="AppStarting" />
          <ComboBoxItem Content="ArrowCD" />
          <ComboBoxItem Content="Arrow" />
          <ComboBoxItem Content="Cross" />
          <ComboBoxItem Content="HandCursor" />
          <ComboBoxItem Content="Help" />
          <ComboBoxItem Content="IBeam" />
          <ComboBoxItem Content="No" />
          <ComboBoxItem Content="None" />
          <ComboBoxItem Content="Pen" />
          <ComboBoxItem Content="ScrollSE" />
          <ComboBoxItem Content="ScrollWE" />
          <ComboBoxItem Content="SizeAll" />
          <ComboBoxItem Content="SizeNESW" />
          <ComboBoxItem Content="SizeNS" />
          <ComboBoxItem Content="SizeNWSE" />
          <ComboBoxItem Content="SizeWE" />
          <ComboBoxItem Content="UpArrow" />
          <ComboBoxItem Content="WaitCursor" />
          <ComboBoxItem Content="Custom" />
        </ComboBox>
      </StackPanel>
      <!-- The user can select different cursor types using this ComboBox -->
      <StackPanel Margin="10">
        <Label HorizontalAlignment="Left">Scope of Cursor</Label>
        <StackPanel>
          <RadioButton Name="rbScopeElement" IsChecked="True"
                       Checked="CursorScopeSelected">Display Area Only</RadioButton>
          <RadioButton Name="rbScopeApplication"
                       Checked="CursorScopeSelected">Entire Appliation</RadioButton>
        </StackPanel>
      </StackPanel>
    </StackPanel>
  </Border>
  <!-- When the mouse pointer is over this Border -->
  <!-- the selected cursor type is shown -->
  <Border Name="DisplayArea" Height="250" Width="400"
          Margin="20" Background="AliceBlue">
    <Label HorizontalAlignment="Center">
      Move Mouse Pointer Over This Area
    </Label>
  </Border>
</StackPanel>

Open in new window



The following code behind creates a SelectionChanged event handler which is called when the cursor type is changed in the ComboBox. A switch statement filters on the cursor name and sets the Cursor property on the Border which is named DisplayArea.

If the cursor change is set to "Entire Application", the OverrideCursor property is set to the Cursor property of the Border control. This forces the cursor to change for the whole application.


 
private void CursorTypeChanged(object sender, SelectionChangedEventArgs e)
{
    ComboBox source = e.Source as ComboBox;

    if (source != null)
    {
        ComboBoxItem selectedCursor = source.SelectedItem as ComboBoxItem;

        // Changing the cursor of the Border control 
        // by setting the Cursor property
        switch (selectedCursor.Content.ToString())
        {
            case "AppStarting":
                DisplayArea.Cursor = Cursors.AppStarting;
                break;
            case "ArrowCD":                        
                DisplayArea.Cursor = Cursors.ArrowCD;
                break;
            case "Arrow":
                DisplayArea.Cursor = Cursors.Arrow;
                break;
            case "Cross":
                DisplayArea.Cursor = Cursors.Cross;
                break;
            case "HandCursor":
                DisplayArea.Cursor = Cursors.Hand;
                break;
            case "Help":
                DisplayArea.Cursor = Cursors.Help;
                break;
            case "IBeam":
                DisplayArea.Cursor = Cursors.IBeam;
                break;
            case "No":
                DisplayArea.Cursor = Cursors.No;
                break;
            case "None":
                DisplayArea.Cursor = Cursors.None;
                break;
            case "Pen":
                DisplayArea.Cursor = Cursors.Pen;
                break;
            case "ScrollSE":
                DisplayArea.Cursor = Cursors.ScrollSE;
                break;
            case "ScrollWE":
                DisplayArea.Cursor = Cursors.ScrollWE;
                break;
            case "SizeAll":
                DisplayArea.Cursor = Cursors.SizeAll;
                break;
            case "SizeNESW":
                DisplayArea.Cursor = Cursors.SizeNESW;
                break;
            case "SizeNS":
                DisplayArea.Cursor = Cursors.SizeNS;
                break;
            case "SizeNWSE":
                DisplayArea.Cursor = Cursors.SizeNWSE;
                break;
            case "SizeWE":
                DisplayArea.Cursor = Cursors.SizeWE;
                break;
            case "UpArrow":
                DisplayArea.Cursor = Cursors.UpArrow;
                break;
            case "WaitCursor":
                DisplayArea.Cursor = Cursors.Wait;
                break;
            case "Custom":
                DisplayArea.Cursor = CustomCursor;
                break;
            default:
                break;
        }

        // If the cursor scope is set to the entire application
        // Use OverrideCursor to force the cursor for all elements
        if (cursorScopeElementOnly == false)
        {
            Mouse.OverrideCursor = DisplayArea.Cursor;
        }
    }
}

Open in new window




See Also

http://msdn.microsoft.com/en-us/library/ms754010.aspx

http://social.msdn.microsoft.com/forums/en-US/vbgeneral/thread/a0b5d97f-a9dd-448f-9a6a-fc2836f4f7df

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

Thats all from my side

Regards,

Asif Ahmed Khan

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Obadiah ChristopherCommented:
My guess is this is an ASP.Net app. And if tht is the case I
Don't think these soln work. Is this a asp.net app?
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Obadiah ChristopherCommented:
I think u have 2 use css

.mousecursor{
Cursor:hand;
}
0
_valkyrie_Commented:
Well I went under the notion that it was a Windows application. However if this is asp.net, then this is not the answer.

Monitor cursor movement and flag when it goes over Safari:
    //Requires reference to System.Drawing
    public class MouseMonitor
    {
        [DllImport("user32.dll")]
        static extern IntPtr WindowFromPoint(POINT Point);
        [DllImport("user32.dll")]
        static extern bool GetCursorPos(out POINT lpPoint);
        [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
        static extern IntPtr GetParent(IntPtr hWnd);
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern int GetWindowThreadProcessId(IntPtr handle, out uint processId);

        [StructLayout(LayoutKind.Sequential)]
        public struct POINT
        {
            public int X;
            public int Y;

            public POINT(int x, int y)
            {
                this.X = x;
                this.Y = y;
            }

            public static implicit operator Point(POINT p)
            {
                return new Point(p.X, p.Y);
            }

            public static implicit operator POINT(Point p)
            {
                return new POINT(p.X, p.Y);
            }
        }

        public class MouseFoundOverApplicationEventArgs : EventArgs 
        {
            IntPtr windowHandle;

            public MouseFoundOverApplicationEventArgs(IntPtr windowHandle)
            {
                this.windowHandle = windowHandle;
            }

            public IntPtr WindowHandle
            {
                get { return this.windowHandle; }
            }
        }

        public delegate void MouseFoundOverApplicationEventHandler(object sender, MouseFoundOverApplicationEventArgs e);

        public event MouseFoundOverApplicationEventHandler MouseFoundOverApplication;

        Timer timer = new Timer();
        string applicationName;

        public MouseMonitor(string applicationName)
        {
            this.timer = new Timer();
            this.timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
            this.applicationName = applicationName;
        }

        void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            IntPtr windowHandle = MouseMonitor.GetHandleOfWindow();
            if (MouseMonitor.WindowMatchesApplication(windowHandle, applicationName))
                this.OnMouseFoundOverApplication(new MouseFoundOverApplicationEventArgs(windowHandle));
            this.timer.Start();
        }

        public void Start(double interval = 500)
        {

            this.timer.AutoReset = false;
            this.timer.Interval = interval;
            this.timer.Start();
        }

        public void Stop()
        {
            if (this.timer.Enabled)
                this.timer.Stop();
        }

        protected void OnMouseFoundOverApplication(MouseFoundOverApplicationEventArgs e)
        {
            if (this.MouseFoundOverApplication != null)
                this.MouseFoundOverApplication(this, e);
        }


        private static IntPtr GetHandleOfWindow()
        {
            POINT location;
            MouseMonitor.GetCursorPos(out location);

            IntPtr window = MouseMonitor.WindowFromPoint(location);
            IntPtr windowParent = IntPtr.Zero;

            while (window != IntPtr.Zero)
            {
                windowParent = window;
                window = MouseMonitor.GetParent(window);
            }

            return windowParent;
        }

        private static bool WindowMatchesApplication(IntPtr windowHandle, string applicationName)
        {
            uint processID = 0;
            MouseMonitor.GetWindowThreadProcessId(windowHandle, out processID);
            Process process = Process.GetProcessById((int)processID);

            string executableName = Path.GetFileName(process.MainModule.FileName);
            return (applicationName.ToLower() == executableName.ToLower());
        }
    }

Open in new window


Then to start the monitor:
            this.monitor = new MouseMonitor("safari.exe");
            this.monitor.MouseFoundOverApplication += new MouseMonitor.MouseFoundOverApplicationEventHandler(monitor_MouseFoundOverApplication);
            this.monitor.Start();

Open in new window


Then to catch the event:
        void monitor_MouseFoundOverApplication(object sender, MouseMonitor.MouseFoundOverApplicationEventArgs e)
        {
            //TODO Add code to change cursor
        }

Open in new window


If this is the path you were going and need help finishing the change cursor, let me know. The information on changing the cursor is at: http://msdn.microsoft.com/en-us/library/ms648393%28VS.85%29.aspx
0
khan_webguruCommented:
Hello Bro,

Also look into this

 
HCURSOR WINAPI SetCursor(
  __in_opt  HCURSOR hCursor
);

Open in new window


Regards,

Asif Ahmed Khan
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.