0

Im looking to draw a map of dots(coordinates), i want to be able to select these dots later on by clicking on them. Is it better to use a picturebox for this or should i use a panel?

EDIT

Im drawing the dots from an array of values

AFract
  • 8,868
  • 6
  • 48
  • 70
FancyLord
  • 88
  • 13
  • Better is to use WPF and `Canvas`. – Dusan Jan 23 '18 at 09:35
  • which technology are you using? Winforms? WPF? etc... ? – Mong Zhu Jan 23 '18 at 09:49
  • Im using Windows Forms App – FancyLord Jan 23 '18 at 10:00
  • I added "winforms" in your question tags, it will be clearer. – AFract Jan 23 '18 at 10:22
  • Regarding the question, it depends. For example you can draw your image on a picture box and add invisible controls where your dots are located, and handle events on them. Or you can draw "visual" controls as your dots. It will depend of questions like : do you need to be able to add / remove dots at the fly ? – AFract Jan 23 '18 at 10:23
  • There are 2 area's, only when loading an area i need to draw the dots ( they will have to be drawn outside of the panel too so i must be able to scroll) – FancyLord Jan 23 '18 at 10:31
  • 1
    Use a **PictureBox** has DoubleBuffer enabled so It's much better. Just handle the Paint event of the PictureBox and do all your drawing in there. – Mohamed Sa'ed Jan 23 '18 at 11:07
  • Easiest approach: draw them on a panel, track their spatial and size characteristics, and then react to mouse clicks that fall into those spaces. If you need to actually make the dots do something, then they probably need to be controls of their own. Pictureboxes, more panels, whatever...choose what provides the behavior the dots need. So unless you need more behavior from the dots, just draw them. – DonBoitnott Jan 23 '18 at 16:19
  • i am currently thinking that it might be usefull to change to colour of a the selected dot or something, also i want to get the coordinates of the selected dot – FancyLord Jan 24 '18 at 07:50
  • And what have you tried so far ? – AFract Jan 24 '18 at 07:53
  • i am currently working on a panel, i asked the question before i started to check what i could use best – FancyLord Jan 24 '18 at 09:39

1 Answers1

0

When using a PictureBox, it's best to assign a Bitmap object to PictureBox.Image and then draw to the Bitmap, as that's how it's designed to work.

If you want to use Panel, you should use your own class that inherits from Panel so you can set the options as follows. It's probably the best option if you need scrollbars:

public class Canvas : Panel {

    public Canvas() {
        ResizeRedraw = true;
        DoubleBuffered = true;
    }
}
Bloopy
  • 305
  • 1
  • 9
  • Thanks!, tho is it possible to select items that i've drawn in the picturebox? – FancyLord Jan 25 '18 at 07:55
  • @user2928013 Yes, but there's a bit of work involved. When the control is clicked, use the mouse coordinates to figure out which dot was clicked (if any). You could then change its colour and redraw to show that it's been selected. – Bloopy Jan 26 '18 at 23:51
  • Will this be easier in a panel? – FancyLord Jan 31 '18 at 10:20
  • @user2928013 I suggest trying both. If you want scroll bars you'll need to put the PictureBox in a Panel anyway. But if you find you need to switch between different Bitmaps, then PictureBox would be more useful. – Bloopy Feb 01 '18 at 05:18