У меня есть вопрос, касающийся некоторых данных, которые передаются из одной формы в мой класс. Все идет не так, как мне хотелось бы, поэтому я подумал, что, возможно, найдется кто-то, кто сможет мне помочь.
Это мой код в моем классе
Public Class DrawableTextBox
Inherits Drawable
Dim i_testString As Integer
Private s_InsertLabel As String
Private drawFont As Font
Public Sub New(ByVal fore_color As Color, ByVal fill_color As Color, Optional ByVal line_width As Integer = 0, Optional ByVal new_x1 As Integer = 0, Optional ByVal new_y1 As Integer = 0, Optional ByVal new_x2 As Integer = 1, Optional ByVal new_y2 As Integer = 1)
MyBase.New(fore_color, fill_color, line_width)
X1 = new_x1
Y1 = new_y1
X2 = new_x2
Y2 = new_y2
Trace.WriteLine(s_InsertLabel)
End Sub
Friend WriteOnly Property _textBox() As String
Set(ByVal Value As String)
s_InsertLabel = Value
Trace.WriteLine(s_InsertLabel)
End Set
End Property
' Draw the object on this Graphics surface.
Public Overrides Sub Draw(ByVal gr As System.Drawing.Graphics)
' Make a Rectangle representing this rectangle.
Dim rect As Rectangle = GetBounds()
' Fill the rectangle as usual.
Dim fill_brush As New SolidBrush(FillColor)
gr.FillRectangle(fill_brush, rect)
fill_brush.Dispose()
' See if we're selected.
If IsSelected Then
' Draw the rectangle highlighted.
Dim highlight_pen As New Pen(Color.Yellow, LineWidth)
gr.DrawRectangle(highlight_pen, rect)
highlight_pen.Dispose()
' Draw grab handles.
Trace.WriteLine("drawing the lines for my textbox")
DrawGrabHandle(gr, X1, Y1)
DrawGrabHandle(gr, X1, Y2)
DrawGrabHandle(gr, X2, Y2)
DrawGrabHandle(gr, X2, Y1)
Else
'TextBox()
Dim fg_pen As New Pen(Color.Red, LineWidth)
'Dim fontSize As Single = 0.1 + ((Y2 - Y1) / 2)
Dim fontSize As Single = 20
Try
Dim drawFont As New Font("Arial", fontSize, FontStyle.Bold)
Trace.WriteLine(s_InsertLabel)
gr.DrawString(s_InsertLabel, drawFont, Brushes.Brown, X1, Y1)
Catch ex As ArgumentException
End Try
gr.DrawRectangle(Pens.Azure, rect)
' gr.DrawRectangle(fg_pen, rect)
fg_pen.Dispose()
End If
End Sub
Public Function GetValueString(ByVal ValueType As String)
Return ValueType
End Function
' Return the object's bounding rectangle.
Public Overrides Function GetBounds() As System.Drawing.Rectangle
Return New Rectangle( _
Min(X1, X2), _
Min(Y1, Y2), _
Abs(100), _
Abs(30))
Trace.WriteLine("don't forget to make variables in GetBounds DrawableTextbox")
End Function
' Return True if this point is on the object.
Public Overrides Function IsAt(ByVal x As Integer, ByVal y As Integer) As Boolean
Return (x >= Min(X1, X2)) AndAlso _
(x <= Max(X1, X2)) AndAlso _
(y >= Min(Y1, Y2)) AndAlso _
(y <= Max(Y1, Y2))
End Function
' Move the second point.
Public Overrides Sub NewPoint(ByVal x As Integer, ByVal y As Integer)
X2 = x
Y2 = y
End Sub
' Return True if the object is empty (e.g. a zero-length line).
Public Overrides Function IsEmpty() As Boolean
Return (X1 = X2) AndAlso (Y1 = Y2)
End Function
End Class
У меня есть форма с текстовым полем (form1), в которую текст вставляется и пропускается через нажатие кнопки (al через свойства).
Как видите, я поместил несколько трасс и в свойстве класса мой трассировщик работает нормально, однако, если я посмотрю в своей функции Draw, она уже пропала.
И я получил пустой след.
Кто-нибудь знает, что здесь происходит.
заранее спасибо.
(простите, я новичок)