hi all,
so i'm pretty new to visual basic and i needed some functionality.
A drawing pad has been created and several buttons on it( on the form , see the screenshot). Each button represents a drawable figure. I've created a screenshot for you to see.
http://img231.imageshack.us/i/screenshotus.jpg/
So if you click for instance the rectangle you can draw a rectangle. ( it has been drawn already because i've click and dragged with my mouse ) If you click on the arc or the star , you can draw a star or arc.
This is the tricky part , I want to create a textbox just like when I'm creating my rectangle ( i've already added a button to the collection in the toolbar, it's the button T ) My rectangle class looks like this and inherits from Drawable class ( the star and arc class also inherit from this class ).
Imports System.Math
Imports System.Xml.Serialization
<Serializable()> _
Public Class DrawableRectangle
Inherits Drawable
' Constructors.'
Public Sub New()
End Sub
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
End Sub
' 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 the rectangles")
DrawGrabHandle(gr, X1, Y1)
DrawGrabHandle(gr, X1, Y2)
DrawGrabHandle(gr, X2, Y2)
DrawGrabHandle(gr, X2, Y1)
Else
' Just draw the rectangle.'
Dim fg_pen As New Pen(ForeColor, LineWidth)
gr.DrawRectangle(fg_pen, rect)
fg_pen.Dispose()
End If
End Sub
' Return the object's bounding rectangle.'
Public Overrides Function GetBounds() As System.Drawing.Rectangle
Return New Rectangle( _
Min(X1, X2), _
Min(Y1, Y2), _
Abs(X2 - X1), _
Abs(Y2 - Y1))
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
Now I figured in my draw function I already tried something like
ORIGINAL Else ' Just draw the rectangle.'
Dim fg_pen As New Pen(ForeColor, LineWidth) gr.DrawRectangle(fg_pen, rect) fg_pen.Dispose()
ADJUSTMENT FOR TEXTBOX
Else
Dim fg_pen As New Pen(ForeColor, LineWidth)
Dim drawFont As New Font("Arial", 13, FontStyle.Bold)
'with inputbox 'gr.DrawString(InputBox("Here input", , , 10, 10), drawFont, Brushes.Blue, X1, Y1)
gr.DrawString("Testing the drawstring", drawFont, Brushes.Brown, X1, Y1)
fg_pen.Dispose()
I was reading into the DrawTextBox object and i had a feeling i could use this as a solution to my problem. ( i can only post one hyperlink else I would have posted the link for the msdn website)
My questions are
a) is this indeed possible or do I need to do something else? b) if a is possible , what's the best way to realize this in my DrawableTextBox class