|
-
January 8th, 2012, 03:05 PM
#1
Adding A Function To A Windows Form Button
I understand the basic syntax functionality of C++,
and I can write & compile simple C++ console apps (using Dev-C++).
Now I plan on making simple windows form apps with Visual Studio,
but I'm seeking help with integrating the auto generated managed code with my own functions.
All I'm simply trying to do is add functions to buttons (on windows forms) using Visual C++ in Visual Studio.
My objective is simply to draw a button on the form,
double click on it to jump inside of the button's code,
and add some code that will successfully compile & run.
Like VB, I thought I could simply paste these basic C++ functions into the button1_click area:
Code:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
..I thought I could paste stuff in and done..
}
With C++, I was thinking this would work..
Code:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream outputFile;
outputFile.open("C:\\Users\\Anonymous\\Desktop\\Write2Me.txt");
outputFile << "Writes Line\n";
outputFile << "Writes Another Line\n";
outputFile.close();
return 0;
}
}
Obviously, the above code is not even close. Not even in the same galaxy.
My guess is I have to create a header file?, or a main.cpp file?, and link them somehow?
I've searched several places online, read through a few books,
and even watched 8 hours of VS Essentials Training over the past week.
The self initiative is definitely there, but I'm stuck none the less.
I almost paid Microsoft for online tech support 5 minutes ago (it's okay to laugh).
Any kick start in the right direction is extremely appreciated.
It's not so much this particular code I was trying-
to use for this example (writing a simple .txt file),
my question is more so where the #include headers go in general?,
should my function be somewhere else?, how do I point to it?, link it?, or call it from the button1_click?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|