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. .NET (Core and Framework)
  4. Reference Application MainForm or ApplicationContext

Reference Application MainForm or ApplicationContext

Scheduled Pinned Locked Moved .NET (Core and Framework)
questioncsharpwinforms
3 Posts 2 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.
  • G Offline
    G Offline
    GoDanno
    wrote on last edited by
    #1

    In a WinForms project, the Application.Run method can receive a Form parameter which becomes the main form of the application. According to the documentation, an ApplicationContext is automatically created. My question is, is it possible to get a reference to the MainForm of the application or the ApplicaitonContext that is automatically created? Thanks, Dan...

    J 1 Reply Last reply
    0
    • G GoDanno

      In a WinForms project, the Application.Run method can receive a Form parameter which becomes the main form of the application. According to the documentation, an ApplicationContext is automatically created. My question is, is it possible to get a reference to the MainForm of the application or the ApplicaitonContext that is automatically created? Thanks, Dan...

      J Offline
      J Offline
      John Arlen
      wrote on last edited by
      #2

      I'm not sure I understand exactly what you want to do, but the default Main() code looks like: [STAThread] static void Main() { Form1 form = new Form1(); Application.Run(form); } So the reference exists at that point. Obviously from within Form1, you have a reference with "this". The main questions would be - (1) where do you want to reference it? and (2) what specifically do you want to do with it?

      G 1 Reply Last reply
      0
      • J John Arlen

        I'm not sure I understand exactly what you want to do, but the default Main() code looks like: [STAThread] static void Main() { Form1 form = new Form1(); Application.Run(form); } So the reference exists at that point. Obviously from within Form1, you have a reference with "this". The main questions would be - (1) where do you want to reference it? and (2) what specifically do you want to do with it?

        G Offline
        G Offline
        GoDanno
        wrote on last edited by
        #3

        Well, I am trying to access the MainForm of the application from another form. So, I just decided to pass the MainForm as a parameter in a method of the other form. Thanks, Dan...

        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