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. Accessing Form Components from another class(namespace)

Accessing Form Components from another class(namespace)

Scheduled Pinned Locked Moved C#
csharpcomtoolsquestion
8 Posts 4 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.
  • P Offline
    P Offline
    Programm3r
    wrote on last edited by
    #1

    Hi all, I would like to know whether it is possible to access form components from a class which is in another namespace. If not why did they decide to develop C# like that? Many Thanks in advance Regards,


    The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

    P 1 Reply Last reply
    0
    • P Programm3r

      Hi all, I would like to know whether it is possible to access form components from a class which is in another namespace. If not why did they decide to develop C# like that? Many Thanks in advance Regards,


      The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Programm3r wrote:

      I would like to know whether it is possible to access form components from a class which is in another namespace

      Yes.

      Deja View - the feeling that you've seen this post before.

      My blog | My articles

      P 1 Reply Last reply
      0
      • P Pete OHanlon

        Programm3r wrote:

        I would like to know whether it is possible to access form components from a class which is in another namespace

        Yes.

        Deja View - the feeling that you've seen this post before.

        My blog | My articles

        P Offline
        P Offline
        Programm3r
        wrote on last edited by
        #3

        Thanks you for the reply Pete. Is it possible that you could perhaps give me an example or a link of which you may know where I can see such an occurance? Many thanks in advance Regards,


        The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

        P J 2 Replies Last reply
        0
        • P Programm3r

          Thanks you for the reply Pete. Is it possible that you could perhaps give me an example or a link of which you may know where I can see such an occurance? Many thanks in advance Regards,


          The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          Hmmm.

          namespace MyNamespace1
          {
          public partial class MyForm : Form
          {
          MyForm()
          {
          ....
          }
          public string MyValue{ get ; set; }
          }
          }

          namespace MyNamespace2
          {
          public partial class MyForm2 : Form
          {
          private MyNamespace1.MyForm _form
          public MyForm2()
          {
          _form = new MyNamespace1.MyForm();
          _form.MyValue = "Weyhey.";
          }

          }
          }

          Deja View - the feeling that you've seen this post before.

          My blog | My articles

          P 1 Reply Last reply
          0
          • P Programm3r

            Thanks you for the reply Pete. Is it possible that you could perhaps give me an example or a link of which you may know where I can see such an occurance? Many thanks in advance Regards,


            The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

            J Offline
            J Offline
            Jesse Squire
            wrote on last edited by
            #5

            Any time that you are accessing something from the base class library, you are accessing code that lives in another namespace. For an explicit example, create a console application and observe the default namespace assigned to your code. Now, add a call to Console.WriteLine and output some text. If you place your mouse pointer over the word Console, you'll notice that it is a class defined in the System namespace. Thus, you have just accessed a class defined in another namespace. I get the feeling, however, that this is not the question that you meant to ask. You may wish to try rephrasing so that your intended question is a bit more clear. Hope that helps. :)

            --Jesse

            "... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi

            1 Reply Last reply
            0
            • P Pete OHanlon

              Hmmm.

              namespace MyNamespace1
              {
              public partial class MyForm : Form
              {
              MyForm()
              {
              ....
              }
              public string MyValue{ get ; set; }
              }
              }

              namespace MyNamespace2
              {
              public partial class MyForm2 : Form
              {
              private MyNamespace1.MyForm _form
              public MyForm2()
              {
              _form = new MyNamespace1.MyForm();
              _form.MyValue = "Weyhey.";
              }

              }
              }

              Deja View - the feeling that you've seen this post before.

              My blog | My articles

              P Offline
              P Offline
              Programm3r
              wrote on last edited by
              #6

              Hmmm ... So The code below will create a new instance of the first form, right? Now wouldn't that throw away any data / text that would remain on the first form?... private MyNamespace1.MyForm _form public MyForm2() { _form = new MyNamespace1.MyForm(); _form.MyValue = "Weyhey."; } ...


              The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

              P L 2 Replies Last reply
              0
              • P Programm3r

                Hmmm ... So The code below will create a new instance of the first form, right? Now wouldn't that throw away any data / text that would remain on the first form?... private MyNamespace1.MyForm _form public MyForm2() { _form = new MyNamespace1.MyForm(); _form.MyValue = "Weyhey."; } ...


                The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                I just showed you how to access a form in a different namespace. How you want to handle it is up to you.

                Deja View - the feeling that you've seen this post before.

                My blog | My articles

                1 Reply Last reply
                0
                • P Programm3r

                  Hmmm ... So The code below will create a new instance of the first form, right? Now wouldn't that throw away any data / text that would remain on the first form?... private MyNamespace1.MyForm _form public MyForm2() { _form = new MyNamespace1.MyForm(); _form.MyValue = "Weyhey."; } ...


                  The only programmers that are better that C programmers are those who code in 1's and 0's :bob: :)Programm3r My Blog: ^_^

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  Hi, every time you execute new something() you create something new. creating a Form is not the same as showing a Form; your new Form would be invisible until you do something to it, such as _form.Show(). creating or showing a Form does not alter any other Form. :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


                  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