Hi, all i have to make an application in which there is requirement to hide a cursor when a event is generated and cursor enters a panel, and if the mouse is clicked in the panel, the cursor has to be show again. But i am unable to do this. any help would be appreciated, thanks in advance.:)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CursorHide
{
    public partial class Form1 : Form
    {
        private bool flag;

        public Form1()
        {
            InitializeComponent();
        }

        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            flag = false;
            Cursor.Show();
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (flag)
                Cursor.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            flag = true;
        }

    }
}

Recommended Answers

All 3 Replies

private void panel1_MouseMove(object sender, MouseEventArgs e)
        {

            if (flag)
                Cursor.Hide();
            else
                Cursor.Show();
            
            
        }
commented: Simple but effective! +6
private void panel1_MouseMove(object sender, MouseEventArgs e)
        {

            if (flag)
                Cursor.Hide();
            else
                Cursor.Show();
            
            
        }

thnks bro,I tried this but it didnt work.:(

thnks bro,I tried this but it didnt work.:(

works fine just takes a few seconds to register.

Click the button wait a few secs and it will register not instant.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.