Windows Develop Bookmark and Share   
 index > Windows Forms General > A Change in Form
 

A Change in Form

I am writting a Windows Form application. However I noticed that all the functions added by Visual Studio is defined in the class. If I can remember correctly this makes them inline, which is an in appropriate form to use when you want to write a large function.

For instance I added the function (with theAdd Member void CreatePage() to the Form1, but it defines it in the class:

void CreatePage(){
}

When I try to define it outside the class using the form I learned for standard C++ classes

void Form1::CreatePage(){
}

The compiler says that it is not a class or namespace.

Any idea how I can define it outside the class?
everlearnin  Monday, August 10, 2009 10:19 AM
Actually in C# there is nothing like header, Here you have to write the function definition with-in the class.
Please mark the post as answer if it is helpfull to you because it boosts the members to answer more and more.
_SuDhiR_  Monday, August 10, 2009 10:51 AM
Your code won't compile because you forgot to #include "Form1.h". You are not writing C++ code anymore, this is a different language called C++/CLI. The standard C++ rulez no longer apply and that includes separating the declarations from their implementation. Don't fight the designer, keep your code inside the .h file.

And pick up a book about the language, it is different enough to get you into a lot of trouble if you don't learn it. In fact, since you need to learn a new language anyway, it would be wise to make that C#. Writing WF apps in C++/CLI is deprecated.

Hans Passant.
nobugz  Monday, August 10, 2009 11:50 AM

Which language you using???


Please mark the post as answer if it is helpfull to you because it boosts the members to answer more and more.
_SuDhiR_  Monday, August 10, 2009 10:27 AM

To be honest the more I look at the forums for CLR .NET and Widows Forms the more I get the idea I am writting in C#. However, I don't know C# I only know C++ and I installed my Visual Studio to be VC++, so my logic tells me I am writing in C++ or Visual C++, which to me are one and the same.

The reason this is so strange to me is when I use Add Member Function Wizard for MFC it put the function declaration in the class and used the form I described above for standard C++ class functions for the declaration. But using the same Wizard in Windows Forms it puts the entire function inside the class.

everlearnin  Monday, August 10, 2009 10:45 AM
Actually in C# there is nothing like header, Here you have to write the function definition with-in the class.
Please mark the post as answer if it is helpfull to you because it boosts the members to answer more and more.
_SuDhiR_  Monday, August 10, 2009 10:51 AM

Ok I suppose I just have to except that this is the way it is done when targeting the CLR.

everlearnin  Monday, August 10, 2009 11:15 AM
Your code won't compile because you forgot to #include "Form1.h". You are not writing C++ code anymore, this is a different language called C++/CLI. The standard C++ rulez no longer apply and that includes separating the declarations from their implementation. Don't fight the designer, keep your code inside the .h file.

And pick up a book about the language, it is different enough to get you into a lot of trouble if you don't learn it. In fact, since you need to learn a new language anyway, it would be wise to make that C#. Writing WF apps in C++/CLI is deprecated.

Hans Passant.
nobugz  Monday, August 10, 2009 11:50 AM

You can use google to search for other answers

Custom Search

More Threads

• Is it possible to capture the DOS console window outputs and display them in the TextBox?
• C# 2005 Sort ListView by column
• when timer enabled in asynchronous function it's not running
• Memory Usage Guidelines
• button without focus possible for only mouse clicks?
• Blinking Text
• Application.exit() not working
• New control extending DomainUpDown (Paint problems)
• Graphic in .Net executable
• app control using only keyboard