I have been looking around for two days on how to simply update the text field of a RichTextBox on a form called Form1 from a separate class called Chat_Commands.
I am trying to play with some coding for c++ GUI as i have not learned it and only done basic C++ in school. What i wanted to do was have a separate file with a new class to control a TCP chat server.
namespace ChatCommands {
usingnamespace System::Windows::Forms;
usingnamespace GUI_Chat;
public ref class Chat_Commands
{
enumclass caseDirection { upper, lower };
// Private section
private:
// Public section
public:
//void GUI_Chat_Commands(void);
Chat_Commands(void);
void command_Selection(System::String^ command);
char change_Case(char letter, caseDirection caseType);
void display_Usage(void);
};
//enum caseDirection { upper, lower };
// Constructor
Chat_Commands::Chat_Commands() { }
// Determine what command is being entered.
void Chat_Commands::command_Selection(System::String^ command)
{
System::String ^lowerCommand;
for each (char letter in command)
{
lowerCommand += (wchar_t) change_Case(letter, caseDirection::lower);
}
if ("exit" == lowerCommand)
{
Application::Exit();
}
if ("?" == lowerCommand)
{
display_Usage();
}
}
char Chat_Commands::change_Case(char letter, caseDirection caseType )
{
switch (caseType)
{
case caseDirection::upper:
// This changes to uppercase
if (letter > 96 && letter < 122) // Check if the letter is lowercase
{
letter -= 32; // Change the letter to uppercase.
}
break;
case caseDirection::lower:
// This changes to Lowercase
if (letter > 'A' && letter < 'Z') // Check if the letter is uppercase
{
letter += 32;
}
break;
default:
break;
}
return letter;
}
/*
ref class ManagedGlobals {
public:
static Form1^ mainForm = gcnew Form1;
};
*/
void Chat_Commands::display_Usage(void)
{
Form1^ frm1 = gcnew Form1;
// **** TODO: Impliment some way of being able to intereact with the rtbConsole control on Form1.
//ManagedGlobals::mainForm->update_rtbConsole("Usage");
//<Form1^>* pointer = (gcroot<ManagedClass^>*)(input);
frm1->delPassData("Usage");
}
};
Can anyone tell me how to get the helper class to update data on the form in Visual studio 2012?
As you can see in the function at the bottom of Commands.h I just simply want to send the text back to a function on Form1 that will update the control.
This is not C++, this is C++/CLI, which is basically a Microsoft-tainted C++. Have you tried looking as Microsoft's resources? MSDN is a good (but confusing) place to look.
class Foo {
int x;
public:
void set( int y ) { x = y; }
};
class Bar {
public:
void gaz( Foo & f, int y ) { f.set( y ); }
};
int main()
{
Foo z;
Bar w;
w.gaz( z, 42 );
return 0;
}
Foo is a type of objects that have feature x. The x could be "content of a text field". The interface of Foo allows manipulation of the feature. Surely, the text field of RichTextBox does not change automagickally; someone uses its interface.
Bar is a type of objects too. It happens to encapsulate a procedure gaz, which accesses (uses) the interface of the type Foo objects.
If you have a "form", then it must somehow reference its "boxes". The program must have a list of its forms. Nothing should prevent a procedure to put stuff into a box that it finds from a form, if it can find the form from the application. The boxes being GUI elements is irrelevant (unless the interface of the GUI elements is bizarre).