How do I simplify this

JustinN

Member
Joined
Jun 28, 2004
Messages
18
I have 2 classes (Graphics circle, Graphics Item) Than I have a form that calls these classes and code to draw on this form. what do I need to do to use this code through out my program without using all of this code.

Public Class frmdraw
Inherits System.Windows.Forms.Form
enums....
Public Enum GraphicsTools As Integer
CirclePen = 0
End Enum
Public Enum GraphicsSizes As Integer
Small = 4
Medium = 10
Large = 20
End Enum
members.....
Public GraphicsItem As New ArrayList
Public GraphicTool As GraphicsTools = GraphicsTools.CirclePen
Public GraphicsSize As GraphicsSizes = GraphicsSizes.Large
Public GraphicColor As Color = Color.Black
DoMousePaint - respond to a mouse movement....
Private Sub DoMousePaint(ByVal e As MouseEventArgs)
store the new item somewhere...
Dim newItem As GraphicsItem
what tool are you using?
Select Case GraphicTool
circlepen?
Case GraphicTool.CirclePen
create a new graphics circle...
Dim circle As New GraphicsCircle
circle.SetPoint(e.X, e.Y, GraphicsSize, GraphicColor, True)
store this for addition...
newItem = circle
End Select
where you given an item?
If Not newItem Is Nothing Then
add it to the list...
GraphicsItem.Add(newItem)
invalidate...
Invalidate()

End If

End Sub
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)

is the button down?
If e.Button = MouseButtons.Left Then
DoMousePaint(e)
End If



End Sub
Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
is the button down?
If e.Button = MouseButtons.Left Then
DoMousePaint(e)
End If
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
go through the list...
Dim item As GraphicsItem
For Each item In GraphicsItem
ask each item to draw itself
item.Draw(e.Graphics)
Next
End Sub
 
Maybe im going about this all wrong. I have a small form with a textbox and an add button. The user can type in a number in the textbox and then click the add button. I want this to add the number to the database (which I already can do) and then load a form in which the user can draw on. This form needs to be linked with the number that the user ented in the textbox. so that the user can select the number later and it will bring up that form with the drawing on it.
What do you think??
 
Try having the user draw in a control in the form (a picbox perhaps) and then saving the drawing as an image in the database. Then you can have a "blank" form and load the delected "drawing" into the picture box for viewing/editing, what-have-you.
 
You could serialize the GraphicsItem ArrayList and store that in the DB - just associate it with the number the user entered.
This could then be deserialized when the form is loaded from the DB - if you need to keep the items editable this should work - if you just store the resulting image then you wouldnt be able to edit the items later.
 
Back
Top