3 Replies - 468 Views - Last Post: 25 April 2011 - 03:35 AM Rate Topic: -----

#1 tympaniplayer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-April 11

problem using windows forms for program

Posted 24 April 2011 - 05:32 PM

I want to take my simple encryption program and create a GUI using windows form. I have the basic layout for the form, however I am not sure how to link the "submit" buttons to the text boxes, and then how to get output into a seperate text box.
Basically I am not sure how to use code in windows forms, except for simple things like message boxes, and changing colors.

I have looked up some things, however the tutorials are things like making message boxes show up.

Perhaps someone could point me in the right direction of a tutorial? or a few examples to get me started? Thank you!


Here is my Encrypt Program.
#include<iostream>
#include<string>
#include<vector>
using namespace std;


string redEncrypt ( string red )
{
	int size = red.size();
	for ( int position = 0; position < size; position ++ )
	{
		if ( red[position] == 'A' || red[position] == 'a' )
		{
			red[position] = 'R';
		}


		else if ( red[position] == 'B' || red[position] == 'b' )
		{
			red[position] = 'S';
		}


		else if ( red[position] == 'C' || red[position] == 'c' )
		{
			red[position] = 'T';
		}


		else if ( red[position] == 'D' || red[position] == 'd' )
		{
			red[position] = 'U';
		}


		else if ( red[position] == 'E' || red[position] == 'e' )
		{
			red[position] = 'V';
		}


		else if ( red[position] == 'F' || red[position] == 'f' )
		{
			red[position] = 'W';
		}

		else if ( red[position] == 'G' || red[position] == 'g' )
		{
			red[position] = 'X';
		}


		else if ( red[position] == 'H' || red[position] == 'h' )
		{
			red[position] = 'Y';
		}


		else if ( red[position] == 'I' || red[position] == 'i' )
		{
			red[position] = 'Z';
		}


		else if ( red[position] == 'J' || red[position] == 'j' )
		{
			red[position] = 'A';
		}


		else if ( red[position] == 'K' || red[position] == 'k' )
		{
			red[position] = 'B';
		}


		else if ( red[position] == 'L' || red[position] == 'l' )
		{
			red[position] = 'C';
		}


		else if ( red[position] == 'M' || red[position] == 'm' )
		{
			red[position] = 'D';
		}


		else if ( red[position] == 'N' || red[position] == 'n' )
		{
			red[position] = 'E';
		}

		else if ( red[position] == 'O' || red[position] == 'o' )
		{
			red[position] = 'F';
		}


		else if ( red[position] == 'P' || red[position] == 'p' )
		{
			red[position] = 'G';
		}

		else if ( red[position] == 'Q' || red[position] == 'q' )
		{
			red[position] = 'H';
		}


		else if ( red[position] == 'R' || red[position] == 'r' )
		{
			red[position] = 'I';
		}


		else if ( red[position] == 'S' || red[position] == 's' )
		{
			red[position] = 'J';
		}


		else if ( red[position] == 'T' || red[position] == 't' )
		{
			red[position] = 'K';
		}


		else if ( red[position] == 'U' || red[position] == 'u' )
		{
			red[position] = 'L';
		}


		else if ( red[position] == 'V' || red[position] == 'v' )
		{
			red[position] = 'M';
		}


		else if ( red[position] == 'W' || red[position] == 'w' )
		{
			red[position] = 'N';
		}


		else if ( red[position] == 'X' || red[position] == 'x' )
		{
			red[position] = 'O';
		}


		else if ( red[position] == 'Y' || red[position] == 'y' )
		{
			red[position] = 'P';
		}


		else if ( red[position] == 'Z' || red[position] == 'z' )
		{
			red[position] = 'Q';
		}

	}

	return red;
}

