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. Managed C++/CLI
  4. About Multiple Windows Forms

About Multiple Windows Forms

Scheduled Pinned Locked Moved Managed C++/CLI
csharphelpdotnetvisual-studiowinforms
10 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.
  • S Offline
    S Offline
    savitri
    wrote on last edited by
    #1

    Hi All, I am Savitri Here. I new to VC.Net.I am using visual studio 2005.In this i am doing one small program. I started the project like CLR->Windows Application. In that initially Form1 was created.In that i added one more Windows Form called Loginform. I am accessing functions and variables from loginform to Form1 by adding #include "LoginForm.h" in form1.h. But i want access functions of Form1 into LoginForm class,in this i am facing problem and i was not able to include "Form1.h" in LoginForm. Why it is giving problem i am not understanding? Please give me some solution or hints from that i will solve the problem. Please tell me any good books for vc.net and i want some samples of vc.Net.Please help me out. Thanks in advance to all. Regards, Savitri P

    N 1 Reply Last reply
    0
    • S savitri

      Hi All, I am Savitri Here. I new to VC.Net.I am using visual studio 2005.In this i am doing one small program. I started the project like CLR->Windows Application. In that initially Form1 was created.In that i added one more Windows Form called Loginform. I am accessing functions and variables from loginform to Form1 by adding #include "LoginForm.h" in form1.h. But i want access functions of Form1 into LoginForm class,in this i am facing problem and i was not able to include "Form1.h" in LoginForm. Why it is giving problem i am not understanding? Please give me some solution or hints from that i will solve the problem. Please tell me any good books for vc.net and i want some samples of vc.Net.Please help me out. Thanks in advance to all. Regards, Savitri P

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Hi Savitri,

      savitri wrote:

      Why it is giving problem i am not understanding?

      If you do that, you will get circular reference. This is the reason for all those errors. You need to forward declare Form1 inside LoginForm and include form1.h in LoginForm.cpp and use the methods from Form1.

      // LoginForm.h

      ref class Form1;

      public ref class Loginform : public System::Windows::Forms::Form
      {
      // code goes here
      }

      // LoginForm.cpp

      #include "form1.h"

      void Loginform::SomeMethod()
      {
      // you can access form1 methods here without any error
      }

      savitri wrote:

      Please tell me any good books for vc.net and i want some samples of vc.Net

      1 - C++/CLI in action[^]. (This is my favorite) 2 - Visual C++/CLI and the .NET 3.5 Platform[^] :)

      Navaneeth How to use google | Ask smart questions

      S 1 Reply Last reply
      0
      • N N a v a n e e t h

        Hi Savitri,

        savitri wrote:

        Why it is giving problem i am not understanding?

        If you do that, you will get circular reference. This is the reason for all those errors. You need to forward declare Form1 inside LoginForm and include form1.h in LoginForm.cpp and use the methods from Form1.

        // LoginForm.h

        ref class Form1;

        public ref class Loginform : public System::Windows::Forms::Form
        {
        // code goes here
        }

        // LoginForm.cpp

        #include "form1.h"

        void Loginform::SomeMethod()
        {
        // you can access form1 methods here without any error
        }

        savitri wrote:

        Please tell me any good books for vc.net and i want some samples of vc.Net

        1 - C++/CLI in action[^]. (This is my favorite) 2 - Visual C++/CLI and the .NET 3.5 Platform[^] :)

        Navaneeth How to use google | Ask smart questions

        S Offline
        S Offline
        savitri
        wrote on last edited by
        #3

        Hi, Thanks for suggestions.But still i have one doubt. That is shall i create object in constructor or what? or without that how can i use methods of form1 in loginform. Help me please. Thanks in advance. Regards, Savitri P

        N 1 Reply Last reply
        0
        • S savitri

          Hi, Thanks for suggestions.But still i have one doubt. That is shall i create object in constructor or what? or without that how can i use methods of form1 in loginform. Help me please. Thanks in advance. Regards, Savitri P

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          Pass the Form1 object via LoginForm's constructor.

          Navaneeth How to use google | Ask smart questions

          S 1 Reply Last reply
          0
          • N N a v a n e e t h

            Pass the Form1 object via LoginForm's constructor.

            Navaneeth How to use google | Ask smart questions

            S Offline
            S Offline
            savitri
            wrote on last edited by
            #5

            Hi Navaneeth, Thanks for your reply.I have one more doubt hot we can inherit the classes in vc.net programming. Like in C# i have one class called xyz this is normal class not window form. and one more class called save this is windows form. they wrote like this. partial class save: public xyz{ //code here}. Like this how can i write in vc.net or else is der another way to access one class into other class. Please help me out. Thanks in advance. Regards, Savitri P :)

            M N 2 Replies Last reply
            0
            • S savitri

              Hi Navaneeth, Thanks for your reply.I have one more doubt hot we can inherit the classes in vc.net programming. Like in C# i have one class called xyz this is normal class not window form. and one more class called save this is windows form. they wrote like this. partial class save: public xyz{ //code here}. Like this how can i write in vc.net or else is der another way to access one class into other class. Please help me out. Thanks in advance. Regards, Savitri P :)

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              If you derive xyz from save, and save is a form, then xyz is a form too. Is that really what you want?

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              1 Reply Last reply
              0
              • S savitri

                Hi Navaneeth, Thanks for your reply.I have one more doubt hot we can inherit the classes in vc.net programming. Like in C# i have one class called xyz this is normal class not window form. and one more class called save this is windows form. they wrote like this. partial class save: public xyz{ //code here}. Like this how can i write in vc.net or else is der another way to access one class into other class. Please help me out. Thanks in advance. Regards, Savitri P :)

                N Offline
                N Offline
                N a v a n e e t h
                wrote on last edited by
                #7

                savitri wrote:

                they wrote like this. partial class save: public xyz{ //code here}.

                Is this C#? If yes, it is not valid/ Like c++, you don't specify access modifiers when inheriting.

                savitri wrote:

                Like this how can i write in vc.net

                AFAIK, C++/CLI doesn't support partial classes. You said XYZ is a normal class and Save is a windows form. If yes, how can Save derive from XYZ? It has to derive from System::Windows::Forms::Form or it's children.

                savitri wrote:

                is der another way to access one class into other class. Please help me out.

                You have to include classes header file and use it. What is the confusion here? Your question is not clear enough to answer. :)

                Navaneeth How to use google | Ask smart questions

                S 1 Reply Last reply
                0
                • N N a v a n e e t h

                  savitri wrote:

                  they wrote like this. partial class save: public xyz{ //code here}.

                  Is this C#? If yes, it is not valid/ Like c++, you don't specify access modifiers when inheriting.

                  savitri wrote:

                  Like this how can i write in vc.net

                  AFAIK, C++/CLI doesn't support partial classes. You said XYZ is a normal class and Save is a windows form. If yes, how can Save derive from XYZ? It has to derive from System::Windows::Forms::Form or it's children.

                  savitri wrote:

                  is der another way to access one class into other class. Please help me out.

                  You have to include classes header file and use it. What is the confusion here? Your question is not clear enough to answer. :)

                  Navaneeth How to use google | Ask smart questions

                  S Offline
                  S Offline
                  savitri
                  wrote on last edited by
                  #8

                  Hi, Ya i have to include header files to access the functions and variables of that class. thanks for ur guidance. I got the soft copy of that book what u specified in previous reply. In VC.NET i have 2 windows forms Called Form1 and Form2. I am including form2.h in form1 and accessing all the functions of form2. But when i am including form1.h in form2 then i am getting error and not able to access the functions. After that i did like this. ref class form1;and created object of form1 in form2 constructor and when i called form2 frm=gcnew form2(this); and also i am getting error like base class undefined for this code public ref class form2: form1 {//code here } Sorry if i written something wrong.I am new to this .net.Please help me to learn this. Thanks in advance. Regards, Savitri P

                  N 1 Reply Last reply
                  0
                  • S savitri

                    Hi, Ya i have to include header files to access the functions and variables of that class. thanks for ur guidance. I got the soft copy of that book what u specified in previous reply. In VC.NET i have 2 windows forms Called Form1 and Form2. I am including form2.h in form1 and accessing all the functions of form2. But when i am including form1.h in form2 then i am getting error and not able to access the functions. After that i did like this. ref class form1;and created object of form1 in form2 constructor and when i called form2 frm=gcnew form2(this); and also i am getting error like base class undefined for this code public ref class form2: form1 {//code here } Sorry if i written something wrong.I am new to this .net.Please help me to learn this. Thanks in advance. Regards, Savitri P

                    N Offline
                    N Offline
                    N a v a n e e t h
                    wrote on last edited by
                    #9

                    Can you post code for Form1 and Form2?

                    Navaneeth How to use google | Ask smart questions

                    S 1 Reply Last reply
                    0
                    • N N a v a n e e t h

                      Can you post code for Form1 and Form2?

                      Navaneeth How to use google | Ask smart questions

                      S Offline
                      S Offline
                      savitri
                      wrote on last edited by
                      #10

                      Hi Navaneeth, I am writing here code of form1 and form2.

                      form1.h
                      #pragma once

                      #include "AboutApp.h"
                      #include "LoginForm.h"
                      #using <mscorlib.dll>

                      //#pragma comment( lib, "user32.lib" )

                      namespace NewMDIApp {

                      using namespace System;
                      using namespace System::ComponentModel;
                      using namespace System::Collections;
                      using namespace System::Windows::Forms;
                      using namespace System::Data;
                      using namespace System::Drawing;
                      using namespace System::Runtime::InteropServices;
                      
                      /// <summary>
                      /// Summary for Form1
                      ///
                      /// WARNING: If you change the name of this class, you will need to change the
                      ///          'Resource File Name' property for the managed resource compiler tool
                      ///          associated with all .resx files this class depends on.  Otherwise,
                      ///          the designers will not be able to interact properly with localized
                      ///          resources associated with this form.
                      /// </summary>
                      
                      public ref class Form1 : public System::Windows::Forms::Form
                      {
                      	        
                      public:
                      	Form1(void)
                      	{
                      		InitializeComponent();
                      		//
                      		//TODO: Add the constructor code here
                      		//
                      	}
                      
                      protected:
                      

                      #pragma region Windows Form Designer generated code
                      /// <summary>
                      /// Required method for Designer support - do not modify
                      /// the contents of this method with the code editor.
                      /// </summary>
                      void InitializeComponent(void)
                      {
                      // Form1
                      //
                      this->AccessibleRole = System::Windows::Forms::AccessibleRole::MenuBar;
                      this->AllowDrop = true;
                      this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
                      this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
                      this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"$this.BackgroundImage")));
                      this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
                      this->ClientSize = System::Drawing::Size(1017, 700);
                      this->Controls->Add(this->statusBar1);
                      this->Controls->Add(this->statusStrip1);
                      }
                      #pragma endregion
                      public:
                      [DllImport("user32.dll",EntryPoint="GetKeyState")]
                      //static int GetKeyState (int keycode);
                      static int GetKeyState(int keyCode);
                      [DllImport("user32.dll",EntryPoint="keybd_event")]
                      static void keybd_event(Byte bVk, Byte bScan, UInt16 dwFlags, int dwExtraInfo);
                      //[import("user32.dll", ExactSpelling=true)];
                      //public: System::short GetKeyState(int keyCode);
                      public: static LoginForm^ lgFrm=gcnew LoginForm;

                      private: System::Void

                      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