Hello, I'm new to the forum and also kinda new to VC++ (but familiar with C++)..
Im making ths application which uses Form. I have form with many buttons and I have a class with methods.
Where and how should I create my object so I could access it through form elements(like clicking on button)? Use seters and geters with buttons etc..
Please help me, I'm searching for this for two days now...
You can create a member variable of your method class in your form/dialog class. You can also create a variable of method class in onClick function of your button. see following example.
Code:
void CTestingDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
MethodClass mClass;
mClass.DoProcess();
OnOK();
}
void CTestingDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
MethodClass *pMClass = new MethodClass();
pMClass->DoProcess();
delete pMClass;
OnOK();
}
Can you please post your code sample so I can answer more accurately.
A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.
I'm totally new to Visual C++ (I made a new widows form project with Visual Studio). I added two buttons on form(dragged on form).
Example would be something like this:
Form1.h:
private: System::Void PlayBtn_Click(System::Object^ sender, System::EventArgs^ e) {
/*
call class method that increments value
*/
}
private: System::Void StopBtn_Click(System::Object^ sender, System::EventArgs^ e) {
/*
call class method that decrement value
*/
}
And in class MyClass.h:
#pragma once
ref class MyClass
{
private:
int val;
public:
MyClass(void);
void addVal();
void delVal();
};
MyClass.cpp:
#include "StdAfx.h"
#include "Field.h"
void addVal()
{
val++;
}
void delVal()
{
val--;
}
Form1.h is Visual Studio generated code with all the information about the form etc. I include the "MyClass.h" in "Form1.h" at the top of it.
#pragma once
#include "MyClass.h"
My question is where should I create class MyClass object in Form1.h so I could access it form PlayBtn_Click() and StopBtn_Click()?
CString to be displayed in a single line in the display grid.
i am trying to add multiple strings in a resultant cstring variable , but in case some of these strings are of length greater than 1000 , the resultant string is stored and displayed (in a grid/text visualizer) in multiple lines. how to display/store the string in a single line.
did you #include MyClass.h in Form1.h file. Also please make sure your are using same namespaces in both files, Other wise use the namespace statement in form1.h file.
Please move this thread to .Net forum or re-post over there.
A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.
Thank you for your answer, I created the object in Form1() constructor:
MyClass^ myc = gcnew MyClass();
1) What is the exclusive-or operator "^" doing on the left side of the = sign?
2) What is this "gcnew"? Is it a macro.
My point begin that this code is off-topic to this forum. As far as this forum goes, the code above is gibberish. Any .NET questions should go to the Managed C++ forum.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.