Reputation: 18159
Ok, I want to create a class that will handle a special rectangle graphic.
In my form, I want to have two of these special rectangles. So, basically, I need two instances of that class in my form, right?
I manage to initialize two, alright. But, how exactly am I supposed to manage drawing/graphics etc in a class, and the results to be displayed in my form?
Upvotes: 1
Views: 1495
Reputation: 81537
There are a few concepts you need to figure out to put this together:
Here's a quick snippet:
' suppose you have:
Private _myRects as New List(of Rectangle) ' populated elsewhere
' then you handle the paint event of a UI control
Private Sub Control_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) _
Handles MyBase.Paint
Dim g As Graphics = e.Graphics
' loop through your collection drawing each rectangle:
for each rect As Rectangle in _myRects
g.FillRectangle(Brushes.Aqua, rect)
next for
...more drawing as needed
end sub
And here is a pretty nice tutorial on .NET painting with VB. If you follow it through you should have all the pieces to do any kind of 2D .NET drawing you like. (The fun doesn't start until page 2 but do not skip page 1!)
Upvotes: 3
Reputation: 26883
Sounds like the two thing you need to read up on are Developing Custom Controls and Using GDI+ in Windows Forms.
Grab a comfy chair and a nice cup of hot cocoa; you have a lot of reading to do.
Upvotes: 0