Jump to content
  • Advertisement
Sign in to follow this  
RogerThat123

Windows Form Textboxes

This topic is 3351 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im running visual studio 2003. And I have created a windows form application. Designed it in the designer with some textboxes, some buttons, etc. When I click my button, I want the textbox to be set to a char* thats read from my file. My question is how can I set the textbox to that text.


private: System::Void button1_Click(System::Object *  sender, System::EventArgs *  e)
		 {
			 char *szVersion = GetNewVersion(); // read file , returns 1.32 (example) and yes it must be a char* in my case		
			 textBox2->Text = ? // Is this how you set the text? If so how can i convert the char* to the input type of the text box?
		 }

Ty for your help, sorry for stupid questions.

Share this post


Link to post
Share on other sites
Advertisement
It's been a while since I've used C++/CLI, but you might try:


textbox2->Text = gcnew System::String(szVersion);


(edit) Oh wait, you're using old-school Managed C++, otherwise your .Net type *s would be ^s.


textbox2->Text = __gc new System::String(szVersion);


Or something like that. MC++ is truly ghetto.

Share this post


Link to post
Share on other sites
What's with all the people using C++/CLI these days?

Seriously, unless you're writing a managed wrapper around a native library (e.g. like what the SlimDX guys do) there's no reason to be using C++/CLI for anything. I'd rather do GUI stuff in assembly than doing it in C++/CLI!

Share this post


Link to post
Share on other sites
Quote:
Original post by Codeka
What's with all the people using C++/CLI these days?

Seriously, unless you're writing a managed wrapper around a native library (e.g. like what the SlimDX guys do) there's no reason to be using C++/CLI for anything. I'd rather do GUI stuff in assembly than doing it in C++/CLI!


QFE. I only use C++/CLI for wrapper classes to C and only if I absolutely have to. It's way easier to use WinForms in C#. I usually rewrite C code in C# instead unless it's too much of a pain.

Share this post


Link to post
Share on other sites
Hey sorry guys, I have one more question.

So I got everything working now.

But answer this, Is it possible to have another form inside? Like when you click a button on the main form, a new one will pop up. But so I can use another designer to design it?

Currently I just have a message box that pops up when I click the button, but I want to put an image in it.

Share this post


Link to post
Share on other sites
Ok screw that question, this one is more simple I think.

I inserted a picture box into my form, then in the property window I added a picture from my picture album, but when I compile. I get this error

this->pictureBox1->Image = (__try_cast<System::Drawing::Image * >(resources->GetObject(S"pictureBox1.Image")));

the error is

c:\Users\HOMEOFFICE\Documents\Visual Studio Projects\wa\Form1.h(94): error C2039: 'GetObjectA' : is not a member of 'System::Resources::ResourceManager'

The generated code shouldnt be giving me errors should it? Or is there more to do when adding a picture.

Ps. i want to include it as a resource and dont want to rely on it being on my HD

Share this post


Link to post
Share on other sites
Quote:
Original post by RogerThat123
this->pictureBox1->Image = (__try_cast<System::Drawing::Image * >(resources->GetObject(S"pictureBox1.Image")));

the error is

c:\Users\HOMEOFFICE\Documents\Visual Studio Projects\wa\Form1.h(94): error C2039: 'GetObjectA' : is not a member of 'System::Resources::ResourceManager'
You shouldn't be #include'ing <windows.h> in a C++/CLI project - that's what's causing this error (windows.h has a line that #define GetObject GetObjectA).

Just another reason that you shouldn't be doing this sort of thing in C++/CLI...

Share this post


Link to post
Share on other sites
what kind of project can i create instead then? i only have visual studio 2003, is there another project type I can make that I can use a designer for?

Share this post


Link to post
Share on other sites
If you're using windows forms, then you should create a C# project.

If you really want to use C++, then use a native framework and stay away from managed code (I personally like wxWidgets, others might recommend Qt or something else).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!