Body Tag Application

#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;

__gc public class SimpleForm : public Form
{
public:
	SimpleForm();
private:
	void InitializeComponent();
private:
	GroupBox	*grpBodyAttributes;
	RadioButton *rdoBackground;
	void BackgroundClick(Object *Sender, EventArgs *Args);
	RadioButton *rdoText;
	void TextClick(Object *Sender, EventArgs *Args);
	RadioButton *rdoLink;
	void LinkClick(Object *Sender, EventArgs *Args);
	RadioButton *rdoActiveLink;
	void ActiveLinkClick(Object *Sender, EventArgs *Args);
	RadioButton *rdoVisitedLink;
	void VisitedLinkClick(Object *Sender, EventArgs *Args);
	TextBox		*txtBackground;
	TextBox		*txtText;
	TextBox		*txtLink;
	TextBox		*txtActiveLink;
	TextBox		*txtVisitedLink;

                Panel		*pnlPreview;
	
	VScrollBar	*scrRed;
	void scrRedChange(Object *Sender, System::EventArgs *pArgs);
	VScrollBar	*scrGreen;
	void scrGreenChange(Object *Sender, System::EventArgs *pArgs);
	VScrollBar	*scrBlue;
	void scrBlueChange(Object *Sender, System::EventArgs *pArgs);
		
	TextBox		*txtBody;
	TextBox		*txtTextPreview;
	TextBox		*txtLinkPreview;
	TextBox		*txtActiveLinkPreview;
	TextBox		*txtVisitedLinkPreview;

	GroupBox	*grpColorValues;
	Label		*lblBlue;
	Label		*lblGreen;
	Label		*lblRed;
	TextBox		*txtRed;
	TextBox		*txtGreen;
	TextBox		*txtBlue;
	
	Button		*btnClose;
	void CloseClick(Object *Sender, EventArgs *Args);
	Button		*btnCopy;
	void CopyClick(Object *Sender, EventArgs *Args);
	
	TextBox		*txtResult;
private:
	String *HexBG, *HexText, *HexLink, *HexALink, *HexVLink;
	void ApplyColor();
	void ClickOption(Drawing::Color Clr, String *Result);
};

SimpleForm::SimpleForm()
{
	InitializeComponent();
}

