Re: Extending System.Drawing.Rectangle...
Dave <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <000101c782db$f4f034a0$6400a8c0@omniscient1> |
Uh?
What about just casting the object from one to the other, with a cast
operator? Don't need 3.0 to do that... Although you need 2.0 to make it
clean, it's pretty easy with 1.0-1.1 with functions like ToRectangle() and
ctor(Rectangle)
Try that:
(And if you're not comfortable with VB, think of Reflector...)
Public Structure RectangleEx
Public m_x As Integer
Public m_y As Integer
Public m_w As Integer
Public m_h As Integer
Public Property X() As Integer
Get
Return m_x
End Get
Set(ByVal value As Integer)
m_x = value
End Set
End Property
Public Property Y() As Integer
Get
Return m_y
End Get
Set(ByVal value As Integer)
m_y = value
End Set
End Property
Public Property Width() As Integer
Get
Return m_w
End Get
Set(ByVal value As Integer)
m_w = value
End Set
End Property
Public Property Height() As Integer
Get
Return m_h
End Get
Set(ByVal value As Integer)
m_h = value
End Set
End Property
Public Sub New(ByVal x As Integer, ByVal y As Integer, ByVal width As
Integer, ByVal height As Integer)
m_x = x
m_y = y
m_w = width
m_h = height
End Sub
Public Shared Narrowing Operator CType(ByVal item As RectangleEx) As
Rectangle
Return New Rectangle(item.X, item.Y, item.Width, item.Height)
End Operator
Public Shared Widening Operator CType(ByVal item As Rectangle) As
RectangleEx
Return New RectangleEx(item.X, item.Y, item.Width, item.Height)
End Operator
End Structure
Have fun!
Dave.
www.omniscienttrader.com
www.omniscient.ca
-----Original Message-----
From: Discussion forum for developers using Windows Forms to build apps and
controls [mailto:[email protected]] On Behalf Of Chris
Anderson
Sent: April 18, 2007 2:28 AM
To: [email protected]
Subject: Re: [DOTNET-WINFORMS] Extending System.Drawing.Rectangle...
You'd probably need to wrap the Rectangle inside a new class and internally
use the Rectangle to perform standard Rectangle functionality, tgen add what
you want.
Of course you wouldn't be able to use the new class *as* a Rectangle where a
Rectangle was expected.
In .net 3.0 you *might* be able to use extension methods. ( not 100% sure if
you can use them on structs, but worth checking)
What extra functionality are you looking to add?
-----Original Message-----
From: "Gyorgy Bozoki"<[email protected]>
Sent: 18/04/07 05:30:47
To:
"[email protected]"<[email protected]>
Subject: [DOTNET-WINFORMS] Extending System.Drawing.Rectangle...
Hi all,
I have a question about extending structs: I'd like extend
System.Drawing.Rectangle such that it keeps all its existing functionality
and a set of new public members can be called. Since Rectangle is a
structure, it's sealed and cannot be derived from, so that route is
obviously out.
I could easily create a simple new class that would have all the
functionality of Rectangle and the extra functions that I want to add, but I
was wondering if doing this to Rectangle itself would even be technically
possible (for example during run time, if necessary.)
Thanks,
Gyorgy Bozoki
-----Unmodified Original Message-----
Hi all,
I have a question about extending structs: I'd like extend
System.Drawing.Rectangle such that it keeps all its existing functionality
and a set of new public members can be called. Since Rectangle is a
structure, it's sealed and cannot be derived from, so that route is
obviously out.
I could easily create a simple new class that would have all the
functionality of Rectangle and the extra functions that I want to add, but I
was wondering if doing this to Rectangle itself would even be technically
possible (for example during run time, if necessary.)
Thanks,
Gyorgy Bozoki