|
Body Tag Formatter |
![]() |
|
Introduction |
|
In this application, we will create a dialog box equipped with various controls. The subject is to create a format for the HTML's body tag. |
|
Practical Learning: Starting the Exercise |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
private String HexBG, HexText, HexLink, HexALink, HexVLink; |
private void ApplyColor()
{
// Retrieve the current hexadecimal colors from their Edit controls
HexBG = this.txtBackground.Text;
HexText = this.txtText.Text;
HexLink = this.txtLink.Text;
HexALink = this.txtActiveLink.Text;
HexVLink = this.txtVisitedLink.Text;
// Get the integral position of each ScrollBar control
String strRed = Convert.ToString(255 - this.scrRed.Value);
String strGreen = Convert.ToString(255 - this.scrGreen.Value);
String strBlue = Convert.ToString(255 - this.scrBlue.Value);
// Display the position of each ScrollBar
// in its corresponding Edit control
this.txtRed.Text = strRed;
this.txtGreen.Text = strGreen;
this.txtBlue.Text = strBlue;
// Change the color of the Preview panel
// according to the values of the ScrollBar positions
pnlPreview.BackColor = System.Drawing.Color.FromArgb(scrRed.Value, scrGreen.Value, scrBlue.Value);
String FmtRed = (255 - scrRed.Value).ToString("X");
if( FmtRed.Length == 1 )
FmtRed = String.Concat("0", FmtRed);
String FmtGreen = (255 - scrGreen.Value).ToString("X");
if( FmtGreen.Length == 1 )
FmtGreen = String.Concat("0", FmtGreen);
String FmtBlue = (255 - scrBlue.Value).ToString("X");
if( FmtBlue.Length == 1 )
FmtBlue = String.Concat("0", FmtBlue);
// 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 = "#";
BG = String.Concat(BG, FmtRed);
BG = String.Concat(BG, FmtGreen);
BG = String.Concat(BG, FmtBlue);
txtBackground.Text = BG;
pnlBody.BackColor = pnlPreview.BackColor;
txtTextPreview.BackColor = pnlPreview.BackColor;
txtLinkPreview.BackColor = pnlPreview.BackColor;
txtALinkPreview.BackColor = pnlPreview.BackColor;
txtVLinkPreview.BackColor = pnlPreview.BackColor;
HexBG = txtBackground.Text;
}
else if( rdoText.Checked == true )
{
String Txt = "#";
Txt = String.Concat(Txt, FmtRed);
Txt = String.Concat(Txt, FmtGreen);
Txt = String.Concat(Txt, FmtBlue);
txtText.Text = Txt;
txtTextPreview.ForeColor = System.Drawing.Color.FromArgb(scrRed.Value, scrGreen.Value, scrBlue.Value);
HexText = txtText.Text;
}
else if( rdoLink.Checked == true )
{
String TL = "#";
TL = String.Concat(TL, FmtRed);
TL = String.Concat(TL, FmtGreen);
TL = String.Concat(TL, FmtBlue);
txtLink.Text = TL;
txtLinkPreview.ForeColor = System.Drawing.Color.FromArgb(scrRed.Value, scrGreen.Value, scrBlue.Value);
HexLink = txtLink.Text;
}
else if( rdoActiveLink.Checked == true )
{
String AL = "#";
AL = String.Concat(AL, FmtRed);
AL = String.Concat(AL, FmtGreen);
AL = String.Concat(AL, FmtBlue);
txtActiveLink.Text = AL;
txtALinkPreview.ForeColor = System.Drawing.Color.FromArgb(scrRed.Value, scrGreen.Value, scrBlue.Value);
HexALink = txtActiveLink.Text;
}
else if( rdoVisitedLink.Checked == true )
{
String VL = "#";
VL = String.Concat(VL, FmtRed);
VL = String.Concat(VL, FmtGreen);
VL = String.Concat(VL, FmtBlue);
txtVisitedLink.Text = VL;
txtVLinkPreview.ForeColor = System.Drawing.Color.FromArgb(scrRed.Value, scrGreen.Value, scrBlue.Value);
HexVLink = txtVisitedLink.Text;
}
// Update the contents of the bottom Edit control
String BD = "<body bgcolor=\"";
BD = String.Concat(BD, HexBG);
BD = String.Concat(BD, "\" text=\"");
BD = String.Concat(BD, HexText);
BD = String.Concat(BD, "\" link=\"");
BD = String.Concat(BD, HexLink);
BD = String.Concat(BD, "\" alink=\"");
BD = String.Concat(BD, HexALink);
BD = String.Concat(BD, "\" vlink=\"");
BD = String.Concat(BD, HexVLink);
BD = String.Concat(BD, "\">");
txtResult.Text = BD;
}
|
private void scrRed_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
{
this.ApplyColor();
}
private void scrGreen_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
{
this.ApplyColor();
}
private void scrBlue_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
{
this.ApplyColor();
}
|
private void ClickOption(System.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 = String.Concat(Result, "#");
Result = String.Concat(Result, Red.ToString("X"));
Result = String.Concat(Result, Green.ToString("X"));
Result = String.Concat(Result, Blue.ToString("X"));
}
|
private void rdoBackground_CheckedChanged(object sender, System.EventArgs e)
{
// Call the ClickOption() method to calculate
// the hexadecimal value of the color
ClickOption(pnlBody.BackColor, txtBackground.Text);
HexBG = txtBackground.Text;
}
private void rdoText_CheckedChanged(object sender, System.EventArgs e)
{
System.Drawing.Color BGColor = pnlBody.BackColor;
txtTextPreview.BackColor = BGColor;
ClickOption(txtTextPreview.ForeColor, txtText.Text);
HexText = txtText.Text;
}
private void rdoLink_CheckedChanged(object sender, System.EventArgs e)
{
System.Drawing.Color BGColor = pnlBody.BackColor;
txtLinkPreview.BackColor = BGColor;
ClickOption(txtLinkPreview.ForeColor, txtLink.Text);
HexLink = txtLink.Text;
}
private void rdoActiveLink_CheckedChanged(object sender, System.EventArgs e)
{
System.Drawing.Color BGColor = pnlBody.BackColor;
txtALinkPreview.BackColor = BGColor;
ClickOption(txtALinkPreview.ForeColor, txtActiveLink.Text);
HexALink = txtActiveLink.Text;
}
private void rdoVisitedLink_CheckedChanged(object sender, System.EventArgs e)
{
System.Drawing.Color BGColor = pnlBody.BackColor;
txtVLinkPreview.BackColor = BGColor;
ClickOption(txtVLinkPreview.ForeColor, txtVisitedLink.Text);
HexVLink = txtVisitedLink.Text;
}
|
private void btnCopy_Click(object sender, System.EventArgs e)
{
this.txtResult.SelectAll();
this.txtResult.Copy();
}
|
private void btnClose_Click(object sender, System.EventArgs e)
{
Close();
}
|
|
|
||
| Home | Copyright © 2004 FunctionX, Inc. | |
|
|
||