473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How do I remove a shape on mouse click?

I'm trying to find out how to remove a shape on mouse click, but I can't find any solid information on how to do it. Is this possible at all? I'll be creating multiple shapes (They're the same shape, just in different locations) and I want to make it so that the user can remove individual shapes if necessary.

Can anyone please help me out with this one?
Mar 16 '11 #1
10 5834
GaryTexmo
1,501 Expert 1GB
It's your code, you can do whatever you like :P

For example, if your shapes inherit from Control and you're inserting them on a panel, you can quite easily remove them by attaching to the Shape's mouse events (whichever you like). If they are triggered, remove them from the Panel's control list.

That's just speculation though, you've actually said very little about what your program does. If you need any more specific help you're going to have to be more detailed. Tell us what you're trying to do, show us what you've done and what you've tried.
Mar 16 '11 #2
Expand|Select|Wrap|Line Numbers
  1. private void drawDesks(int rows, int cols)
  2.         {
  3.             int checkDimension;
  4.             if (rows > cols)
  5.                 checkDimension = rows;
  6.             else 
  7.                 checkDimension = cols;
  8.             int deskSize = setSizeOfDesks(checkDimension);
  9.             int deskSpace = setSpaceBetweenDesks(checkDimension);
  10.             int iDrawLocation = 0;
  11.             int jDrawLocation = 0;
  12.             int maxWidth = (deskSize + deskSpace) * cols;
  13.             int maxHeight = (deskSize + deskSpace) * rows;
  14.  
  15.             System.Drawing.SolidBrush b = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
  16.             System.Drawing.Graphics g = squareContainerPanel.CreateGraphics();
  17.  
  18.             for (int i = iDrawLocation; i < (maxWidth+iDrawLocation); i+=(deskSpace+deskSize))
  19.             {
  20.                 for (int j = jDrawLocation; j < (maxHeight+jDrawLocation); j += (deskSpace + deskSize))
  21.                 {
  22.                     g.FillRectangle(b, new Rectangle(i,j, deskSize, deskSize));
  23.                 }
  24.             }
  25.  
  26.             b.Dispose();
  27.             g.Dispose();          
  28.         }
Here's how I am adding them, but I'm not sure if I can refer to them individually as they don't have individual names.
Mar 17 '11 #3
GaryTexmo
1,501 Expert 1GB
Next time, it helps if you talk a bit about what you're trying to do. Give some background instead of just throwing code at us ;) That said, I think I get the idea from what you've posted, so lets talk about it.

What you have here looks to be just a display thing. You give it rows and columns and in response to that, it draws a series of desks. This means you don't have any actual objects to interact with, but it does mean you know where your desks are supposed to be at any given time.

You've got a panel, squareContainerPanel, that you're drawing in. That means you can add a listener to the MouseClick event so you can tell when, where mouse interaction took place on that panel. You can use that information to see if that mouse click was over top of one of your shapes. You've already got the code to generate the rectangles, so you know their bounds. A .NET Rectangle also has a Contains method that you can use to see if it contains a point. If it does, you can set some kind of flag somewhere not to draw that particular desk.

Now, I think it's worth pointing out that a change in architecture could make this a little easier for you. Currently, you don't keep track of your rectangles at all... you generate them every time you go to draw them and don't store them at all. Perhaps consider making a Desk class and pre-generating them into a member variable of type List<Desk>. Then all you have to do is draw them. It also helps you when it's time to see if the user is interacting with them. On the panel's mouse click event, you can loop through each Desk in your list and see if the mouse click interacted with that particular object, then take action. In your particular case, taking action would be removing it from the list so that it doesn't get drawn on the next update.

I hope that helps you, if you have any further questions please ask! :)
Mar 17 '11 #4
I've tried to implement what you mentioned, but I can't seem to access the panel when I use different classes.

Here's my slightly updated code:

