|
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 System.ComponentModel.Container components = null;
private String HexBG, HexText, HexLink, HexALink, HexVLink;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
|
private void ApplyColor()
{
// Retrieve the current hexadecimal colors from their Edit controls
HexBG = this.txtBackground.get_Text();
HexText = this.txtText.get_Text();
HexLink = this.txtLink.get_Text();
HexALink = this.txtActiveLink.get_Text();
HexVLink = this.txtVisitedLink.get_Text();
// Get the integral position of each ScrollBar control
int iRed = 255 - this.scrRed.get_Value();
int iGreen = 255 - this.scrGreen.get_Value();
int iBlue = 255 - this.scrBlue.get_Value();
// Display the position of each ScrollBar
// in its corresponding Edit control
this.txtRed.set_Text(String.Format("{0}", (System.Int32)iRed));
this.txtGreen.set_Text(String.Format("{0}", (System.Int32)iGreen));
this.txtBlue.set_Text(String.Format("{0}", (System.Int32)iBlue));
// Change the color of the Preview panel
// according to the values of the ScrollBar positions
pnlPreview.set_BackColor(System.Drawing.Color.FromArgb(this.scrRed.get_Value(), this.scrGreen.get_Value(), this.scrBlue.get_Value()));
String FmtRed = String.Format("{0:X}", (System.Int32)(255 - scrRed.get_Value()));
if( FmtRed.get_Length() == 1 )
FmtRed = String.Concat("0", FmtRed);
String FmtGreen = String.Format("{0:X}", (System.Int32)(255 - scrGreen.get_Value()));
if( FmtGreen.get_Length() == 1 )
FmtGreen = String.Concat("0", FmtGreen);
String FmtBlue = String.Format("{0:X}", (System.Int32)(255 - scrBlue.get_Value()));
if( FmtBlue.get_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.get_Checked() == true )
{
String BG = "#";
BG = String.Concat(BG, FmtRed);
BG = String.Concat(BG, FmtGreen);
BG = String.Concat(BG, FmtBlue);
txtBackground.set_Text(BG);
pnlBody.set_BackColor(pnlPreview.get_BackColor());
txtTextPreview.set_BackColor(pnlPreview.get_BackColor());
txtLinkPreview.set_BackColor(pnlPreview.get_BackColor());
txtALinkPreview.set_BackColor(pnlPreview.get_BackColor());
txtVLinkPreview.set_BackColor(pnlPreview.get_BackColor());
HexBG = txtBackground.get_Text();
}
else if( rdoText.get_Checked() == true )
{
String Txt = "#";
Txt = String.Concat(Txt, FmtRed);
Txt = String.Concat(Txt, FmtGreen);
Txt = String.Concat(Txt, FmtBlue);
txtText.set_Text(Txt);
txtTextPreview.set_ForeColor(System.Drawing.Color.FromArgb(scrRed.get_Value(), scrGreen.get_Value(), scrBlue.get_Value()));
HexText = txtText.get_Text();
}
else if( rdoLink.get_Checked() == true )
{
String TL = "#";
TL = String.Concat(TL, FmtRed);
TL = String.Concat(TL, FmtGreen);
TL = String.Concat(TL, FmtBlue);
txtLink.set_Text(TL);
txtLinkPreview.set_ForeColor(System.Drawing.Color.FromArgb(scrRed.get_Value(), scrGreen.get_Value(), scrBlue.get_Value()));
HexLink = txtLink.get_Text();
}
else if( rdoActiveLink.get_Checked() == true )
{
String AL = "#";
AL = String.Concat(AL, FmtRed);
AL = String.Concat(AL, FmtGreen);
AL = String.Concat(AL, FmtBlue);
txtActiveLink.set_Text(AL);
txtALinkPreview.set_ForeColor(System.Drawing.Color.FromArgb(scrRed.get_Value(), scrGreen.get_Value(), scrBlue.get_Value()));
HexALink = txtActiveLink.get_Text();
}
else if( rdoVisitedLink.get_Checked() == true )
{
String VL = "#";
VL = String.Concat(VL, FmtRed);
VL = String.Concat(VL, FmtGreen);
VL = String.Concat(VL, FmtBlue);
txtVisitedLink.set_Text(VL);
txtVLinkPreview.set_ForeColor(System.Drawing.Color.FromArgb(scrRed.get_Value(), scrGreen.get_Value(), scrBlue.get_Value()));
HexVLink = txtVisitedLink.get_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.set_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.set_BackColor(Clr);
// Get the red value of the color of the Preview panel
Red = pnlPreview.get_BackColor().get_R();
// Get the green value of the color of the Preview panel
Green = pnlPreview.get_BackColor().get_G();
// Get the blue value of the color of the Preview panel
Blue = pnlPreview.get_BackColor().get_B();
// Now that we have the red, green, and blue values of the color,
// Update the scroll bars with the new values
scrRed.set_Value(Red);
scrGreen.set_Value(Green);
scrBlue.set_Value(Blue);
// Update the red, green, and blue values
// of the Numeric Values group box
txtRed.set_Text(String.Format("{0}",(System.Int32)Red));
txtGreen.set_Text(String.Format("{0}",(System.Int32)Green));
txtBlue.set_Text(String.Format("{0}",(System.Int32)Blue));
// Update the string that was passed using
// the retrieved red, green, and blue values
Result = String.Concat(Result, "#");
Result = String.Concat(Result, String.Format("{0:X}",(System.Int32)Red));
Result = String.Concat(Result, String.Format("{0:X}",(System.Int32)Green));
Result = String.Concat(Result, String.Format("{0:X}",(System.Int32)Blue));
}
|
private void rdoBackground_CheckedChanged (Object sender, System.EventArgs e)
{
// Call the ClickOption() method to calculate
// the hexadecimal value of the color
ClickOption(pnlBody.get_BackColor(), txtBackground.get_Text());
HexBG = txtBackground.get_Text();
}
private void rdoText_CheckedChanged (Object sender, System.EventArgs e)
{
System.Drawing.Color BGColor = pnlBody.get_BackColor();
txtTextPreview.set_BackColor(BGColor);
ClickOption(txtTextPreview.get_ForeColor(), txtText.get_Text());
HexText = txtText.get_Text();
}
private void rdoLink_CheckedChanged (Object sender, System.EventArgs e)
{
System.Drawing.Color BGColor = pnlBody.get_BackColor();
txtLinkPreview.set_BackColor(BGColor);
ClickOption(txtLinkPreview.get_ForeColor(), txtLink.get_Text());
HexLink = txtLink.get_Text();
}
private void rdoActiveLink_CheckedChanged (Object sender, System.EventArgs e)
{
System.Drawing.Color BGColor = pnlBody.get_BackColor();
txtALinkPreview.set_BackColor(BGColor);
ClickOption(txtALinkPreview.get_ForeColor(), txtActiveLink.get_Text());
HexALink = txtActiveLink.get_Text();
}
private void rdoVisitedLink_CheckedChanged (Object sender, System.EventArgs e)
{
System.Drawing.Color BGColor = pnlBody.get_BackColor();
txtVLinkPreview.set_BackColor(BGColor);
ClickOption(txtVLinkPreview.get_ForeColor(), txtVisitedLink.get_Text());
HexVLink = txtVisitedLink.get_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. | |
|
|
||