|
Body Tag Formatter |
|
|
Practical Learning: Starting the Exercise |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public Class Form1
Inherits System.Windows.Forms.Form
Private HexBG, HexText, HexLink, HexALink, HexVLink As String
|
Private Sub ApplyColor()
Dim strRed As String
Dim strGreen As String
Dim strBlue As String
Dim FmtRed As String
Dim FmtGreen As String
Dim FmtBlue As String
Dim BG As String
Dim Txt As String
Dim TL As String
Dim AL As String
Dim VL As String
Dim BD As String
HexBG = Me.txtBackground.Text
HexText = Me.txtText.Text
HexLink = Me.txtLink.Text
HexALink = Me.txtActiveLink.Text
HexVLink = Me.txtVisitedLink.Text
' Get the integral position of each ScrollBar control
strRed = CStr(255 - Me.scrRed.Value)
strGreen = CStr(255 - Me.scrGreen.Value)
strBlue = CStr(255 - Me.scrBlue.Value)
' Display the position of each ScrollBar
' in its corresponding Edit control
Me.txtNumRed.Text = strRed
Me.txtNumGreen.Text = strGreen
Me.txtNumBlue.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)
FmtRed = Hex(255 - scrRed.Value)
If Len(FmtRed) = 1 Then
FmtRed = "0" & FmtRed
End If
FmtGreen = Hex(255 - scrGreen.Value)
If Len(FmtGreen) = 1 Then
FmtGreen = "0" & FmtGreen
End If
FmtBlue = Hex(255 - scrBlue.Value)
If Len(FmtBlue) = 1 Then
FmtBlue = "0" & FmtBlue
End If
' Display the position of each ScrollBar
' in its corresponding hexadecimal text control
Me.txtHexRed.Text = FmtRed
Me.txtHexGreen.Text = FmtGreen
Me.txtHexBlue.Text = 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 Then
BG = "#" & FmtRed & FmtGreen & 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
ElseIf rdoText.Checked = True Then
Txt = "#" & FmtRed & FmtGreen & FmtBlue
txtText.Text = Txt
txtTextPreview.ForeColor = System.Drawing.Color.FromArgb(scrRed.Value, scrGreen.Value, scrBlue.Value)
HexText = txtText.Text
ElseIf rdoLink.Checked = True Then
TL = "#"
TL = TL & FmtRed
TL = TL & FmtGreen
TL = TL & FmtBlue
txtLink.Text = TL
txtLinkPreview.ForeColor = System.Drawing.Color.FromArgb(scrRed.Value, scrGreen.Value, scrBlue.Value)
HexLink = txtLink.Text
ElseIf rdoActiveLink.Checked = True Then
AL = "#"
AL = AL & FmtRed
AL = AL & FmtGreen
AL = AL & FmtBlue
txtActiveLink.Text = AL
txtALinkPreview.ForeColor = System.Drawing.Color.FromArgb(scrRed.Value, scrGreen.Value, scrBlue.Value)
HexALink = txtActiveLink.Text
ElseIf rdoVisitedLink.Checked = True Then
VL = "#"
VL = VL & FmtRed
VL = VL & FmtGreen
VL = VL & FmtBlue
txtVisitedLink.Text = VL
txtVLinkPreview.ForeColor = System.Drawing.Color.FromArgb(scrRed.Value, scrGreen.Value, scrBlue.Value)
HexVLink = txtVisitedLink.Text
End If
' Update the contents of the bottom Edit control
BD = "<body bgcolor=""" & txtBackground.Text & """" & " text=""" _
& txtText.Text & """" & " link=""" & txtLink.Text & """" & " alink=""" _
& txtActiveLink.Text & """" & " vlink=""" & txtVisitedLink.Text _
& """ >"
txtResult.Text = BD
End Sub
|
Private Sub scrRed_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles scrRed.Scroll
Me.ApplyColor()
End Sub
Private Sub scrGreen_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles scrGreen.Scroll
Me.ApplyColor()
End Sub
Private Sub scrBlue_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles scrBlue.Scroll
Me.ApplyColor()
End Sub
|
Private Sub ClickOption(ByVal lngColor As Long, ByVal Result As String)
' These variables will hold the red, green, and blue
' values of the passed color
Dim iRed As Integer
Dim iGreen As Integer
Dim iBlue As Integer
' Colorize the Preview panel with the passed color
pnlPreview.BackColor = lngColor
' Get the red value of the color of the Preview panel
iRed = lngColor Mod 256
' Get the green value of the color of the Preview panel
iGreen = (lngColor / 256) Mod 256
' Get the blue value of the color of the Preview panel
iBlue = lngColor / 65536
' Now that we have the red, green, and blue values of the color,
'Update the scroll bars with the new values
scrRed.Value = iRed
scrGreen.Value = iGreen
scrBlue.Value = iBlue
' Update the red, green, and blue values
' of the Numeric Values group box
txtNumRed.Text = CStr(iRed)
txtNumGreen.Text = CStr(iGreen)
txtNumBlue.Text = CStr(iBlue)
'Update the string that was passed using
' the retrieved red, green, and blue values
Result = "#" & Hex(iRed) & Hex(iGreen) & Hex(iBlue)
End Sub
|
Private Sub rdoBackground_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoBackground.CheckedChanged
' If the user clicks Background radio button
' set color of the panel to that of the radio button
Dim BGColor As System.Drawing.Color
BGColor = pnlBody.BackColor
' pnlBody.BackColor = BGColor;
' Call the ClickOption procedure to calculate
' the hexadecimal value of the color
ClickOption(pnlBody.BackColor, txtBackground.Text)
HexBG = txtBackground.Text
End Sub
Private Sub rdoText_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoText.CheckedChanged
Dim BGColor As System.Drawing.Color
BGColor = pnlBody.BackColor
txtTextPreview.BackColor = BGColor
ClickOption(txtTextPreview.ForeColor, txtText.Text)
HexText = txtText.Text
End Sub
Private Sub rdoLink_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoLink.CheckedChanged
Dim BGColor As System.Drawing.Color
BGColor = pnlBody.BackColor
txtLinkPreview.BackColor = BGColor
ClickOption(txtLinkPreview.ForeColor, txtLink.Text)
HexLink = txtLink.Text
End Sub
Private Sub rdoActiveLink_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoActiveLink.CheckedChanged
Dim BGColor As System.Drawing.Color
BGColor = pnlBody.BackColor
txtALinkPreview.BackColor = BGColor
ClickOption(txtALinkPreview.ForeColor, txtActiveLink.Text)
HexALink = txtActiveLink.Text
End Sub
Private Sub rdoVisitedLink_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoVisitedLink.CheckedChanged
Dim BGColor As System.Drawing.Color
BGColor = pnlBody.BackColor
txtVLinkPreview.BackColor = BGColor
ClickOption(txtVLinkPreview.ForeColor, txtVisitedLink.Text)
HexVLink = txtVisitedLink.Text
End Sub
|
Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click
Me.txtResult.SelectAll()
Me.txtResult.Copy()
End Sub
|
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Close()
End Sub
|
|
|
||
| Home | Copyright © 2004 FunctionX, Inc. | |
|
|
||