About Multiple Windows Forms
-
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
-
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
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
insideLoginForm
and includeform1.h
inLoginForm.cpp
and use the methods fromForm1
.// 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
-
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
insideLoginForm
and includeform1.h
inLoginForm.cpp
and use the methods fromForm1
.// 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
-
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
Pass the
Form1
object viaLoginForm
's constructor.Navaneeth How to use google | Ask smart questions
-
Pass the
Form1
object viaLoginForm
's constructor.Navaneeth How to use google | Ask smart questions
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 :)
-
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 :)
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:
-
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 :)
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 andSave
is a windows form. If yes, how canSave
derive fromXYZ
? It has to derive fromSystem::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
-
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 andSave
is a windows form. If yes, how canSave
derive fromXYZ
? It has to derive fromSystem::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
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
-
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
Can you post code for Form1 and Form2?
Navaneeth How to use google | Ask smart questions
-
Can you post code for Form1 and Form2?
Navaneeth How to use google | Ask smart questions
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