Newbie Hello World question: Show in textbox on button click

J

J.S.

I can show Hello World in a MessageBox with this code:

private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e) {MessageBox::Show("Hello, World!");
}

but I cannot show it in a textbox with this code:

private: System::Void button2_Click(System::Object^ sender,
System::EventArgs^ e) {textBox1::Show("Hello World");
}

I am using VC++ 2005 Express Edition beta.

I'd appreciate any pointers. It was so much easier to do in C#. :)

Thanks,
J.S.

--
 
O

Octavio Hernandez

Hi,

MessageBox is a CLASS name and Show is a STATIC (CLASS) member of that
class.
textBox1 is a (reference to) an INSTANCE, so you should use '->' to access
it members.
Furthermore, textBox1 is of class TextBox, which does not offer a Show()
method.
You should use:

textBox1->Text = "Hello";

Regards - Octavio
 
J

J.S.

Hi Octavio,

Thanks for the explanation and the code. It worked perfectly.

Thanks,
J.S.
 
J

John Salerno

J.S. said:
Sorry, wrong forum. :) I meant to post it on the C++ forum.

LOL. As someone learning C#, you scared me for a second! As soon as I
saw the :: symbol, I said to myself, "That has to be C++...at least,
please don't be C#!" :)
 
G

Guest

Hi JS,

I'm glad that you got the right answer to your problem, and I'm sure that
no-one minds that you posted in the wrong forum, but something is puzzling
me. Why are you teaching yourself C++ anyway? If you are just being very
pragmatic, and having done some market research, you've decided that there
are jobs in C++, then OK - that's always a good reason :), but if it's
because you want to learn programming in general, or write your own
applications, then you should be going for C#. It's just as powerful as C++,
and much easier to use, especially for a beginner. It will also get you into
the .Net framework faster, as you won't be so botherd with pesky language
problems. There are very few reasons for a beginner to be getting into C++
these days, apart from getting a job maintaining legacy code.

Spoken as someone who has done his share of c++, and is retraining in C#

- Javaman
 
J

J.S.

John Salerno said:
LOL. As someone learning C#, you scared me for a second! As soon as I saw
the :: symbol, I said to myself, "That has to be C++...at least, please
don't be C#!" :)

LOL That was funny! :)
 
J

J.S.

Javaman,

I agree with you on C# and I am planning to learn primarily C#. However,
since I had downloaded all the Express Editions of VS 2005 I thought I'd try
creating a simple Windows Forms application in all three languages - VB, C#
and C++. That was the reason for the C++ question. :)

I found C# to be only slightly tougher than VB while C++ did take more time
than the other two.

Most of the ASP.Net folks I know use C# and I'll probably use it for Windows
Forms apps. also. However, is it not true that most large companies that
develop Windows applications are still developing primarily in C++? Just
curious.

Thanks,
J.S.
 
G

Guest

J.S. said:
Javaman,

I agree with you on C# and I am planning to learn primarily C#. However,
since I had downloaded all the Express Editions of VS 2005 I thought I'd try
creating a simple Windows Forms application in all three languages - VB, C#
and C++. That was the reason for the C++ question. :)

I found C# to be only slightly tougher than VB while C++ did take more time
than the other two.

Most of the ASP.Net folks I know use C# and I'll probably use it for Windows
Forms apps. also. However, is it not true that most large companies that
develop Windows applications are still developing primarily in C++? Just
curious.

Thanks,
J.S.
 
G

Guest

Thanks for the reply, JS
I agree with you on C# and I am planning to learn primarily C#. However,
since I had downloaded all the Express Editions of VS 2005 I thought I'd try
creating a simple Windows Forms application in all three languages - VB, C#
and C++. That was the reason for the C++ question. :)

Good work! Nothing wrong with knowing a bit about several languages.
I found C# to be only slightly tougher than VB while C++ did take more time
than the other two.

Interesting :)
Most of the ASP.Net folks I know use C# and I'll probably use it for Windows
Forms apps. also. However, is it not true that most large companies that
develop Windows applications are still developing primarily in C++? Just
curious.

It may well be true that products are still developed in C++ (or even C).
However, AFAIK from watching the industry around me, new applications are
being developed in C#, VB.Net, ASP.NET (and also Java/PHP/Oracle, in the Unix
world), and the all the momentum is in that direction. Let's say you could
become a C++ programmer in a month - then I'd recommend you do that, just to
add some flexibility, but you can't - it takes years, and then you will be
competing in a field where there are already numerous people with more years
of C++ than you. Your best bet, as a newbie, or an oldbie, is to go down the
C#/.Net path... (and if you have time to learn two languages, do VB.Net and
C#)

Good luck with it all!

Javaman
 
J

Jon Skeet [C# MVP]

John Salerno said:
LOL. As someone learning C#, you scared me for a second! As soon as I
saw the :: symbol, I said to myself, "That has to be C++...at least,
please don't be C#!" :)

Get ready for C# 2.0 then... this is valid:

using System;

namespace Foo
{
public class Test
{
static void Main()
{
Console.WriteLine (new Test());
Console.WriteLine (new global::Test());
}

public override string ToString()
{
return "Foo namespace";
}
}
}

public class Test
{
public override string ToString()
{
return "Global namespace";
}
}
 
J

J.S.

Javaman59 said:
It may well be true that products are still developed in C++ (or even C).
However, AFAIK from watching the industry around me, new applications are
being developed in C#, VB.Net, ASP.NET (and also Java/PHP/Oracle, in the
Unix
world), and the all the momentum is in that direction. Let's say you could
become a C++ programmer in a month - then I'd recommend you do that, just
to
add some flexibility, but you can't - it takes years, and then you will be
competing in a field where there are already numerous people with more
years
of C++ than you. Your best bet, as a newbie, or an oldbie, is to go down
the
C#/.Net path... (and if you have time to learn two languages, do VB.Net
and
C#)

Good luck with it all!

Thanks, Javaman! Since I plan to do more work with Web Forms than with
Windows Forms I think C# and VB.Net would be ideal for me.

J.S.
 
J

John Salerno

Gawd, what is *that*!? :)

I thought I was (vaguely) familiar with all the new additions!
 
J

Jon Skeet [C# MVP]

John Salerno said:
Gawd, what is *that*!? :)

I thought I was (vaguely) familiar with all the new additions!

It's just a way of specifying the namespace when there'd be any
ambiguity. I can't see it being used very often, to be honest...
 
C

Charlie Tame

Hehe, an excellent wrong group post JS because it's covered a question I was
wondering about but probably wouldn't have bothered anyone by asking.

Thank you Javaman for the opinion, it does pretty much reflect my first
impressions having recently got the VS2005 beta. I also purchased the books
and it seems that for MS at least C++ is on the way out, VB is likely to
fade out in time and C# is growing. I am very impressed by the amount of
work VS2005 saves by doing so many things for you in the background. Not
being used to object oriented programming and classes of any sort (Been out
of programming for years) I will venture the opinion that C# is by far the
easiest of the 3 if you also have to grasp the peripheral concepts. IMO (and
this is obviously very personal) VB actually works against this learning
since it's still a lot like the old "Basics" in syntax and old habits die
hard. These news communities sure do help though.

Charlie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top