Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. VB6 Modules =? in C# ???

VB6 Modules =? in C# ???

Scheduled Pinned Locked Moved C#
questioncsharpdesignsysadmin
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    antoine orchus tech
    wrote on last edited by
    #1

    Hi, Remember the bad old days of VB6? You wanted a global variable, you added a module, and that was it. I know its bad programming... :p Now, my app loads one Form only. But, the app has a lot of classes that are created to deal with network data. How can I have the app's main Form(the ui) get modified by those other classes? How do you modify a form's progress bar from another class? ARgh.. Thanks for your help :) Antoine This by our hands that dream, "I shall find a way or make one!"

    J L 2 Replies Last reply
    0
    • A antoine orchus tech

      Hi, Remember the bad old days of VB6? You wanted a global variable, you added a module, and that was it. I know its bad programming... :p Now, my app loads one Form only. But, the app has a lot of classes that are created to deal with network data. How can I have the app's main Form(the ui) get modified by those other classes? How do you modify a form's progress bar from another class? ARgh.. Thanks for your help :) Antoine This by our hands that dream, "I shall find a way or make one!"

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Pass a reference of the Form instance to the class you want to modify. For example,

      // in the Form class, MyForm.cs
      OtherClass theOtherClass = new OtherClass(this);

      // in the other class
      public class OtherClass
      {
      MyForm myFormInstance = null;

      public OtherClass(MyForm frmInst)
      {
      this.myFormInstance = frmInst;

        this.myFormInstance.DoSomething();
      

      }
      }

      Of course you can always make your Form class have a public static variable to make it accessible from other classes, like so:

      public class MyForm : Form
      {
      public static MyForm TheFormInstance = null;

      public MyForm()
      {
      TheFormInstance = this;
      }
      }

      // in some other class (note that MyForm is the actual name of the class, not a class instance)
      MyForm.TheFormInstance.DoSomething();

      Now as far as using the singleton pattern above, Heath or some other very talented developer will chide me for not mentioning the correct way to do it (when using multiple threads and such). But the above code should suffice if you're just using one Form instance. :-) #include "witty_sig.h"

      A 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        Pass a reference of the Form instance to the class you want to modify. For example,

        // in the Form class, MyForm.cs
        OtherClass theOtherClass = new OtherClass(this);

        // in the other class
        public class OtherClass
        {
        MyForm myFormInstance = null;

        public OtherClass(MyForm frmInst)
        {
        this.myFormInstance = frmInst;

          this.myFormInstance.DoSomething();
        

        }
        }

        Of course you can always make your Form class have a public static variable to make it accessible from other classes, like so:

        public class MyForm : Form
        {
        public static MyForm TheFormInstance = null;

        public MyForm()
        {
        TheFormInstance = this;
        }
        }

        // in some other class (note that MyForm is the actual name of the class, not a class instance)
        MyForm.TheFormInstance.DoSomething();

        Now as far as using the singleton pattern above, Heath or some other very talented developer will chide me for not mentioning the correct way to do it (when using multiple threads and such). But the above code should suffice if you're just using one Form instance. :-) #include "witty_sig.h"

        A Offline
        A Offline
        antoine orchus tech
        wrote on last edited by
        #3

        hi! What is the correct way to do ti when using multiple threads? Thanks Antoine This by our hands that dream, "I shall find a way or make one!"

        J 1 Reply Last reply
        0
        • A antoine orchus tech

          hi! What is the correct way to do ti when using multiple threads? Thanks Antoine This by our hands that dream, "I shall find a way or make one!"

          J Offline
          J Offline
          Judah Gabriel Himango
          wrote on last edited by
          #4

          The search button is your friend: clickity[^] #include "witty_sig.h"

          1 Reply Last reply
          0
          • A antoine orchus tech

            Hi, Remember the bad old days of VB6? You wanted a global variable, you added a module, and that was it. I know its bad programming... :p Now, my app loads one Form only. But, the app has a lot of classes that are created to deal with network data. How can I have the app's main Form(the ui) get modified by those other classes? How do you modify a form's progress bar from another class? ARgh.. Thanks for your help :) Antoine This by our hands that dream, "I shall find a way or make one!"

            L Offline
            L Offline
            LongRange Shooter
            wrote on last edited by
            #5

            antoine@orchus-tech wrote: How can I have the app's main Form(the ui) get modified by those other classes? How do you modify a form's progress bar from another class? Your classes are not getting instantiated by the form??? The form could grab this info from the classes after they are created. If you need info established in a class and passed around then you could make that class using the Singleton pattern which involves alot of static methods and getter/setters. If the form must be modified from outside, then you expose public accessors (getter and setter) for internal fields and pass reference to that form to everyone from the central controller in the app. antoine@orchus-tech wrote: How do you modify a form's progress bar from another class? Go to the C# projects in this site and search for SplashScreen. There is one that is really good and demonstrates the ability of having a smooth status bar based on actual event timings. My class design is as such main form --> loads main class (contains some static methods etc main form --> loads splash screen main form --> calls each init step notifying SplashScreen of event end main form completes init --> calls SplashScreen with 'all done' event splash screen goes away. main form loads MainForm and shows it. Notice that the main class is still around and everything spawned by the main form has access to that class and its' methods. This is similar to the global thing in VB6 but a purer object approach. Search the net for c# patterns and then check on the Singleton pattern for more info. ______________________________ The Tao gave birth to machine language. Machine language gave birth to the assembler. The assembler gave birth to ten thousand languages. Each language has its purpose, however humble. Each language expresses the Yin and Yang of software. Each language has its place within the Tao. Beauty exists because we give a name to C#. Bad exists because we give a name to COBOL.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups