dummy1912
Dummy1912

Posts: 17
Registered: Jun 2010 |
|
 | Attached file 00015.png
(16.12 KB, 1 downloads.) |
|
Import:
code: Imports System.Drawing.Drawing2D
code: <br />
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint<br />
<br />
Const TXT As String = "RAINBOW!"<br />
Dim the_font As New Font("Times New Roman", 150, FontStyle.Bold, GraphicsUnit.Pixel)<br />
<br />
Dim em_height As Integer = the_font.FontFamily.GetEmHeight(FontStyle.Bold)<br />
Dim em_height_pix As Single = the_font.Size<br />
Dim design_to_pixels As Single = the_font.Size / em_height<br />
Dim ascent As Integer = the_font.FontFamily.GetCellAscent(FontStyle.Bold)<br />
Dim ascent_pix As Single = ascent * design_to_pixels<br />
Dim descent As Integer = the_font.FontFamily.GetCellDescent(FontStyle.Bold)<br />
Dim descent_pix As Single = descent * design_to_pixels<br />
Dim cell_height_pix As Single = ascent_pix + descent_pix<br />
Dim internal_leading_pix As Single = cell_height_pix - em_height_pix<br />
Dim line_spacing As Integer = the_font.FontFamily.GetLineSpacing(FontStyle.Bold)<br />
Dim line_spacing_pix As Single = line_spacing * design_to_pixels<br />
Dim external_leading_pix As Single = line_spacing_pix - cell_height_pix<br />
<br />
' See how big the text is.<br />
Dim text_size As SizeF = e.Graphics.MeasureString(TXT, the_font)<br />
Dim x0 As Integer = CInt((Me.ClientSize.Width - text_size.Width) / 2)<br />
Dim y0 As Integer = CInt((Me.ClientSize.Height - text_size.Height) / 2)<br />
<br />
' Get the Y coordinates that the brush should span.<br />
Dim brush_y0 As Integer = CInt(y0 + internal_leading_pix)<br />
Dim brush_y1 As Integer = CInt(y0 + ascent_pix)<br />
<br />
' Fudge the brush down a smidgen.<br />
brush_y0 += CInt(internal_leading_pix)<br />
brush_y1 += 5<br />
<br />
' Make a brush to color the area.<br />
Dim the_brush As New LinearGradientBrush( _<br />
New Point(x0, brush_y0), _<br />
New Point(x0, brush_y1), _<br />
Color.Red, Color.Violet)<br />
Dim color_blend As New ColorBlend<br />
color_blend.Colors = New Color() {Color.Red, Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Indigo}<br />
<br />
color_blend.Positions = New Single() {0, 1 / 7, 2 / 7, 3 / 7, 4 / 7, 5 / 7, 6 / 7, 1}<br />
the_brush.InterpolationColors = color_blend<br />
<br />
' Draw the text.<br />
e.Graphics.DrawString(TXT, the_font, the_brush, x0, y0)<br />
<br />
If False Then<br />
' Debugging statements.<br />
' Fill a rainbow rectangle for reference.<br />
e.Graphics.FillRectangle(the_brush, x0, brush_y0, 10, brush_y1 - brush_y0)<br />
<br />
' Outline the text area.<br />
e.Graphics.DrawRectangle(Pens.Blue, x0, y0, text_size.Width, text_size.Height)<br />
<br />
' Draw the internal leading line.<br />
Dim y As Single<br />
y = y0 + internal_leading_pix<br />
e.Graphics.DrawLine(Pens.Red, x0, y, x0 + text_size.Width, y)<br />
<br />
' Draw the internal baseline.<br />
y = y0 + ascent_pix<br />
e.Graphics.DrawLine(Pens.Red, x0, y, x0 + text_size.Width, y)<br />
<br />
' Draw the internal descent line.<br />
y = y0 + cell_height_pix<br />
e.Graphics.DrawLine(Pens.Red, x0, y, x0 + text_size.Width, y)<br />
End If<br />
<br />
the_brush.Dispose()<br />
the_font.Dispose()<br />
End Sub<br />
|