void SimpleForm::InitializeComponent()
{
	this->Text = S"Body Tag Formatter";
	this->Size = Drawing::Size(504, 350);
	this->MaximizeBox = false; 
	this->Icon = new Drawing::Icon("bodytag.ico");


	// The Body Attributes group box
	this->grpBodyAttributes = new GroupBox();
	this->grpBodyAttributes->Location = Drawing::Point(8, 8);
	this->grpBodyAttributes->Size = Drawing::Size(176, 152);
	this->grpBodyAttributes->TabIndex = 0;
	this->grpBodyAttributes->TabStop = false;
	this->grpBodyAttributes->Text = "Body Attributes";

	// The Background radio button
	this->rdoBackground = new RadioButton();
	this->rdoBackground->Checked = true;
	this->rdoBackground->Location = Drawing::Point(16, 24);
	this->rdoBackground->Size = Drawing::Size(88, 24);
	this->rdoBackground->TabIndex = 0;
	this->rdoBackground->TabStop = true;
	this->rdoBackground->Text = "Background";
	this->rdoBackground->add_Click(new EventHandler(this, BackgroundClick));

	// The Text radio button
	this->rdoText = new RadioButton();
	this->rdoText->Location = Drawing::Point(16, 48);
	this->rdoText->Size = Drawing::Size(88, 24);
	this->rdoText->TabIndex = 1;
	this->rdoText->Text = "Text";
	this->rdoText->add_Click(new EventHandler(this, TextClick));
	
	// The Link radio button
	this->rdoLink = new RadioButton();
	this->rdoLink->Location = Drawing::Point(16, 72);
	this->rdoLink->Size = Drawing::Size(88, 24);
	this->rdoLink->TabIndex = 2;
	this->rdoLink->Text = "Link";
	this->rdoLink->add_Click(new EventHandler(this, LinkClick));

	// The Active Link radio button
	this->rdoActiveLink = new RadioButton();
	this->rdoActiveLink->Location = Drawing::Point(16, 96);
	this->rdoActiveLink->Size = Drawing::Size(88, 24);
	this->rdoActiveLink->TabIndex = 3;
	this->rdoActiveLink->Text = "Active Link";
	this->rdoActiveLink->add_Click(new EventHandler(this, ActiveLinkClick));
	
	// The Visited radio button
	this->rdoVisitedLink = new RadioButton();
	this->rdoVisitedLink->Location = Drawing::Point(16, 120);
	this->rdoVisitedLink->Size = Drawing::Size(88, 24);
	this->rdoVisitedLink->TabIndex = 4;
	this->rdoVisitedLink->Text = "Visited Link";
	this->rdoVisitedLink->add_Click(new EventHandler(this, VisitedLinkClick));

	// The Background text box
	this->txtBackground = new TextBox();
	this->txtBackground->Location = Drawing::Point(112, 24);
	this->txtBackground->Size = Drawing::Size(50, 20);
	this->txtBackground->TabIndex = 5;
	this->txtBackground->Text = "#FFFFFF";

	// The Text text box
	this->txtText = new TextBox();
	this->txtText->Location = Drawing::Point(112, 48);
	this->txtText->Size = Drawing::Size(50, 20);
	this->txtText->TabIndex = 6;
	this->txtText->Text = "#000000";
	
	// The Link text box
	this->txtLink = new TextBox();
	this->txtLink->Location = Drawing::Point(112, 72);
	this->txtLink->Size = Drawing::Size(50, 20);
	this->txtLink->TabIndex = 7;
	this->txtLink->Text = "#0000FF";

	// The Active Link text box
	this->txtActiveLink = new TextBox();
	this->txtActiveLink->Location = Drawing::Point(112, 96);
	this->txtActiveLink->Size = Drawing::Size(50, 20);
	this->txtActiveLink->TabIndex = 8;
	this->txtActiveLink->Text = "#008000";
	
	// The Visited Link text box
	this->txtVisitedLink = new TextBox();
	this->txtVisitedLink->Location = Drawing::Point(112, 120);
	this->txtVisitedLink->Size = Drawing::Size(50, 20);
	this->txtVisitedLink->TabIndex = 9;
	this->txtVisitedLink->Text = "#FF0000";

	this->grpBodyAttributes->Controls->Add(this->rdoBackground);
	this->grpBodyAttributes->Controls->Add(this->rdoText);
	this->grpBodyAttributes->Controls->Add(this->rdoLink);
	this->grpBodyAttributes->Controls->Add(this->rdoActiveLink);
	this->grpBodyAttributes->Controls->Add(this->rdoVisitedLink);
	this->grpBodyAttributes->Controls->Add(this->txtBackground);
	this->grpBodyAttributes->Controls->Add(this->txtText);
	this->grpBodyAttributes->Controls->Add(this->txtLink);
	this->grpBodyAttributes->Controls->Add(this->txtActiveLink);
	this->grpBodyAttributes->Controls->Add(this->txtVisitedLink);
	this->Controls->Add(grpBodyAttributes);
			
	// The Preview panel
	this->pnlPreview = new Panel();
	this->pnlPreview->BackColor = Drawing::Color::White;
	this->pnlPreview->BorderStyle = BorderStyle::Fixed3D;
	this->pnlPreview->Location = Drawing::Point(192, 12);
	this->pnlPreview->Name = "pnlPreview";
	this->pnlPreview->Size = Drawing::Size(128, 147);
	this->pnlPreview->TabIndex = 1;
	this->Controls->Add(pnlPreview);

	// The Red scroll bar
	this->scrRed = new VScrollBar();
	this->scrRed->Location = Drawing::Point(328, 12);
	this->scrRed->Minimum = 0;
	this->scrRed->Maximum = 255;
	this->scrRed->Size = Drawing::Size(16, 147);
	this->scrRed->TabIndex = 2;
	this->scrRed->Value = 255;
	this->scrRed->add_ValueChanged(new EventHandler(this, scrRedChange));
	this->Controls->Add(scrRed);

	// The green scroll bar
	this->scrGreen = new VScrollBar();
	this->scrGreen->Location = Drawing::Point(352, 12);
	this->scrGreen->Minimum = 0;
	this->scrGreen->Maximum = 255;
	this->scrGreen->Size = Drawing::Size(16, 146);
	this->scrGreen->TabIndex = 3;
	this->scrGreen->Value = 255;
	this->scrGreen->add_ValueChanged(new EventHandler(this, scrGreenChange));
	this->Controls->Add(scrGreen);

	// The blue scroll bar
	this->scrBlue = new VScrollBar();
	this->scrBlue->Location = Drawing::Point(376, 12);
	this->scrBlue->Minimum = 0;
	this->scrBlue->Maximum = 255;
	this->scrBlue->Size = Drawing::Size(16, 146);
	this->scrBlue->TabIndex = 4;
	this->scrBlue->Value = 255;
	this->scrBlue->add_ValueChanged(new EventHandler(this, scrBlueChange));
	this->Controls->Add(scrBlue);

	// The Body preview text box
	this->txtBody = new TextBox();
	this->txtBody->BackColor = Drawing::Color::White;
	this->txtBody->Location = Drawing::Point(8, 176);
	this->txtBody->Multiline = true;
	this->txtBody->Size = Drawing::Size(256, 104);
	this->txtBody->TabIndex = 5;
	this->txtBody->Text = "";

	// The Preview text box
	this->txtTextPreview = new TextBox();
	this->txtTextPreview->BorderStyle = BorderStyle::None;
	this->txtTextPreview->ForeColor = Drawing::Color::Black;
	this->txtTextPreview->Location = Drawing::Point(24, 184);
	this->txtTextPreview->Size = Drawing::Size(224, 13);
	this->txtTextPreview->TabIndex = 10;
	this->txtTextPreview->Text = "Body tag formatter and colorizer";
	this->txtTextPreview->TextAlign = HorizontalAlignment::Center;

	// The Link Preview text box
	this->txtLinkPreview = new TextBox();
	this->txtLinkPreview->BorderStyle = BorderStyle::None;
	this->txtLinkPreview->ForeColor = Drawing::Color::Blue;
	this->txtLinkPreview->Location = Drawing::Point(24, 208);
	this->txtLinkPreview->Size = Drawing::Size(224, 13);
	this->txtLinkPreview->TabIndex = 11;
	this->txtLinkPreview->Text = "Sample text as link";
	this->txtLinkPreview->TextAlign = HorizontalAlignment::Center; 

	// The Active Link Preview text box
	this->txtActiveLinkPreview = new TextBox();
	this->txtActiveLinkPreview->BorderStyle = BorderStyle::None;
	this->txtActiveLinkPreview->ForeColor = Drawing::Color::Green;
	this->txtActiveLinkPreview->Location = Drawing::Point(24, 232);
	this->txtActiveLinkPreview->Size = Drawing::Size(224, 13);
	this->txtActiveLinkPreview->TabIndex = 12;
	this->txtActiveLinkPreview->Text = "Active link that has been visited";
	this->txtActiveLinkPreview->TextAlign = HorizontalAlignment::Center; 

	// The Visited Link Preview text box
	this->txtVisitedLinkPreview = new TextBox();
	this->txtVisitedLinkPreview->BorderStyle = BorderStyle::None;
	this->txtVisitedLinkPreview->ForeColor = Drawing::Color::Red;
	this->txtVisitedLinkPreview->Location = Drawing::Point(24, 256);
	this->txtVisitedLinkPreview->Size = Drawing::Size(224, 13);
	this->txtVisitedLinkPreview->TabIndex = 13;
	this->txtVisitedLinkPreview->Text = "This link has been visited";
	this->txtVisitedLinkPreview->TextAlign = HorizontalAlignment::Center;

	this->Controls->Add(txtTextPreview);
	this->Controls->Add(txtLinkPreview);
	this->Controls->Add(txtActiveLinkPreview);
	this->Controls->Add(txtVisitedLinkPreview);
	this->Controls->Add(txtBody);

	// The Color Values group box
	this->grpColorValues = new GroupBox();
	this->grpColorValues->Location = Drawing::Point(272, 176);
	this->grpColorValues->Size = Drawing::Size(122, 104);
	this->grpColorValues->TabIndex = 6;
	this->grpColorValues->TabStop = false;
	this->grpColorValues->Text = "Color Values";

	// The Red label
	this->lblRed = new Label();
	this->lblRed->AutoSize = true;
	this->lblRed->Location = Drawing::Point(8, 30);
	this->lblRed->Size = Drawing::Size(28, 13);
	this->lblRed->TabIndex = 0;
	this->lblRed->Text = "Red:";
	this->grpColorValues->Controls->Add(this->lblRed);

	// The Green label
	this->lblGreen = new Label();
	this->lblGreen->AutoSize = true;
	this->lblGreen->Location = Drawing::Point(8, 54);
	this->lblGreen->Size = Drawing::Size(39, 13);
	this->lblGreen->TabIndex = 1;
	this->lblGreen->Text = "Green:";
	this->grpColorValues->Controls->Add(this->lblGreen);

	// The Blue label
	this->lblBlue = new Label();
	this->lblBlue->AutoSize = true;
	this->lblBlue->Location = Drawing::Point(8, 80);
	this->lblBlue->Size = Drawing::Size(30, 13);
	this->lblBlue->TabIndex = 2;
	this->lblBlue->Text = "Blue:";
	this->grpColorValues->Controls->Add(this->lblBlue);

	// The Red text box
	this->txtRed = new TextBox();
	this->txtRed->Location = Drawing::Point(72, 24);
	this->txtRed->Size = Drawing::Size(40, 20);
	this->txtRed->TabIndex = 3;
	this->txtRed->Text = "255";
	this->txtRed->TextAlign = HorizontalAlignment::Right;
	this->grpColorValues->Controls->Add(this->txtRed);
	
	// The Green text box
	this->txtGreen = new TextBox();
	this->txtGreen->Location = Drawing::Point(72, 48);
	this->txtGreen->Size = Drawing::Size(40, 20);
	this->txtGreen->TabIndex = 4;
	this->txtGreen->Text = "255";
	this->txtGreen->TextAlign = HorizontalAlignment::Right;
	this->grpColorValues->Controls->Add(txtGreen);
	
	// The Blue text box
	this->txtBlue = new TextBox();
	this->txtBlue->Location = Drawing::Point(72, 72);
	this->txtBlue->Size = Drawing::Size(40, 20);
	this->txtBlue->TabIndex = 5;
	this->txtBlue->Text = "255";
	this->txtBlue->TextAlign = HorizontalAlignment::Right;

	this->grpColorValues->Controls->Add(this->txtBlue);
	this->Controls->Add(grpColorValues);

	// The Close button
	this->btnClose = new Button();
	this->btnClose->Location = Drawing::Point(408, 12);
	this->btnClose->TabIndex = 7;
	this->btnClose->Text = "&Close";
	this->btnClose->Click += new EventHandler(this, CloseClick);
	this->Controls->Add(btnClose);

	// The Copy button
	this->btnCopy = new Button();
	this->btnCopy->Location = Drawing::Point(408, 256);
	this->btnCopy->TabIndex = 8;
	this->btnCopy->Text = "C&opy";
	this->btnCopy->Click += new EventHandler(this, CopyClick);
	this->Controls->Add(btnCopy);

	// The Result text box
	this->txtResult = new TextBox();
	this->txtResult->Location = Drawing::Point(8, 288);
	this->txtResult->Name = "txtResult";
	this->txtResult->Size = Drawing::Size(476, 20);
	this->txtResult->TabIndex = 9;
	this->txtResult->Text = "<body bgcolor=\"#FFFFFF\" text=\"#000000\" link=\"#0000FF\" alink=\"#008000\" vlink=\"#FF0000\">";
	this->Controls->Add(txtResult);
}

