我想为矩形结构创建一个新属性,这样当我创建一个新的矩形时,我将能够指定一个额外的值(除了默认值)
例如默认值:
dim rect as new rectangle(x, y, width, height)
我希望能够声明如下内容:
dim rect as new rectangle (x, y, with, height, another_value as integer)
如何扩展矩形结构并添加新的构造函数?
答案 0 :(得分:0)
您可以创建一个使用Rectangle结构的类。
Public Class MyRect
Public Sub New({use your params for contructor})
Rect = New Rectangle({initilize from params})
End Sub
....
Public Property Rect As Rectangle
'more properties as needed
....
然后画出你的物体:
Dim _myRectObj As New MyRect({params for your constructor})
e.Graphics.DrawRectangle(_myRectObj.Rect, ....)