Link to home
Start Free TrialLog in
Avatar of madmare
madmareFlag for Israel

asked on

Mouse border in C#

Hii,
 How do i set a border to upear near the mouse pointer on my form, when i move the mouse pointer, the border move with it


thank you
Avatar of existenz2
existenz2
Flag of Netherlands image

The following code is an example. This code makes use of the MouseMoveEvent which only works when the mouse is placed upon the form. This can go wrong sometimes. You also can make it work outside the form, by creating a thread or timer which checks every few (mili)seconds if the position has changed and the refreshes the window.

using System;
using System.Drawing;
using System.Windows.Forms;

namespace MouseTest
{
      public class MainForm : System.Windows.Forms.Form
      {
            public MainForm()
            {
                  InitializeComponent();
            }
            
            [STAThread]
            public static void Main(string[] args)
            {
                  Application.Run(new MainForm());
            }
            
            private void InitializeComponent() {
                  //
                  // MainForm
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.ClientSize = new System.Drawing.Size(320, 285);
                  this.Name = "MainForm";
                  this.Text = "MainForm";
                  this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MainFormMouseMove);
            }
            #endregion
            void MainFormMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                  this.Width = Cursor.Position.X;
                  this.Height = Cursor.Position.Y;
            }
            
      }
}
Avatar of madmare

ASKER

i wanted to move a Rectangel when the mouse pointer is moveed, the Rectangle i wanted to be an aqua color thats mean it has a border but filled with NO color
ASKER CERTIFIED SOLUTION
Avatar of existenz2
existenz2
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of madmare

ASKER

what is this "moveRect" ?
moveRect is a boolean which can be either true or false. If it's false, the rectangle wont resize with the border when the form size is changed, if it's true the rectangle will resize with the border when the form size is changed. So it's only added to control the resizing from the rectangle.