void SimpleForm::ApplyColor()
{
	// Retrieve the current hexadecimal colors from their Edit controls
    HexBG = txtBackground->Text;
    HexText = txtText->Text;
    HexLink = txtLink->Text;
    HexALink = txtActiveLink->Text;
    HexVLink = txtVisitedLink->Text;

    // Get the integral position of each ScrollBar control
	String *strRed   = Convert::ToString(scrRed->Value);
    String *strGreen = Convert::ToString(scrGreen->Value);
    String *strBlue  = Convert::ToString(scrBlue->Value);

    // Display the position of each ScrollBar
    // in its corresponding Edit control
    txtRed->Text   = strRed;
    txtGreen->Text = strGreen;
    txtBlue->Text  = strBlue;

    // Change the color of the Preview panel
    // according to the values of the ScrollBar positions
	pnlPreview->BackColor = Drawing::Color::FromArgb(scrRed->Value, scrGreen->Value, scrBlue->Value);

    // Get the position of each ScrollBar control
    // Create a hexadecimal color starting with #
    // And display the color in the appropriate Edit control
    if( rdoBackground->Checked == true )
	{
		String *BG = S"#";
				BG = BG->Concat(BG, scrRed->Value.ToString("X"));
				BG = BG->Concat(BG, scrGreen->Value.ToString("X"));
				BG = BG->Concat(BG, scrBlue->Value.ToString("X"));
        txtBackground->Text              = BG;
        txtBody->BackColor				 = pnlPreview->BackColor;
        txtTextPreview->BackColor		 = pnlPreview->BackColor;
        txtLinkPreview->BackColor		 = pnlPreview->BackColor;
        txtActiveLinkPreview->BackColor  = pnlPreview->BackColor;
        txtVisitedLinkPreview->BackColor = pnlPreview->BackColor;
        HexBG = txtBackground->Text;
	}
	else if( rdoText->Checked == true )
	{
		String *Txt = S"#";
				Txt = Txt->Concat(Txt, scrRed->Value.ToString("X"));
				Txt = Txt->Concat(Txt, scrGreen->Value.ToString("X"));
				Txt = Txt->Concat(Txt, scrBlue->Value.ToString("X"));
		txtText->Text = Txt;
		txtTextPreview->ForeColor = Drawing::Color::FromArgb(scrRed->Value, scrGreen->Value, scrBlue->Value);
        HexText = txtText->Text;
	}
	else if( rdoLink->Checked == true )
	{
		String *TL = S"#";
				TL = TL->Concat(TL, scrRed->Value.ToString("X"));
				TL = TL->Concat(TL, scrGreen->Value.ToString("X"));
				TL = TL->Concat(TL, scrBlue->Value.ToString("X"));
		txtLink->Text = TL;
        txtLinkPreview->ForeColor = Drawing::Color::FromArgb(scrRed->Value, scrGreen->Value, scrBlue->Value);
        HexLink = txtLink->Text;
	}
	else if( rdoActiveLink->Checked == true )
	{
		String *AL = S"#";
				AL = AL->Concat(AL, scrRed->Value.ToString("X"));
				AL = AL->Concat(AL, scrGreen->Value.ToString("X"));
				AL = AL->Concat(AL, scrBlue->Value.ToString("X"));
		txtActiveLink->Text = AL;
        txtActiveLinkPreview->ForeColor = Drawing::Color::FromArgb(scrRed->Value, scrGreen->Value, scrBlue->Value);
        HexALink = txtActiveLink->Text;
	}
	else if( rdoVisitedLink->Checked == true )
	{
		String *VL = S"#";
				VL = VL->Concat(VL, scrRed->Value.ToString("X"));
				VL = VL->Concat(VL, scrGreen->Value.ToString("X"));
				VL = VL->Concat(VL, scrBlue->Value.ToString("X"));
		txtVisitedLink->Text = VL;
        txtVisitedLinkPreview->ForeColor = Drawing::Color::FromArgb(scrRed->Value, scrGreen->Value, scrBlue->Value);
        HexVLink = txtVisitedLink->Text;
    }

    // Update the contents of the bottom Edit control
    String *BD = S"<body bgcolor=\"";
			BD = BD->Concat(BD, HexBG);
			BD = BD->Concat(BD, S"\" text=\"");
			BD = BD->Concat(BD, HexText);
			BD = BD->Concat(BD, S"\" link=\"");
			BD = BD->Concat(BD, HexLink);
			BD = BD->Concat(BD, S"\" alink=\"");
			BD = BD->Concat(BD, HexALink);
			BD = BD->Concat(BD, S"\" vlink=\"");
			BD = BD->Concat(BD, HexVLink);
			BD = BD->Concat(BD, S"\">");
	txtResult->Text = BD;
}

