Windows Form Textboxes

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 on other sites
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.

ty man

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 on other sites
Quote:
 Original post by CodekaWhat'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 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 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 on other sites
Quote:
 Original post by RogerThat123this->pictureBox1->Image = (__try_cast(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 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 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 on other sites
its not even possible to insert my image from a resource, as a bmp file?

Share on other sites
It is possible. As I said, you shouldn't #include <windows.h> in a C++/CLI project. If you take that out, it'll fix that problem (though it might cause other problems...)

Like Promit says in this other recent thread, you should only be using C++/CLI if have a thorough understanding of both C++ and .NET already... do yourself a favour and either switch to a C# project, or use a native GUI library such as wxWidgets.

Share on other sites
I have 2 other files that are included in the project, that are written in C++. Converting to C# would take way too long for me considering I have never touched it.

C++ is just way easier for me

Share on other sites
In which case, I would recommend wxWidgets over winforms. Not having to deal with the complexity of C++/CLI is a huge win for wxWidgets.

Share on other sites
and what is wxWidgets..

Share on other sites
If you are new to programming and wish to make Windows programs, I would suggest that you consider downloading either Visual C# or Visual Basic .NET express editions. Registration is free, and you can use them for any purpose. You will have a much easier time, I think using these either of those than you would C++.

http://www.microsoft.com/express/vcsharp/

http://www.microsoft.com/express/vb/default.aspx

Edit:
I just read above that you don't want to switch to C# because you've already studied some C++. This, I believe, is a very serious mistake. C++ is a very complicated language, and if all you want to do is make some simple programs, you really don't need it. Further more, the same .NET libraries you've been accessing with C++/CLI are able to be used from C# and Visual Basic.

Professional developers use C# and Visual Basic for a wide range of purposes, and there is certainly no shame in doing the same for hobby work.

Share on other sites
Quote:
 I have 2 other files that are included in the project, that are written in C++. Converting to C# would take way too long for me considering I have never touched it.

But you're not writing C++ already. If you're using VS 2003 and you're using Windows Forms, you're using C++ with the Managed C++ extensions enabled. This is fundamentally massively different from C++ -- almost, in fact, as different as C#. And in a much more unpleasant fashion.

You cannot use Windows Forms and C++ together directly. If you want to use C++, use a different windowing toolkit like wxWidgets. If you want to use Windows Forms, use C#.

C++/CLI and C++ w/ Managed C++ extensions are terribly complicated languages that are not suitable for usage by people who did not realize they were using them. If you persist in this direction, you need to understand that you are intentionally taking one of the most difficult paths available to you and that you will need to learn quite a lot about how native and managed interoperability code works.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628370
• Total Posts
2982297

• 10
• 9
• 13
• 24
• 11