Hihi, I'm trying to simply set the text within a textBox that I have drawn onto a 'Form1' Visual C++
I am currently trying to use the line: NarakunoKyokai::Form1::textbox1->Text = "hi";
to try and display 'hi' in textbox1 but I only get the compiler error of
Error c2228: left of .Text must have class/struct/union
I am using the script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
usingnamespace NarakunoKyokai;
std::string ScrReader (int a, int b);
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
std::string lol = ScrReader(1,1);
NarakunoKyokai::Form1::textbox1->Text = "hi";
return 0;
}
Where Form1 is Run, but the textbox isn't created within the script, but simply drawn onto the form and named textbox1 (sorry to keep saying it but I don't know whether this matters or not'
What am I doing wrong in trying to set the text within the textbox?
Therefore I see that when the component is initialized as 'this' it can then be referenced, but how would I do this from another file,namespace and function is my real question then
usingnamespace NarakunoKyokai;
std::string ScrReader (int a, int b);
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Control only returns here after the Application has exited
// therefore the following code will have no effect.
std::string lol = ScrReader(1,1);
NarakunoKyokai::Form1::textbox1->Text = "hi";
return 0;
}
To address your question, you need a handle to the object and then access the object from that. eg.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
usingnamespace NarakunoKyokai;
std::string ScrReader (int a, int b);
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Form1 ^theForm = gcnew Form1();
theForm->textbox1->Text = "hi";
Application::Run(theForm);
return 0;
}
Err, I'm confused then, so What does Application::Run actually do, If it is run when the Application exits, is it ok to put the main script of the proogram before it, it won't all run before the form is generated it?
All I'm trying to do is be able to control the text and be able to change it at certain events while the form is 'running', hence why Run confuses me. =/
Ok see if this makes sense. The Application class 'represents' the application. It has several static methods and properties to manage an application. The Form class is a 'view' of your application.
So, Application::Run is asking the application to run with the Form class as its main view. The run method then effectively sits in a loop processing events until it is told to exit at which point it returns back to main. During the time the application is running the Form should handle any events that you need handling.
Sorry for the newbie questions ^_^'
I get what you mean now,
So Application::Run Makes the Form run as the main view and once it has exited, the remainder of main() is run.
Where then does the actual script 'content' go then, in other words, where do I need to add functions, events and whatnot so that they occur while the application is actually running and visible to the user?