void SimpleForm::scrRedChange(Object *Sender, System::EventArgs *pArgs)
{
	ApplyColor();
}

void SimpleForm::scrGreenChange(Object *Sender, System::EventArgs *pArgs)
{
	ApplyColor();
}

void SimpleForm::scrBlueChange(Object *Sender, System::EventArgs *pArgs)
{
	ApplyColor();
}

void SimpleForm::ClickOption(Drawing::Color Clr, String *Result)
{
	// These variables will hold the red, green, and blue
	// values of the passed color
    int Red, Green, Blue;

	// Colorize the Preview panel with the passed color
    pnlPreview->BackColor = Clr;

	// Get the red value of the color of the Preview panel
	Red = pnlPreview->BackColor.R;
	// Get the green value of the color of the Preview panel
    Green = pnlPreview->BackColor.G;
	// Get the blue value of the color of the Preview panel
    Blue = pnlPreview->BackColor.B;

	// Now that we have the red, green, and blue values of the color,
	// Update the scroll bars with the new values
    scrRed->Value = Red;
    scrGreen->Value = Green;
    scrBlue->Value = Blue;

	// Update the red, green, and blue values
	// of the Numeric Values group box
    txtRed->Text   = Red.ToString();
    txtGreen->Text = Green.ToString();
    txtBlue->Text  = Blue.ToString();

	// Update the string that was passed using
	// the retrieved red, green, and blue values
    Result = Result->Concat(Result, S"#");
	Result = Result->Concat(Result, Red.ToString("X"));
	Result = Result->Concat(Result, Green.ToString("X"));
	Result = Result->Concat(Result, Blue.ToString("X"));
}

