vb.net - 如何在不使用继承类的情况下将形状绘制为对象
问题描述
我有一个类来绘制一些带有鼠标事件和一些属性的形状。如果我使用继承类(继承控件),则一切正常,否则没有什么可显示的。因为我将位置和大小的 myclass 设置为使用鼠标事件。如何在不使用继承类的情况下将形状作为对象。
Imports System
Imports System.Collections
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.ComponentModel
Public Class Shape
Public x1 As Integer
Public x2 As Integer
Public y1 As Integer
Public y2 As Integer
Public Sub New(x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer, ByRef g As Graphics)
MyBase.New()
Me.x1 = x1 : Me.x2 = x2 : Me.y1 = y1 : Me.y2 = y2
draw(g)
Me.Left = x1
Me.Top = y1
Me.Width = x2 - x1
Me.Height = y2 - y1
End Sub
Public Sub draw(ByRef egraphics As Graphics)
Dim _mybrush As Brush ' brush to fill vertex
_mybrush = New System.Drawing.SolidBrush(Color.White)
Dim _mypen As New Pen(Color.Black, 5) ' make pen to draw
_mypen.DashStyle = DashStyle.Solid
egraphics.FillRectangle(_mybrush, New Rectangle(x1, y1, (x2 - x1), (y2 - y1))) ' dont change between this line and next line if change you can not to see border
egraphics.DrawRectangle(_mypen, New Rectangle(x1, y1, (x2 - x1), (y2 - y1))) ' dont change between this line and next line if change you can not to see border
End Sub
End Class
解决方案
推荐阅读
- r - 将 R markdown 直接渲染到 S3 存储桶
- macos - NSSplitView 导致 NSScrollView 绘图错误?
- python - 在 IDLE 上创建 python 代码,然后在 macOS 终端中使用它
- javascript - React 提取嵌套的 json 对象
- javascript - 在 React Native 中调用不同文件中的列表?
- reactjs - 有没有一种奇特的方法来检测取消选中复选框?
- r - 如何创建“for”循环来创建包含 R 中 NA 的列向量?
- time-series - FBProphet:了解回归量对多元预测的影响
- ssl - 使用互联网调试 kubernetes pod 的 SSL 握手问题
- python - 如何使用 python 读取字体文件的特定属性?(独立于操作系统)