Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Working with Windows Forms in C++  (Read 2491 times)

0 Members and 1 Guest are viewing this topic.
Working with Windows Forms in C++
« on: October 25, 2009, 04:11:50 am »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1767
So I'm making an application to organize resources for a project I'm working on using the .NET form designer in Visual Studio 2008 or whatever it's called. However, I'm not exactly sure how it works. So I'm making this topic to be like a general question topic for when I may need it.

As for right now, I'm trying to simply just have it bring up another form when I click the button, but I don't know how to reference the other form. This is what I'm trying right now:

Code: [Select]
private: System::Void btnForm2_Click(System::Object^  sender, System::EventArgs^  e)
{
     Form2.Show();
}

(I've also tried Form2->Show(); and Show(Form2); but I have no idea which one to use)
And it says Form2 is an undeclared identifier. So how exactly do I declare it, because shouldn't it already be declared since the Form2.h was created? So yeah help be needed here.

Also some useful information more about how the using the Windows Forms would be great too. =P
Logged
  • https://colbydude.com
Re: Working with Windows Forms in C++
« Reply #1 on: October 25, 2009, 04:48:55 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Posts: 728
Form2 is actually a class. So, when you press the button, you want to create a new instance of Form2.

Like so:

Code: [Select]
private: System::Void btnForm2_Click(System::Object^  sender, System::EventArgs^  e)
{
    Form2 form = new Form2();
    form.Show();
}
Logged
  • Pyxosoft
Re: Working with Windows Forms in C++
« Reply #2 on: October 25, 2009, 04:52:59 am »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Instantiate the Form2 class in your Form1.load procedure.  Then call Show() on buttonclick on that object.
Logged



i love big weenies and i cannot lie
Re: Working with Windows Forms in C++
« Reply #3 on: October 25, 2009, 05:29:14 am »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1767
Ah ok, that makes a whole lot more sense, but now it's giving me this:

Code: [Select]
Error 2
error C3673: 'KRMC::Form2' : class does not have a copy-constructor c:\users\colby\documents\visual studio 2008\projects\krm c++\krm c++\Form1.h 107

What's that supposed to mean? O_o

And it's pointing to the Form2 form = new Form2(); line.
Logged
  • https://colbydude.com
Re: Working with Windows Forms in C++
« Reply #4 on: October 25, 2009, 05:53:19 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Posts: 728
Been forever since I've used vc++.

Code: [Select]
private: System::Void btnForm2_Click(System::Object^  sender, System::EventArgs^  e)
{
    Form2^ form = gcnew Form2;
    form->Show();
}

Try that.
« Last Edit: October 25, 2009, 06:05:15 am by Xfixium »
Logged
  • Pyxosoft
Re: Working with Windows Forms in C++
« Reply #5 on: October 25, 2009, 06:27:10 am »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1767
Great, it worked beautifully.

What exactly does the ^ do though? I've never even used it (probably seen it somewhere) before.
Logged
  • https://colbydude.com
Re: Working with Windows Forms in C++
« Reply #6 on: October 25, 2009, 06:41:55 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Posts: 728
It's a handle to a managed type. Don't remember the exact reason. Just know it's used in conjunction with the "gcnew" keyword.
Logged
  • Pyxosoft
Re: Working with Windows Forms in C++
« Reply #7 on: October 25, 2009, 07:37:22 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
Ah ok, that makes a whole lot more sense, but now it's giving me this:

Code: [Select]
Error 2
error C3673: 'KRMC::Form2' : class does not have a copy-constructor c:\users\colby\documents\visual studio 2008\projects\krm c++\krm c++\Form1.h 107

What's that supposed to mean? O_o

And it's pointing to the Form2 form = new Form2(); line.

Colbydude. Not to criticize you, but some friendly advise. The best way to learn C++ is to figure certain errors out yourself, then asking someone else. Because you learn more about what you did wrong that way.

A small hint: Google is your friend! I typed in the following keywords "c++ error C3673" and the first hit led me to the following site: http://msdn.microsoft.com/en-us/library/ms173670%28VS.80%29.aspx

If by then you still can't figure out what is the problem you can ask other people about it. In learning to program, failing miserably many times before succeeding is pretty normal. The "error Cxxxx" variation is the simplest to figure out. The big problems begin when you get "error LNKxxxx", because these are seriously vague.

Some free advise on common LNK errors:
LNK2001 and LNK2005: mean that your design for the application is completely wrong. You have to start your design from scratch, reorganize your code and think about the design patterns you use.
Logged
Re: Working with Windows Forms in C++
« Reply #8 on: October 25, 2009, 02:39:30 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Quote
Some free advise on common LNK errors:
LNK2001 and LNK2005: mean that your design for the application is completely wrong. You have to start your design from scratch, reorganize your code and think about the design patterns you use.

Umm..no?  2001 means that you forgot a library in your project and 2005 means you just suck at keeping your variables, classes etc organized.  Both can be easily fixed.
Logged



i love big weenies and i cannot lie
Re: Working with Windows Forms in C++
« Reply #9 on: October 25, 2009, 02:42:40 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Quote
Some free advise on common LNK errors:
LNK2001 and LNK2005: mean that your design for the application is completely wrong. You have to start your design from scratch, reorganize your code and think about the design patterns you use.

Umm..no?  2001 means that you forgot a library in your project and 2005 means you just suck at keeping your variables, classes etc organized.  Both can be easily fixed.
This.

Seriously Niek, judging someones coding worth by the fact that they get a couple of linker errors? Thats total garbage.
Logged
Re: Working with Windows Forms in C++
« Reply #10 on: October 25, 2009, 04:18:19 pm »
  • Minalien
  • *
  • Reputation: +10/-1
  • Offline Offline
  • Gender: Female
  • Posts: 2119
Quote
Some free advise on common LNK errors:
LNK2001 and LNK2005: mean that your design for the application is completely wrong. You have to start your design from scratch, reorganize your code and think about the design patterns you use.

Umm..no?  2001 means that you forgot a library in your project and 2005 means you just suck at keeping your variables, classes etc organized.  Both can be easily fixed.
This.

Seriously Niek, judging someones coding worth by the fact that they get a couple of linker errors? Thats total garbage.
QFT'd.
Logged
Quote
There's such a double standard about religion in the modern world. Catholics can gather, wear white robes, and say "In nomine Patris, et Filii, et Spiritus Sancti" and be considered normal.

But if my friends and I gather, wear black robes, and say  "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn", we're considered cultists.
  • Development Blog
Re: Working with Windows Forms in C++
« Reply #11 on: October 25, 2009, 04:20:53 pm »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1767
@Niek: Yeah... I suppose I could've done that first, but it was 2:41 AM and my brain doesn't function correctly. Plus I just haven't really dealt with Forms so I have no idea what errors would go with what.

@Infini and MG-Zero: Thanks?
Logged
  • https://colbydude.com
Re: Working with Windows Forms in C++
« Reply #12 on: October 25, 2009, 04:23:45 pm »
  • Minalien
  • *
  • Reputation: +10/-1
  • Offline Offline
  • Gender: Female
  • Posts: 2119
It's a handle to a managed type. Don't remember the exact reason. Just know it's used in conjunction with the "gcnew" keyword.
If you want, compare the ^ to a *. The ^ was added as the CLI extension's method of handling references, which most managed languages (particularly C#) does automatically. This is because C++/CLI has to differentiate between unmanaged and managed types and variables. Because the asterisk was already taken for C++ pointers, ^ was used for reference handles, and specifically relates to Managed components (those related to the .NET Framework).

I also recently started picking into C++/CLI. I'm in love :D
Logged
Quote
There's such a double standard about religion in the modern world. Catholics can gather, wear white robes, and say "In nomine Patris, et Filii, et Spiritus Sancti" and be considered normal.

But if my friends and I gather, wear black robes, and say  "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn", we're considered cultists.
  • Development Blog
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.041 seconds with 60 queries.

anything