[RESOLVED] "Name" A Shape
Hello
I have this code:
Code:
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.FillEllipse(Brushes.Blue, 100, 100, 100, 100)
End Sub
How do I use this shape in the code? For example I want to be able to move it around using keydown events.
Thanks :)
Re: [RESOLVED] "Name" A Shape
The way you would make the initial code that dday posted global would be to move the declaration of pnl out of the sub and make it a form level variable. Then pnl would be available to any sub on the form.
I've worked with this kind of thing both ways. I was working on a program that had lots of drag and drop, but the number and location of the items was quite variable. I used Pictureboxes for those items, as dragging and dropping works best with controls. However, inside many of the pictureboxes could be up to eight other items that could be clicked, along with a few other items that could be dragged around. Initially, I went with Pictureboxes inside Pictureboxes, for the purpose of the drag and drop. I then realized that the eight items couldn't be dragged, but only clicked. What worked best for them was to draw them directly into the Picturebox that contained them, and not use a control at all. I also started out with the items that could be drawn as controls in the Picturebox, but that meant creating an arbitrarily large number of controls, which became a nightmare to manage, and all of which cost time and memory. At that point, I just started drawing things into the Pictureboxes.
Based on this experience, I would say that using controls, and moving them, works well for a small number of items. Once you get into the dozens, though, the cost of creating, maintaining, and manipulating, the controls begins to outweigh the benefits.