Expand|Select|Wrap|Line Numbers
  1. private void drawDesks(int rows, int cols)
  2.         {
  3.             int checkDimension;
  4.             if (rows > cols)
  5.                 checkDimension = rows;
  6.             else 
  7.                 checkDimension = cols;
  8.             int deskSize = setSizeOfDesks(checkDimension);
  9.             int deskSpace = setSpaceBetweenDesks(checkDimension);
  10.             int iDrawLocation = 0;
  11.             int jDrawLocation = 0;
  12.             int maxWidth = (deskSize + deskSpace) * cols;
  13.             int maxHeight = (deskSize + deskSpace) * rows;
  14.  
  15.             List<Desk> desks = new List<Desk>();
  16.  
  17.             System.Drawing.SolidBrush b = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
  18.             System.Drawing.Graphics g = squareContainerPanel.CreateGraphics();
  19.  
  20.             for (int i = iDrawLocation; i < (maxWidth+iDrawLocation); i+=(deskSpace+deskSize))
  21.             {
  22.                 for (int j = jDrawLocation; j < (maxHeight+jDrawLocation); j += (deskSpace + deskSize))
  23.                 {
  24.                     desks.Add(new Desk(i, j, deskSize, deskSize));
  25.                 }
  26.             }
  27.  
  28.             foreach (Desk d in desks)
  29.                 d.drawDesk();
  30.  
  31.             b.Dispose();
  32.             g.Dispose();
  33.  
  34.  
  35.         }

Expand|Select|Wrap|Line Numbers
  1. class Desk
  2.     {
  3.         int xPos, yPos, nWidth, nHeight;
  4.  
  5.         public Desk(int xPos, int yPos, int nWidth, int nHeight)
  6.         {
  7.             this.nWidth = nWidth;
  8.             this.nHeight = nHeight;
  9.             this.xPos = xPos;
  10.             this.yPos = yPos;
  11.         }
  12.  
  13.         public void drawDesk()
  14.         {
  15.             g.FillRectangle(b, new Rectangle(xPos, yPos, nWidth, nHeight));      
  16.         }
  17.     }
I get the error that b and g doesn't exist in the current context.

Am I doing this right? Using the two loops to get the correct coordinates and putting them as desks in the list? And then calling a drawDesk method to draw them all out again.

Thank you so much for all the help you give me! I'm learning a lot as I go along.
Mar 17 '11 #5
GaryTexmo
1,501 Expert 1GB
The error messages speak for themselves, the objects you're trying to access don't exist in the scope you're trying to access them in. You created them in an entirely different method.

Also, you're creating the desks in the same method you're drawing them in. Which means you're creating them every single draw... you're either going to end up with a lot of extra objects.

In your Desk class, the DrawDesk method should probably take a parameter that's a Graphics object, then you can use that to draw.

Let me give you a rough sketch of what I'm trying to explain, maybe that will help :)

