textBox .Text Reference

Jan 15, 2009 at 6:37pm
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
using namespace 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?
Last edited on Jan 15, 2009 at 6:52pm
Jan 15, 2009 at 6:51pm
Sorry, just found in the code for the textbox a section starting with
1
2
3
void InitializeComponent(void)
		{
			this->textbox1 = (gcnew System::Windows::Forms::TextBox());

later followed by
this->textbox1->Text = L"test";

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
Jan 16, 2009 at 10:56am
Could anyone give any help/insight? =/
Jan 16, 2009 at 3:19pm
Have you actually tried at least inserting the L? You never know that might change things.
Jan 16, 2009 at 3:52pm
Yep, I've tried and it changes nothing =/
Jan 16, 2009 at 4:39pm
closed account (z05DSL3A)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using namespace 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
using namespace 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;
}

Last edited on Jan 16, 2009 at 6:41pm
Jan 16, 2009 at 7:42pm
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. =/
Jan 16, 2009 at 8:30pm
closed account (z05DSL3A)
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.
Jan 16, 2009 at 8:36pm
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?
Jan 16, 2009 at 8:47pm
closed account (z05DSL3A)
Sorry for the newbie questions ^_^'

We were all there once. :0)

So Application::Run Makes the Form run as the main view and once it has exited, the remainder of main() is run.

Yep

Where then does the actual ...

I'll have a look for a suitable walk through/tutorial on MSDN for you.

Jan 16, 2009 at 9:00pm
thanks :3
Jan 16, 2009 at 9:56pm
closed account (z05DSL3A)
It's not the best but you should see where this go.
http://msdn.microsoft.com/en-us/library/z9w2f38k.aspx
Topic archived. No new replies allowed.