|
-
Mar 8th, 2010, 04:22 PM
#1
[RESOLVED] Graphics Rectangle
I am trying to have different types of rectangles. I thought something like this would work, but Rectangle is not a class.
Code:
Public Class xRectangle
Inherits Rectangle
End Class
What I wanted this for was to remove a selection rectangle from an existing drawing. I have all of the objects to draw stored in a list and I am trying to remove the selection rectangle without removing the object it is covering. Hope this makes a little sense.
-
Mar 8th, 2010, 07:33 PM
#2
Re: Graphics Rectangle
System.Drawing.Rectangle is a structure and you can't inherit structures, plain and simple. If you need a class that you can inherit then define your own base class and then inherit that. That base class can either wrap a Rectangle structure or define its own functionality from scratch.
-
Mar 8th, 2010, 08:00 PM
#3
Re: Graphics Rectangle
Thanks jmc! I have been working on this since posting the question and as usual your advice is great. (BTW - I (borrowed, copied, used,...) some code you had written for a line that computed the rectangle for the line.)
Does this seem like the right direction?
Code:
Public MustInherit Class Shape
Private _x, _y, _w, _h As Integer
Private _spt, _ept As Point
Private _r As Rectangle
Public Sub New(ByVal spt As Point, ByVal ept As Point)
'lines - thanks to jmc @ vbforums
'define a rectangle for the line
...
End Sub
Public Sub New(ByVal x As Integer, ByVal y As Integer, ByVal w As Integer, ByVal h As Integer)
'rectangle
...
End Sub
Public Property X() As Integer
Get
Return Me._x
End Get
Set(ByVal value As Integer)
Me._x = value
End Set
End Property
Public Property Y() As Integer
Get
Return Me._y
End Get
Set(ByVal value As Integer)
Me._y = value
End Set
End Property
Public Property Width() As Integer
Get
Return Me._w
End Get
Set(ByVal value As Integer)
Me._w = value
End Set
End Property
Public Property Height() As Integer
Get
Return Me._h
End Get
Set(ByVal value As Integer)
Me._h = value
End Set
End Property
End Class
Public Class dRectangle
Inherits Shape
Public Sub New(ByVal X As Integer, ByVal Y As Integer, _
ByVal Width As Integer, ByVal Height As Integer)
MyBase.New(X, Y, Width, Height)
End Sub
It seems like it is starting to come together.
Code:
Dim test As New dRectangle(0, 0, 10, 10)
-
Mar 8th, 2010, 08:17 PM
#4
Re: Graphics Rectangle
At a glance, yes, although there's not much point having your _x, _y, _w and _h fields as well as _r, given that a Rectangle structure contains that same information. If you're going to wrap a Rectangle structure then you don't really need your own fields.
-
Mar 9th, 2010, 08:52 AM
#5
Re: Graphics Rectangle
 Originally Posted by jmcilhinney
At a glance, yes, although there's not much point having your _x, _y, _w and _h fields as well as _r, given that a Rectangle structure contains that same information. If you're going to wrap a Rectangle structure then you don't really need your own fields.
Good point. I can't thank you enough. Some of your other posts are slowly getting me through understanding graphics. Yesterday for the first time I actually started to believe I might know what the hell was going on.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|