string blueEncrypt ( string blue )
{
		int size = blue.size();
	for ( int position = 0; position < size; position ++ )
	{
		if ( blue[position] == 'A' || blue[position] == 'a' )
		{
			blue[position] = 'C';
		}


		else if ( blue[position] == 'B' || blue[position] == 'b' )
		{
			blue[position] = 'F';
		}


		else if ( blue[position] == 'C' || blue[position] == 'c' )
		{
			blue[position] = 'I';
		}


		else if ( blue[position] == 'D' || blue[position] == 'd' )
		{
			blue[position] = 'L';
		}


		else if ( blue[position] == 'E' || blue[position] == 'e' )
		{
			blue[position] = 'O';
		}


		else if ( blue[position] == 'F' || blue[position] == 'f' )
		{
			blue[position] = 'R';
		}

		else if ( blue[position] == 'G' || blue[position] == 'g' )
		{
			blue[position] = 'W';
		}


		else if ( blue[position] == 'H' || blue[position] == 'h' )
		{
			blue[position] = 'Z';
		}


		else if ( blue[position] == 'I' || blue[position] == 'i' )
		{
			blue[position] = 'Y';
		}


		else if ( blue[position] == 'J' || blue[position] == 'j' )
		{
			blue[position] = 'A';
		}


		else if ( blue[position] == 'K' || blue[position] == 'k' )
		{
			blue[position] = 'D';
		}


		else if ( blue[position] == 'L' || blue[position] == 'l' )
		{
			blue[position] = 'G';
		}


		else if ( blue[position] == 'M' || blue[position] == 'm' )
		{
			blue[position] = 'J';
		}


		else if ( blue[position] == 'N' || blue[position] == 'n' )
		{
			blue[position] = 'X';
		}

		else if ( blue[position] == 'O' || blue[position] == 'o' )
		{
			blue[position] = 'H';
		}


		else if ( blue[position] == 'P' || blue[position] == 'p' )
		{
			blue[position] = 'S';
		}

		else if ( blue[position] == 'Q' || blue[position] == 'q' )
		{
			blue[position] = 'V';
		}


		else if ( blue[position] == 'R' || blue[position] == 'r' )
		{
			blue[position] = 'M';
		}


		else if ( blue[position] == 'S' || blue[position] == 's' )
		{
			blue[position] = 'B';
		}


		else if ( blue[position] == 'T' || blue[position] == 't' )
		{
			blue[position] = 'E';
		}


		else if ( blue[position] == 'U' || blue[position] == 'u' )
		{
			blue[position] = 'P';
		}


		else if ( blue[position] == 'V' || blue[position] == 'v' )
		{
			blue[position] = 'K';
		}


		else if ( blue[position] == 'W' || blue[position] == 'w' )
		{
			blue[position] = 'N';
		}


		else if ( blue[position] == 'X' || blue[position] == 'x' )
		{
			blue[position] = 'Q';
		}


		else if ( blue[position] == 'Y' || blue[position] == 'y' )
		{
			blue[position] = 'U';
		}


		else if ( blue[position] == 'Z' || blue[position] == 'z' )
		{
			blue[position] = 'T';
		}

	}
	return blue;
}