Expand|Select|Wrap|Line Numbers
  1. public class Desk
  2. {
  3.   // Same stuff you already have, but maybe add this...
  4.   private Color m_deskColor;
  5.   public Color DeskColor
  6.   {
  7.     get { return m_deskColor; }
  8.     set { m_deskColor = value; }
  9.   }
  10.   ...
  11.  
  12.   public void Draw(Graphics g)
  13.   {
  14.     if (g != null)
  15.     {
  16.       g.FillRectangle(new SolidBrush(drawColor, ...);
  17.     }
  18. }
Then your main class might look something like...

Expand|Select|Wrap|Line Numbers
  1. public partial class Form1 : Form
  2. {
  3.   private List<Desk> m_deskList = new List<Desk>();
  4.  
  5.   public Form1()
  6.   {
  7.     ...
  8.     CreateDesks(); // This form does whatever you're already doing to create the desks and stores them in m_deskList
  9.   }
  10.  
  11.   protected override void OnPaint(PaintEventArgs e)
  12.   {
  13.     // Note, this is the form's paint event, you might want to add a listener to the event on your panel, whatever you want to do...
  14.     base.OnPaint(e);
  15.  
  16.     Graphics g = e.Graphics;
  17.     foreach (Desk d in m_deskList)
  18.       d.Draw(g);
  19.   }
  20. }
You want your list of desk objects to live at the class level so that it can be used by other methods. The idea is to create a list of data and have the draw method only display it. It's just a means of visually showing the state of your program and shouldn't ever create new, persistent data.
Mar 18 '11 #6
I'm quite late in replying but I've just gone back to working on this part of my program. I'm trying to figure out how to remove a particular shape in my grid and I'm using a MouseClick event to find out the coordinates of the click.

The only thing I can think of is recording the x,y coordinates that the user clicks and adding them to a list, and then after every click I could redraw the grid, but also look into the list of "bad coords" and if a shape attempts to draw within a certain width/height of the shape I wouldn't let it. I can't really see how this could work though as there up to 900 potential pixels per shape that a user could click.

Here's the code for the form:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace ExamsHelper
  11. {
  12.     public partial class RoomDesigner : Form
  13.     {
  14.         private List<Desk> m_deskList = new List<Desk>();
  15.  
  16.         string roomName;
  17.         private int rows;
  18.         private int cols;
  19.  
  20.         public RoomDesigner(int r, int c)
  21.         {
  22.             Text = "Room Designer - Currently editing: ";
  23.             rows = r;
  24.             cols = c;
  25.             InitializeComponent();
  26.             this.StartPosition = FormStartPosition.CenterParent;
  27.             this.TopMost = true;
  28.  
  29.             squareContainerPanel.MouseClick += new MouseEventHandler(squareContainerPanel_MouseClick);
  30.  
  31.         }
  32.  
  33.         private void squareContainerPanel_MouseClick(object sender, MouseEventArgs e)
  34.         {
  35.             int xcoord = e.X;
  36.             int ycoord = e.Y;
  37.  
  38.             foreach(Desk d in m_deskList)
  39.             {
  40.                 if(d.Contains(xcoord, ycoord))
  41.                 {
  42.                     // code to remove the shape
  43.                 }
  44.             }
  45.         }
  46.  
  47.         private void drawDesks(int rows, int cols)
  48.         {
  49.             int checkDimension;
  50.             if (rows > cols)
  51.                 checkDimension = rows;
  52.             else 
  53.                 checkDimension = cols;
  54.             int deskSize = setSizeOfDesks(checkDimension);
  55.             int deskSpace = setSpaceBetweenDesks(checkDimension);
  56.             int iDrawLocation = 0;
  57.             int jDrawLocation = 0;
  58.             int maxWidth = (deskSize + deskSpace) * cols;
  59.             int maxHeight = (deskSize + deskSpace) * rows;
  60.  
  61.             System.Drawing.SolidBrush b = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
  62.             System.Drawing.Graphics g = squareContainerPanel.CreateGraphics();
  63.  
  64.             for (int i = iDrawLocation; i < (maxWidth+iDrawLocation); i+=(deskSpace+deskSize))
  65.             {
  66.                 for (int j = jDrawLocation; j < (maxHeight+jDrawLocation); j += (deskSpace + deskSize))
  67.                 {
  68.                     m_deskList.Add(new Desk(i, j, deskSize, deskSize));
  69.                 }
  70.             }
  71.  
  72.             foreach (Desk d in m_deskList)
  73.                 d.Draw(g, b);
  74.  
  75.             b.Dispose();
  76.             g.Dispose();
  77.  
  78.  
  79.         }
  80.  
  81.         private int setSizeOfDesks(int checkDimension) // fit inside 490-510 incl space
  82.         {
  83.             if (checkDimension <= 5)
  84.                 return 50;
  85.             else if (checkDimension <= 10)
  86.                 return 55;
  87.             else if (checkDimension <= 15)
  88.                 return 28;
  89.             else if (checkDimension <= 20)
  90.                 return 20;
  91.             else if (checkDimension <= 25)
  92.                 return 15;
  93.             else if (checkDimension <= 30)
  94.                 return 15;
  95.             else return 0;
  96.         }
  97.  
  98.         private int setSpaceBetweenDesks(int checkDimension)
  99.         {
  100.             if (checkDimension <= 5)
  101.                 return 20;
  102.             else if (checkDimension <= 10)
  103.                 return 20;
  104.             else if (checkDimension <= 15)
  105.                 return 6;
  106.             else if (checkDimension <= 20)
  107.                 return 5;
  108.             else if (checkDimension <= 25)
  109.                 return 4;
  110.             else if (checkDimension <= 30)
  111.                 return 7;
  112.             else return 0;
  113.         }
  114.  
  115.         private void button1_Click(object sender, EventArgs e)
  116.         {
  117.             drawDesks(rows, cols);
  118.         }
  119.  
  120.         private void setNameButton_Click(object sender, EventArgs e)
  121.         {
  122.             roomName = "";
  123.             toolStripLabel.Text = "Currently editing: ";
  124.             Text = "Room Designer - Currently editing: ";
  125.             roomName = roomNameTB.Text;
  126.  
  127.             Text += roomName;
  128.  
  129.             toolStripLabel.Text += roomName + " which is a " + rows + " by " + cols + " room";
  130.         }
  131.  
  132.         protected override void OnPaint(PaintEventArgs e)
  133.         {
  134.             drawDesks(rows, cols);
  135.         }
  136.     }
  137.  
  138.     class Desk
  139.     {
  140.         int xPos, yPos, nWidth, nHeight;
  141.  
  142.         private Color m_deskColour;
  143.  
  144.         public Color DeskColour
  145.         {
  146.             get { return m_deskColour; }
  147.             set { m_deskColour = value; }
  148.         }
  149.  
  150.         public Desk(int xPos, int yPos, int nWidth, int nHeight)
  151.         {
  152.             this.nWidth = nWidth;
  153.             this.nHeight = nHeight;
  154.             this.xPos = xPos;
  155.             this.yPos = yPos;
  156.         }
  157.  
  158.         public void Draw(Graphics g, Brush b)
  159.         {
  160.             if (g != null)
  161.             {
  162.                 g.FillRectangle(b, new Rectangle(xPos, yPos, nWidth, nHeight));
  163.             }
  164.         }
  165.  
  166.         public bool Contains(int x, int y)
  167.         {
  168.             if (x >= xPos && x < xPos + nWidth && y >= yPos && y < yPos + nHeight)
  169.                 return true;
  170.             else
  171.                 return false;
  172.         } 
  173.     }
  174. }
  175.  
I've tried to follow what you say, and you're teaching me a lot in answering all of the questions you ask!

Thank you very much.
Mar 25 '11 #7
GaryTexmo
1,501 Expert 1GB
The key part here is that you're not drawing the shapes quite right. You've got a button click event and when that button is clicked, you generate and draw the items on the form, but that's the only time this happens. If you want the shapes to generate in response to the button, that's totally fine, but you need to have the drawing done on the form's paint event. If you don't, anytime the form updates it's going to erase your desks. To demonstrate this, click your button, then drag another window over your form and off again.

In my post before this one, post #6, you can see code for how to do this. Your button should generate the list of desks but not draw them. Your paint event will draw them.

Now, on your mouse click, you can check to see if the mouse coordinate is contained by the desk. If it is, remove it from the draw list. When you do that, you'll also want to make a call to this.Invalidate() to cause your form to redraw, thus removing the desk from the screen.

You don't need to store the list of click coordinates, you can just test every shape and remove any that overlap with the mouse coordinates. Unless you have a lot of shapes (like thousands), you should be able to just loop through the entire list and remove it. Since the shape is gone from the draw list, it won't get drawn on the next update (which you force after you remove a shape) and it will be gone. You also don't need to worry about this test... a simple bounding box is pretty quick, you're not testing every pixel, you're just seeing if the point coordinates are inside a box. You've already got the correct math for this so that's just fine.

If it is the case where you've got thousands of desks and the test to see if the mouse clicked on one is just taking too long, you can look at a more optimized virtual space organizer. I recommend a QuadTree and I've actually got an insight with code for one I made not too long ago. You can find it here: http://bytes.com/topic/c-sharp/insig...implementation

It all depends on how many desks you draw. In looking at your code, I don't see you drawing more than a couple hundred, and a simple sequence is more than sufficient.

You're on the right track and almost there, keep going! :)
Mar 25 '11 #8
GaryTexmo
1,501 Expert 1GB
At the risk of confusing things, I'm going to add something else. If you make your Desk inherit from Control, you'll have access to all the events that a Control has. Instead of drawing them on the form, you can simply add each Desk to a Panel's Control list.

That means you'll be able to add an event listener to the Click event on each desk, which gives you two advantages:

1) You won't have to test each object in your list.
2) You won't have to worry about ordering. The controls handle that themselves, so you can use things like BringToFront and SendToBack. You also know that the Click event happens on that control, whereas checking mouse coordinates mean you can potentially get more than one item if your items overlap.

