Solved

Custom Mouse Icon C#

Posted on 2009-04-14
3
232 Views
Last Modified: 2013-12-17
I have a listbox full of camera names. When I drag a name from the listbox onto a Panel I have it opening up a new (smaller) panel which then begins to display video. You can have as many windows open in the primary panel as desired. The problem is that when you have multiple cameras open its hard to position a new camera just right. What I want to do is when I drag over the primary panel I want a rectangle to be drawn that follows my mouse around until I let go, so I can see where the video will be exactly displayed. The panel is needs to be 240, 180 pixels. If anyone could provide c# code that accomplishes this I will reward them the 500 points.
0
Comment
Question by:Pretzel_Jesus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 24142236
Something like this should get you started:
    public partial class Form1 : Form
    {
 
        private int CursorWidth = 240;
        private int CursorHeight = 180;
 
        private void listBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                int index = listBox1.SelectedIndex;
                if (index != -1)
                {
                    listBox1.DoDragDrop(new DataObject("Camera", listBox1.Items[index].ToString()), DragDropEffects.All);
                }
            }
        }
 
        private void panel1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = e.Data.GetDataPresent("Camera") ? DragDropEffects.All : DragDropEffects.None;
        }
 
        private void listBox1_GiveFeedback(object sender, GiveFeedbackEventArgs e)
        {
            e.UseDefaultCursors = false;
            Bitmap bmp = new Bitmap(CursorWidth, CursorHeight);
            Graphics g = Graphics.FromImage(bmp);
            g.Clear(Color.Red);
            g.Dispose();
            panel1.Cursor = new Cursor(bmp.GetHicon());
        }
 
        private void panel1_DragDrop(object sender, DragEventArgs e)
        {
            PictureBox pb = new PictureBox();
            pb.BorderStyle = BorderStyle.FixedSingle;
            Point pt = panel1.PointToClient(Cursor.Position);
            pt.Offset(-CursorWidth/2, -CursorHeight/2);
            pb.Location = pt;
            pb.Size = new Size(240, 180);
            panel1.Controls.Add(pb);
            panel1.Cursor = Cursors.Default;
        }
 
    }

Open in new window

0
 

Author Comment

by:Pretzel_Jesus
ID: 24142701
Ok I see what you are doing here. Good idea. This partially works. I see the box appear exactly as I wanted, but it doesnt leave once I let go of the mouse button. How do I make it revert to the normal mousebutton once the dragging has been completed?
0
 

Author Closing Comment

by:Pretzel_Jesus
ID: 31570051
Actually I missed a line of code. Your code worked perfectly. Thanks!
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question