Results 1 to 15 of 15

Thread: creating forms

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73

    creating forms

    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
    Last edited by pea33nut; Jun 29th, 2004 at 11:45 AM.

  2. #2
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    I would put everything you can inside a class and just pass in references where applicable. I mean, if it is just one and two liners like most of that example seems to be, there isn't much code to be saved, and not much reason to anyways.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73
    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??

  4. #4
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    Well, it sounds like you need to create forms on the fly and store them in some kind of collection (array, linked list, whatever you like). As part of that form class you are going to want to store your number. Then when you selecdt the number somehow later on, you are going to want to step through your collection, compare against the number, and show the form that matches.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  5. #5
    Hyperactive Member dogfish227's Avatar
    Join Date
    Oct 2002
    Location
    GA
    Posts
    409
    i didnt read that whole first part but in answer to the question i have quoted you can use a hashtable to hold the form and use the number as a key.

    Originally posted by pea33nut
    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??

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73
    yeah, you got any hints on starting to code this beast?? Never used a hashtable before.

  7. #7
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    Look in the help, they are really pretty simple. You create one, probably with what you are doing, the default capacity and load factor, and then you add elements to it by key and value like

    Dim MyHashTable as New HashTable()

    MyHashTable.Add(1,MyNewForm1)

    Dim CurrentForm as MyForm1 = MyHashTable(1)

    CurrentForm.Show()
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  8. #8
    Hyperactive Member dogfish227's Avatar
    Join Date
    Oct 2002
    Location
    GA
    Posts
    409
    I would start with making the form that you will be drawing on work. look at the graphics object which is great for making a drawing program simmilar to paint.

  9. #9
    Hyperactive Member dogfish227's Avatar
    Join Date
    Oct 2002
    Location
    GA
    Posts
    409
    if you want an example go here:
    http://www.wrox.com/WileyCDA/WroxTit...load_code.html
    and download the code. chapter 14 is a simple drawing program

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73
    I have a form that allows me to draw. Some how I need to create blank forms in my code that allows the user to draw on. Is there a way that I can just use the form that I have my drawing program on and then maybe the user can just save it as a new name?

  11. #11
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    Your new form is a class now...i.e. Class Form1. So in your code you can create new instances of it.

    Dim NewForm as New Form1

    MyHashTable.Add(1,NewForm)
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73
    but it says that Form 1 is not defined

    Dim NewForm As New Form1
    Dim MyHashTable As New Hashtable

    MyHashTable.Add(1, NewForm)

    Dim CurrentForm As frmAddItemNumber = MyHashTable(1)

    CurrentForm.Show()

  13. #13
    Registered User LoNeR's Avatar
    Join Date
    Jun 2004
    Location
    Heliom Prime
    Posts
    20
    did you have a form that name form1?

    if none.

    VB Code:
    1. dim newform as new (NameOfYourForm)

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73
    Yes I do have a form1. this is the error that I get.

    An unhandled exception of type 'System.InvalidCastException' occurred in AndersenAsi.exe

    Additional information: Specified cast is not valid.

    As this statement is highlighted
    Dim CurrentForm As frmAddItemNumber = MyHashTable(1)

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73
    So what do I need to do, make a class?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width