Something to think about.

I think in the near future I'm going to write an insight on this topic. It's come up enough that it might be helpful. Note to self... remember this :D
Mar 25 '11 #9
I believe I'm almost there, just one final hurdle that I can't figure out. I've managed to make it so that the rectangles are invisible, but when I click I get the "boo" message, and if I click there again, the message doesn't appear. This means it was removed, right?

I've tried sending the panel to the back, bringing the Desks to the front, and I still can't figure out how to make these things visibile.

I've only changed a couple of things (such as using a for loop to check if the desk was clicked). I played around with having Desk inherit from Control but I wasn't able to get that going.

I also get a red border and a red cross through my form. Not sure what's going on there.

Here's my code, maybe you can spot what's wrong.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace ExamsHelper
  11. {
  12.     public partial class RoomDesigner : Form
  13.     {
  14.         private List<Desk> m_deskList = new List<Desk>();
  15.  
  16.         private SolidBrush b;
  17.         private Graphics g;
  18.  
  19.         string roomName;
  20.         private int rows;
  21.         private int cols;
  22.  
  23.         public RoomDesigner(int r, int c)
  24.         {
  25.             Text = "Room Designer - Currently editing: ";
  26.             rows = r;
  27.             cols = c;
  28.             InitializeComponent();
  29.             this.StartPosition = FormStartPosition.CenterParent;
  30.             this.TopMost = true;
  31.  
  32.             drawDesks(rows, cols);
  33.  
  34.             squareContainerPanel.MouseClick += new MouseEventHandler(squareContainerPanel_MouseClick);
  35.  
  36.         }
  37.  
  38.         private void squareContainerPanel_MouseClick(object sender, MouseEventArgs e)
  39.         {
  40.             int xcoord = e.X;
  41.             int ycoord = e.Y;
  42.  
  43.             for (int i = m_deskList.Count - 1; i >= 0; i--)
  44.             {
  45.                 Desk d = (Desk)m_deskList[i];
  46.                 if (d.Contains(xcoord, ycoord))
  47.                 {
  48.                     MessageBox.Show("boo");
  49.                     m_deskList.Remove(d);
  50.                     squareContainerPanel.Invalidate();
  51.                 }
  52.             }
  53.         }
  54.  
  55.         private void drawDesks(int rows, int cols)
  56.         {
  57.             int checkDimension;
  58.             if (rows > cols)
  59.                 checkDimension = rows;
  60.             else 
  61.                 checkDimension = cols;
  62.             int deskSize = setSizeOfDesks(checkDimension);
  63.             int deskSpace = setSpaceBetweenDesks(checkDimension);
  64.             int iDrawLocation = 0;
  65.             int jDrawLocation = 0;
  66.             int maxWidth = (deskSize + deskSpace) * cols;
  67.             int maxHeight = (deskSize + deskSpace) * rows;
  68.  
  69.             b = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
  70.             g = squareContainerPanel.CreateGraphics();
  71.  
  72.             for (int i = iDrawLocation; i < (maxWidth+iDrawLocation); i+=(deskSpace+deskSize))
  73.             {
  74.                 for (int j = jDrawLocation; j < (maxHeight+jDrawLocation); j += (deskSpace + deskSize))
  75.                 {
  76.                     m_deskList.Add(new Desk(i, j, deskSize, deskSize));
  77.                 }
  78.             }
  79.  
  80.             foreach (Desk d in m_deskList)
  81.                 d.Draw(g, b);
  82.  
  83.             b.Dispose();
  84.             g.Dispose();  
  85.         }
  86.  
  87.         protected override void OnPaint(PaintEventArgs e)
  88.         {
  89.             base.OnPaint(e);
  90.  
  91.             Graphics g = e.Graphics;
  92.             foreach (Desk d in m_deskList)
  93.                 d.Draw(g,b);
  94.         }
  95.  
  96.         private int setSizeOfDesks(int checkDimension) // fit inside 490-510 incl space
  97.         {
  98.             if (checkDimension <= 5)
  99.                 return 50;
  100.             else if (checkDimension <= 10)
  101.                 return 55;
  102.             else if (checkDimension <= 15)
  103.                 return 28;
  104.             else if (checkDimension <= 20)
  105.                 return 20;
  106.             else if (checkDimension <= 25)
  107.                 return 15;
  108.             else if (checkDimension <= 30)
  109.                 return 15;
  110.             else return 0;
  111.         }
  112.  
  113.         private int setSpaceBetweenDesks(int checkDimension)
  114.         {
  115.             if (checkDimension <= 5)
  116.                 return 20;
  117.             else if (checkDimension <= 10)
  118.                 return 20;
  119.             else if (checkDimension <= 15)
  120.                 return 6;
  121.             else if (checkDimension <= 20)
  122.                 return 5;
  123.             else if (checkDimension <= 25)
  124.                 return 4;
  125.             else if (checkDimension <= 30)
  126.                 return 7;
  127.             else return 0;
  128.         }
  129.  
  130.         private void button1_Click(object sender, EventArgs e)
  131.         {
  132.             /**foreach (Desk d in m_deskList)
  133.             {
  134.                 d.Draw(g, b);
  135.             }**/
  136.         }
  137.  
  138.         private void setNameButton_Click(object sender, EventArgs e)
  139.         {
  140.             roomName = "";
  141.             toolStripLabel.Text = "Currently editing: ";
  142.             Text = "Room Designer - Currently editing: ";
  143.             roomName = roomNameTB.Text;
  144.  
  145.             Text += roomName;
  146.  
  147.             toolStripLabel.Text += roomName + " which is a " + rows + " by " + cols + " room";
  148.         }
  149.     }
  150.  
  151.     class Desk
  152.     {
  153.         int xPos, yPos, nWidth, nHeight;
  154.  
  155.         private Color m_deskColour;
  156.  
  157.         public Color DeskColour
  158.         {
  159.             get { return m_deskColour; }
  160.             set { m_deskColour = value; }
  161.         }
  162.  
  163.         public Desk(int xPos, int yPos, int nWidth, int nHeight)
  164.         {
  165.             this.nWidth = nWidth;
  166.             this.nHeight = nHeight;
  167.             this.xPos = xPos;
  168.             this.yPos = yPos;
  169.         }
  170.  
  171.         public void Draw(Graphics g, SolidBrush b)
  172.         {
  173.             if (g != null)
  174.             {
  175.                 g.FillRectangle(b, new Rectangle(xPos, yPos, nWidth, nHeight));
  176.             }
  177.         }
  178.  
  179.         public bool Contains(int x, int y)
  180.         {
  181.             if (x >= xPos && x < xPos + nWidth && y >= yPos && y < yPos + nHeight)
  182.                 return true;
  183.             else
  184.                 return false;
  185.         } 
  186.     }
  187. }
  188.  
  189.  