void SimpleForm::BackgroundClick(Object *Sender, EventArgs *Args)
{
	// If the user clicks Background radio button
    // set color of the panel to that of the radio button
	Drawing::Color BGColor = txtBody->BackColor;

    txtBody->BackColor      = BGColor;

	// Call the ClickOption() method to calculate
	// the hexadecimal value of the color
    ClickOption(txtBody->BackColor, txtBackground->Text);
    HexBG = txtBackground->Text;
}

void SimpleForm::TextClick(Object *Sender, EventArgs *Args)
{
	Drawing::Color BGColor = txtBody->BackColor;

    txtTextPreview->BackColor  = BGColor;

    ClickOption(txtTextPreview->ForeColor, txtText->Text);
	HexText = txtText->Text;   
}

void SimpleForm::LinkClick(Object *Sender, EventArgs *Args)
{
	Drawing::Color BGColor = txtBody->BackColor;

	txtLinkPreview->BackColor  = BGColor;

	ClickOption(txtLinkPreview->ForeColor, txtLink->Text);
	HexLink = txtLink->Text;   
}

void SimpleForm::ActiveLinkClick(Object *Sender, EventArgs *Args)
{
	Drawing::Color BGColor = txtBody->BackColor;

	txtActiveLinkPreview->BackColor  = BGColor;

	ClickOption(txtActiveLinkPreview->ForeColor, txtActiveLink->Text);
	HexALink = txtActiveLink->Text;   
}

void SimpleForm::VisitedLinkClick(Object *Sender, EventArgs *Args)
{
	Drawing::Color BGColor = txtBody->BackColor;

	txtVisitedLinkPreview->BackColor  = BGColor;

	ClickOption(txtVisitedLinkPreview->ForeColor, txtVisitedLink->Text);
	HexVLink = txtVisitedLink->Text;   
}

void SimpleForm::CopyClick(Object *Sender, EventArgs *Args)
{
	this->txtResult->SelectAll();
	this->txtResult->Copy();
}

void SimpleForm::CloseClick(Object *Sender, EventArgs *Args)
{
	Close();
}

int __stdcall WinMain()
{
	SimpleForm *FM = new SimpleForm;
	Application::Run(FM);

	return 0;
}

Home