Results 1 to 5 of 5

Thread: [RESOLVED] Graphics Rectangle

  1. #1

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Resolved [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.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    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)
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Graphics Rectangle

    Quote Originally Posted by jmcilhinney View Post
    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.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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
  •  



Click Here to Expand Forum to Full Width