Confused about SubMain Form & Class flow

Posted on 2006-04-29
Last Modified: 2010-04-23
I am confused about Sub Main, Form & Class flow ..

I'm making a game and I'm gonna have to implement a game loop into the sub main.  But I need a form.  My question is how does the classes access controls on the form? What is the best way to handle this "flow". Do you see what I mean?

Module SubMain

  Private _frmGame as frmGame
  Private _clsObjects as clsObjects
  Private _clsData as clsData

  Public Sub Main
    _frmServer = new frmServer
    _clsUsers = new clsUsers
    _clsData = new clsData

  End Sub

End Module
Question by:Hepen
    LVL 48

    Expert Comment

    I am trying to guess whether you have previous experience in OpenGL - maybe game loop concept is taken from here.
    Windows application built using .NET platform contains internal message loop. Developer must implement event handlers in Windows forms.

    There is no need to customize SubMain and it must look by the following way:

    Module SubMain

      Public Sub Main
         Application.Run(new frmServer)
      End Sub

    End Module

    You must handle various events in frmServer. You need to create and show two additional forms in frmServer_OnLoad or othe place according to your needs. Draw screen in frmServer_OnPaint. Handle user commands in mouse and keyboard event handlers.

    Maybe I didn't understand what you mean, please give more details.
    Animations are done by timer: add timer to the form and redraw image with some change in timer event handler.
    LVL 3

    Expert Comment

    Alex gave you good info.

    But maybe this will help.

    Make your form your start up object.

    In the form create an instance of the class using withevents.

    In your class define the events you want the form to react to.

    In the class sub new create a timer and use it to do whatever you want and raise events back to your form at appropriate points.
    (use a System.Threading.Timer not  a System Timer .. Trust me on this one!!! The threading /snyc issues wil drive you crazy if you dont)

    In the form you just write code for the objects events (make sure the object was declared withevents)


    Author Comment

    CAn you give an example of events between a form and a class?
    LVL 96

    Accepted Solution

    Public Class formMain

       Private WithEvents Testing As New Tester

       Private Sub OnTestInitiated(ByVal sender As Object, ByVal e As EventArgs) Handles Testing.TestInitiated
       End Sub

    End Class

    Public Class Tester

       Public Event TestInitiated As EventHandler

       Public Sub Start()
           RaiseEvent TestInitiated(Me, EventArgs.Empty)
       End Sub

    End Class


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now