none
How to change my cursor to an arrow??

    Question

  • What code do I write to make it so that when my cursor goes over top of an image in my RTB, it changes into the two sided arrow cursor used in most text programs, to show the user of the program that the image size can be modified?

    Sunday, April 27, 2008 2:50 AM

Answers

  • Hi, you should make a custom RichTextBox control to realize that feature.

     

    Here I have thought out a workaround, not fully realize that ,but you might get inspired from that.

    Code Snippet

     

                this.richTextBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.richTextBox1_MouseClick);
                this.richTextBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.richTextBox1_MouseMove);

     

     

            private void richTextBox1_MouseClick(object sender, MouseEventArgs e)
            {
                if (this.richTextBox1.SelectedRtf.IndexOf(@"\pict") != -1 && this.richTextBox1.SelectionType == RichTextBoxSelectionTypes.Object)
                {
                    MessageBox.Show("Image has been clicked!");
                }
            }


            private void richTextBox1_MouseMove(object sender, MouseEventArgs e)
            {
                if (this.richTextBox1.SelectedRtf.IndexOf(@"\pict") != -1 && this.richTextBox1.SelectionType == RichTextBoxSelectionTypes.Object)
                {
                    this.Cursor = Cursors.SizeNESW;
                }
                else
                {
                    this.Cursor = Cursors.Default;
                }
            }

     

     

    When you write your own custom control which inherited from RichTextBox control, you can also think about override the OnMouseMove, and OnMouseClick , check if it focus on the Image you added. Just a thinking, hope can help you.

     

    Wishes.

    Thursday, May 01, 2008 6:02 AM

All replies

  • Use something like:

     

    this.Cursor = Cursors.SizeNESW (or one of the others). Look here for what it can be set to. Use the Enter/Leave events to know when you are entering or leaving the image.

     

    Sunday, April 27, 2008 6:00 AM
  • How do I use enter/leave events? I'm really new to programming...

    Monday, April 28, 2008 2:17 AM
  •  TheTrueFace wrote:

    How do I use enter/leave events? I'm really new to programming...

     

    Hi, If you have a pictureBox control, You can do like:

     

    Code Snippet

    private void InitializeComponent()
            {

     

    ////Add the fulling code

         this.pictureBox1.MouseLeave += new System.EventHandler(this.pictureBox1_MouseLeave);
                this.pictureBox1.MouseEnter += new System.EventHandler(this.pictureBox1_MouseEnter);

     

    }

     

    Code Snippet

     

     private void pictureBox1_MouseEnter(object sender, EventArgs e)
            {
                this.Cursor = Cursors.Hand;

                //this.Cursor = Cursors.SizeNESW ;
            }

            private void pictureBox1_MouseLeave(object sender, EventArgs e)
            {
                this.Cursor = Cursors.Default;
            }

     

     

     

    And when you using Visual studio IDE, just focus on the Form or controls you are working on, and right click to open the menu and choose "Properites" opeing the property window , find the MouseEnter and MouseLeave event in the event tag of the properies window and double click to add them.

     

    Wishes. 

    Monday, April 28, 2008 6:19 AM
  • Hi TheTrueFace,

     

    If you are using picture box, then you can directly chage the picture box's properties Cursor = SizeNESW.
     
    Hope that, this may be help.

    Monday, April 28, 2008 6:48 AM
  • I do NOT have a picture box. I am randomly spawning an image out of no where with an INSERT IMAGE control. How do I make it so that this randomly spawned image will cause the cursor to change?

    Tuesday, April 29, 2008 3:29 AM
  • Hi, you should make a custom RichTextBox control to realize that feature.

     

    Here I have thought out a workaround, not fully realize that ,but you might get inspired from that.

    Code Snippet

     

                this.richTextBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.richTextBox1_MouseClick);
                this.richTextBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.richTextBox1_MouseMove);

     

     

            private void richTextBox1_MouseClick(object sender, MouseEventArgs e)
            {
                if (this.richTextBox1.SelectedRtf.IndexOf(@"\pict") != -1 && this.richTextBox1.SelectionType == RichTextBoxSelectionTypes.Object)
                {
                    MessageBox.Show("Image has been clicked!");
                }
            }


            private void richTextBox1_MouseMove(object sender, MouseEventArgs e)
            {
                if (this.richTextBox1.SelectedRtf.IndexOf(@"\pict") != -1 && this.richTextBox1.SelectionType == RichTextBoxSelectionTypes.Object)
                {
                    this.Cursor = Cursors.SizeNESW;
                }
                else
                {
                    this.Cursor = Cursors.Default;
                }
            }

     

     

    When you write your own custom control which inherited from RichTextBox control, you can also think about override the OnMouseMove, and OnMouseClick , check if it focus on the Image you added. Just a thinking, hope can help you.

     

    Wishes.

    Thursday, May 01, 2008 6:02 AM