string redDecrypt ( string red )
{
	int size = red.size();
	for ( int position = 0; position < size; position ++ )
	{
		if ( red[position] == 'R' || red[position] == 'r' )
		{
			red[position] = 'A';
		}


		else if ( red[position] == 'S' || red[position] == 's' )
		{
			red[position] = 'B';
		}


		else if ( red[position] == 'T' || red[position] == 't' )
		{
			red[position] = 'C';
		}


		else if ( red[position] == 'U' || red[position] == 'u' )
		{
			red[position] = 'D';
		}


		else if ( red[position] == 'V' || red[position] == 'v' )
		{
			red[position] = 'E';
		}


		else if ( red[position] == 'W' || red[position] == 'w' )
		{
			red[position] = 'F';
		}

		else if ( red[position] == 'X' || red[position] == 'x' )
		{
			red[position] = 'G';
		}


		else if ( red[position] == 'Y' || red[position] == 'y' )
		{
			red[position] = 'H';
		}


		else if ( red[position] == 'Z' || red[position] == 'z' )
		{
			red[position] = 'I';
		}


		else if ( red[position] == 'A' || red[position] == 'a' )
		{
			red[position] = 'J';
		}


		else if ( red[position] == 'B' || red[position] == 'b' )
		{
			red[position] = 'K';
		}


		else if ( red[position] == 'C' || red[position] == 'c' )
		{
			red[position] = 'L';
		}


		else if ( red[position] == 'D' || red[position] == 'd' )
		{
			red[position] = 'M';
		}


		else if ( red[position] == 'E' || red[position] == 'e' )
		{
			red[position] = 'N';
		}

		else if ( red[position] == 'F' || red[position] == 'f' )
		{
			red[position] = 'O';
		}


		else if ( red[position] == 'G' || red[position] == 'g' )
		{
			red[position] = 'P';
		}

		else if ( red[position] == 'H' || red[position] == 'h' )
		{
			red[position] = 'Q';
		}


		else if ( red[position] == 'I' || red[position] == 'i' )
		{
			red[position] = 'R';
		}


		else if ( red[position] == 'J' || red[position] == 'j' )
		{
			red[position] = 'S';
		}


		else if ( red[position] == 'K' || red[position] == 'k' )
		{
			red[position] = 'T';
		}


		else if ( red[position] == 'L' || red[position] == 'l' )
		{
			red[position] = 'U';
		}


		else if ( red[position] == 'M' || red[position] == 'm' )
		{
			red[position] = 'V';
		}


		else if ( red[position] == 'N' || red[position] == 'n' )
		{
			red[position] = 'W';
		}


		else if ( red[position] == 'O' || red[position] == 'o' )
		{
			red[position] = 'X';
		}


		else if ( red[position] == 'P' || red[position] == 'p' )
		{
			red[position] = 'Y';
		}


		else if ( red[position] == 'Q' || red[position] == 'q' )
		{
			red[position] = 'Z';
		}

	}
	return red;
}

string blueDecrypt ( string blue )
{
			int size = blue.size();
	for ( int position = 0; position < size; position ++ )
	{
		if ( blue[position] == 'C' || blue[position] == 'c' )
		{
			blue[position] = 'A';
		}


		else if ( blue[position] == 'F' || blue[position] == 'f' )
		{
			blue[position] = 'B';
		}


		else if ( blue[position] == 'I' || blue[position] == 'i' )
		{
			blue[position] = 'C';
		}


		else if ( blue[position] == 'L' || blue[position] == 'l' )
		{
			blue[position] = 'D';
		}


		else if ( blue[position] == 'O' || blue[position] == 'o' )
		{
			blue[position] = 'E';
		}


		else if ( blue[position] == 'R' || blue[position] == 'r' )
		{
			blue[position] = 'F';
		}

		else if ( blue[position] == 'W' || blue[position] == 'w' )
		{
			blue[position] = 'G';
		}


		else if ( blue[position] == 'Z' || blue[position] == 'z' )
		{
			blue[position] = 'H';
		}


		else if ( blue[position] == 'Y' || blue[position] == 'y' )
		{
			blue[position] = 'I';
		}


		else if ( blue[position] == 'A' || blue[position] == 'a' )
		{
			blue[position] = 'J';
		}


		else if ( blue[position] == 'D' || blue[position] == 'd' )
		{
			blue[position] = 'K';
		}


		else if ( blue[position] == 'G' || blue[position] == 'g' )
		{
			blue[position] = 'L';
		}


		else if ( blue[position] == 'J' || blue[position] == 'j' )
		{
			blue[position] = 'M';
		}


		else if ( blue[position] == 'X' || blue[position] == 'x' )
		{
			blue[position] = 'N';
		}

		else if ( blue[position] == 'H' || blue[position] == 'h' )
		{
			blue[position] = 'O';
		}


		else if ( blue[position] == 'S' || blue[position] == 's' )
		{
			blue[position] = 'P';
		}

		else if ( blue[position] == 'V' || blue[position] == 'v' )
		{
			blue[position] = 'Q';
		}


		else if ( blue[position] == 'M' || blue[position] == 'm' )
		{
			blue[position] = 'R';
		}


		else if ( blue[position] == 'B' || blue[position] == 'b' )
		{
			blue[position] = 'S';
		}


		else if ( blue[position] == 'E' || blue[position] == 'e' )
		{
			blue[position] = 'T';
		}


		else if ( blue[position] == 'P' || blue[position] == 'p' )
		{
			blue[position] = 'U';
		}


		else if ( blue[position] == 'K' || blue[position] == 'k' )
		{
			blue[position] = 'V';
		}


		else if ( blue[position] == 'N' || blue[position] == 'n' )
		{
			blue[position] = 'W';
		}


		else if ( blue[position] == 'Q' || blue[position] == 'q' )
		{
			blue[position] = 'X';
		}


		else if ( blue[position] == 'U' || blue[position] == 'u' )
		{
			blue[position] = 'Y';
		}


		else if ( blue[position] == 'T' || blue[position] == 't' )
		{
			blue[position] = 'Z';
		}

	}
	return blue;
}

