Neo003 Posted February 20, 2009 Share Posted February 20, 2009 What I have here is TextField | TextBox_1 | TextBox_2 I want to Multiply TextField x TextBox_1 and show the result in TextBox_2, Can anyone tell me how to do this in C++. Also I wanted to add the last coloum into let say another textbox. Link to comment Share on other sites More sharing options...
0 Xilo Posted February 20, 2009 Share Posted February 20, 2009 TextBox_2 value = TextField value * TextBox_1 value Look up the API for whatever gui you are using... That should help. Link to comment Share on other sites More sharing options...
0 tunafish Posted February 20, 2009 Share Posted February 20, 2009 So just do a kinda of straight forward textbox1 x textbox2 but ya could save it as a variable. Suggest you read your college notes before basically asking someone to do your work for you without even attempting it and posting what you got Link to comment Share on other sites More sharing options...
0 hdood Posted February 20, 2009 Share Posted February 20, 2009 The question doesn't make sense as "C++" has no GUI toolkit. Your question seems to actually be about using Windows Forms from (managed) C++/CLI, in which case if you're using a TextBox or MaskedTextBox you have to take the text value (the ->Text member) in it and convert it to an integer, do whatever you want with it, and then convert it back to text and display it in another TextBox. Can I ask why you're using C++/CLI though? It really only makes sense if you have to interact with existing C++ code. Link to comment Share on other sites More sharing options...
0 Neo003 Posted February 20, 2009 Author Share Posted February 20, 2009 I'm using MS Visual Studio 2008 & It's a windows form app under C++. Forgive me for not making it clear, I'm new to this and I usally don't know much lingo you guys use. This app I'm doing after having some problem with Hello World! :( I know it's sad. But bear with me I am doing this without any books or anything just using internet as a guide and still having problem. I'm done with the design part of it, It's just the calculation I'm having problem with. What I want to know what code to write after I double click the top right text box under "Total". Link to comment Share on other sites More sharing options...
0 hdood Posted February 20, 2009 Share Posted February 20, 2009 I'm using MS Visual Studio 2008 & It's a windows form app under C++. Forgive me for not making it clear, I'm new to this and I usally don't know much lingo you guys use. The point I was trying to make though, is that C++ and C++/CLI is not the same thing. The latter is a new managed language that builds on the C++ foundation, adding functionality that makes it usable as a managed language. It's very useful if you're looking to mix new managed code with older native code that has already been written. If C++ is what you're actually looking to learn, you should be sticking to plain old native C++. Most people learn the basics of that by starting out with command line programming and then eventually moving onto the Windows GUI APIs like Win32 (plain C, but usable from C++) or MFC (basically a C++ wrapper for Win32). Most Windows programs are written in such native code, and not C++/CLI and Windows Forms. Starting out with advanced GUI programming in C++/CLI (yes, even a hello world is advanced if you have no prior experience) in an attempt to learn C++ is essentially like jumping straight into the deepest part of the Atlantic Ocean without knowing how to swim. You're basically starting out by learning things that don't apply to C++ at all. Now if you're actually wanting to learn managed programming and .NET, you're really better off going with C#. It is a cleaner and simpler language, and also has vastly superior IntelliSense (autocompletion) which is nice for learning. Writing pure managed code in C++/CLI is for masochists. What I want to know what code to write after I double click the top right text box under "Total". No code goes in your screenshot, because what you have actually done is added a MaskInputRejected event handler to your read-only MaskedTextBox. Said event fires when the text passed to the MaskedTextBox does not match the set mask. Clearly that is not what you want to do. The box you actually want your events on is in the "Enter No. of Notes" column. Maybe a TextChanged event which then reads the Text value of the control and converts it to an int. Once you have that int, multiply it by whatever you want and then convert it back to text, and use that text to set the box in the Total column. The result would be a Total column that dynamically updates as you type into the number column. The problem here is that you are getting way, way, way ahead of yourself. This is not "hello world code." You are trying to do something fairly advanced without having learned the boring basics of the language -- an exercise that is doomed to fail. I'm not saying this to be mean, but you have to learn to crawl before you can walk. Link to comment Share on other sites More sharing options...
0 Andre S. Veteran Posted February 20, 2009 Veteran Share Posted February 20, 2009 (edited) Just to clarify, the language here is really C++/CLI, not C++. There's no such thing as a "ref class" in C++ so this is really another language; one that strives to feel as familiar as possible to C++ programmers, but still another language. Also, it's very complex and definitely not a good choice for a beginner programmer. In any case, unless you're doing VB6 you'd better start with console applications, because working with a GUI quickly involves learning advanced concepts. I could be of more help if you posted your solution. (EDIT : Again, I got beat to the point. Thanks hdood) Edited February 20, 2009 by Dr_Asik Link to comment Share on other sites More sharing options...
0 Neo003 Posted February 20, 2009 Author Share Posted February 20, 2009 I understand, thank you. It's the crawling part which you spoke of is difficult to find on the internet. I tried so many websites the all put tutorial which doesn't make any sense to a newbie like me without someone?s help. Like you guys said C++/CLI is different from C++, I went to lot of websites but none of them mentioned this. I feel a little bummed out now since I'm halfway from making the program and to start over again. Link to comment Share on other sites More sharing options...
0 Andre S. Veteran Posted February 20, 2009 Veteran Share Posted February 20, 2009 One of the problems with C++/CLI is that you don't find many beginner tutorials for it. In fact you don't find many tutorials at all. It's a language for crazy advanced C++ programmers so they don't need tutorials, they learn by osmosis and magic. And MSDN. :p Link to comment Share on other sites More sharing options...
0 hdood Posted February 20, 2009 Share Posted February 20, 2009 You're likely not going to find that much about C++/CLI on the internet because it is a very esoteric programming language intended as a sort of sadomasochistic bridge between C++ and the managed world. It shouldn't really take long to recreate the GUI in C# using the Windows Forms editor in Visual Studio, though, if you wanted to take that route. You would still have to learn the basics of the language and object oriented programming though. On the plus side, there are lots and lots of C# tutorials. If going the native route, GUI programming is really beyond what one would be able to do without a significant investment in learning. (Damn, Dr Asik gets his revenge) Link to comment Share on other sites More sharing options...
0 Neo003 Posted February 20, 2009 Author Share Posted February 20, 2009 How do I know that I'm using C++/CLI?, I started a New Project - > Visual C++ -> Windows Form Application ( I didn't click CLR Console Application). Link to comment Share on other sites More sharing options...
0 hdood Posted February 20, 2009 Share Posted February 20, 2009 You know because Windows Forms is a managed API, and managed code is only available from C++/CLI. CLR means Common Language Runtime, which is the runtime for managed code. Everything under that section is managed (ie C++/CLI). Win32, MFC, and ATL are native. Under Visual C#, everything is managed. Link to comment Share on other sites More sharing options...
0 Andre S. Veteran Posted February 21, 2009 Veteran Share Posted February 21, 2009 How do I know that I'm using C++/CLI?, I started a New Project - > Visual C++ -> Windows Form Application ( I didn't click CLR Console Application).In Visual Studio 2008 Professional (my version), Windows Form Applications are under C++ -> CLR. So they are implicitely C++/CLI. It's indeed unfortunate that the distinction isn't made more clearly. Your first applications in C++ should really be of the General -> Empty Project type. That's plain old native C++. Link to comment Share on other sites More sharing options...
Question
Neo003
What I have here is TextField | TextBox_1 | TextBox_2
I want to Multiply TextField x TextBox_1 and show the result in TextBox_2, Can anyone tell me how to do this in C++.
Also I wanted to add the last coloum into let say another textbox.
Link to comment
Share on other sites
12 answers to this question
Recommended Posts