You're the best Gary!
Mar 26 '11 #10
GaryTexmo
1,501 Expert 1GB
I copied and pasted your code into a new solution and, with minimal tweaking, was able to get it to work. There's a couple of issues you'll want to fix...

1) I didn't realize you had this setup when I suggested it, but you're doing your drawing on the form but trapping clicks on the panel. Remove the override to the OnPaint method of your form and add an event listener to the Paint method for your squareContainerPanel object. The same code as you have for your Form paint goes there, with the exception of the call to base.

2)Remove the draw loop from drawDesks(...) and replace it with a call to the Invalidate method on the squareContainerPanel object. Better to let the systems you already have in place handle drawing.

3) You didn't comment on it, but I was getting an error on the call to FillRectangle. It was throwing a "Parameter is not valid." exception. It took me a while to track down the cause, but it's because at the end of your drawDesks(...) method, you call dispose on the brush you ultimately pass to the Desk class's draw method. Remove the call to dispose (and actually, you can even remove the Graphics object you set up (and subsequently dispose) there as well.

After fixing those, everything worked fine. The desks popped up on the panel and when I clicked one I got a message box. I closed the message box and the desk was taken out of the list and stopped drawing.

Regarding the method of having the Desk inherit from Control, I'll write an insight on this in the near future. Keep an eye out, I'll hopefully be able to find time to write it this week.
Mar 28 '11 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: BadOmen | last post by:
I want my program to send a mouse click to the window at the current mouse position, how do I do that? Example: I have my mouse over a button in Word and then my program is sending the left...
2
by: Serge | last post by:
Hi, in my windows.forms application I have added a goupBox control to my windows.form. Now I want to know the x,y-position from the mouse cursor when I click on the groupBox. The strange thing...
12
by: mdb | last post by:
My app has a notify icon in the systray. I want the left mouse click to initiate a menu, and a right-mouse click to do something else. Normally, for a button, I would listen to MouseDown and if I...
1
by: wesmanjunk | last post by:
Receiving mouse click from anywhere on the desktop. Then using mouse_event to generate a mouse click in the same location. I have made the code to use mouse_event to generate a click anywhere on...
4
by: Prateek | last post by:
Hi All, I have created an ASP.NET page that basically consists of a table having text boxes in all cells. The table is created using client side java script. There are some calculations being...
4
by: aam | last post by:
i'm trying to find the coordinates of a certain button on a page that i'm viewing so i can program the mouse to click on it automatically every so many seconds. either that or have the mouse click...
24
by: aam | last post by:
hi, im trying to figure out how i can program the mouse to automatically click on a button of a web page that i'm viewing.i do not have control over the page.i would also like to set up an...
3
by: Gary Kahrau | last post by:
How do I programatically apply a click to a particular row and column 0 of a datagrid? I want to do this in code as if the user did a mouse click on the leftmost column. ...
5
by: moonie | last post by:
I have an msn style c# windows application with a form and panel on it. A news list is drawn from the database and dynamically added via labels, link lables during form loading. In this...
1
by: hamidnourashraf | last post by:
I'm wondering if it's possible to invoke a mouse click anywhere. I don't mean invoke a mouse click event but, the actual mouse click itself. For instance, If I had my mouse over the "my computer"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.