int main()
{
	string plaintext;
	int command = 0;
	cout << "Red and Blue Encryption and Decryption\n";
	cout << "Menu\n";
	cout << "\t1: Encrypt with key: Red\n";
	cout << "\t2: Decrypt with key: Red\n";
	cout << "\t3: Encrypt with key: Blue\n";
	cout << "\t4: Decrypt with key: Blue\n";
	cout << "\t5: Exit\n";
	cin >> command;
	while ( command !=5 )
	{
		switch( command )
		{
		case 1:
			{
				cout << "Enter Text: ";
				cin.ignore();
				getline( cin, plaintext );
				cout << endl << redEncrypt( plaintext ) << endl;
				break;
			}
		case 2:
			{
				cout << "Enter Text: ";
				cin.ignore();
				getline ( cin, plaintext );
				cout << endl << redDecrypt( plaintext ) << endl;
				break;
			}

		case 3:
			{
				cout << "Enter Text: ";
				cin.ignore();
				getline ( cin, plaintext );
				cout << endl << blueEncrypt( plaintext ) << endl;
				break;
			}
		case 4:
			{
				cout << "Enter Text: ";
				cin.ignore();
				getline ( cin, plaintext );
				cout << endl << blueDecrypt( plaintext ) << endl;
				break;
			}
		default:
			cout <<"Invalid Command\n";
		}

		cout << "\nRed and Blue Encryption and Decryption\n";
		cout << "Menu\n";
		cout << "\t1: Encrypt with key: Red\n";
		cout << "\t2: Decrypt with key: Red\n";
		cout << "\t3: Encrypt with key: Blue\n";
		cout << "\t4: Decrypt with key: Blue\n";
		cout << "\t5: Exit\n";
		cin >> command;
	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: problem using windows forms for program

#2 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5191
  • View blog
  • Posts: 26,901
  • Joined: 10-May 07

Re: problem using windows forms for program

Posted 24 April 2011 - 05:34 PM

What compiler are you using?

You need to define an id for the text boxes & buttons, & then add their id to the message loop.

Also, how are you able to have a windows program with main() & not WinMain() ?
Was This Post Helpful? 0
  • +
  • -

#3 tympaniplayer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-April 11

Re: problem using windows forms for program

Posted 24 April 2011 - 05:38 PM

Sorry, I'm using windows virtual studio 2010, and that is just a console application
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,437
  • Joined: 23-August 08

Re: problem using windows forms for program

Posted 25 April 2011 - 03:35 AM

MSDN's Visual C++ Developers' Center
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1