Text Effects in Visual Basic 2008 (Block)

This is the continuation of my last tutorial which is Text Effects in Visual Basic 2008. Now, I will teach you how to “Block” Effect on the text. With this, it will create the text with an embossed look. You can adjust the Depth and even the font size of the text. So let’s get started: Open Visual Basic 2008 and open the file which is the Effects in Visual Basic 2008. Then, add the Label and NumericDownUp named it “nudDepth” and set the value to 10 And it will look like this. First Form After that, go to the code viewer and create a sub procedure for the ” Block” effects.
  1. Private Sub draw_block_text()
  2.         Dim text_size As SizeF
  3.         Dim grafx As Graphics
  4.         Dim back_brush As Brush = Brushes.Black 'COLOR FOR THE BOARDER TEXT
  5.         Dim fore_brush As Brush = Brushes.RoyalBlue 'COLOR FOR THE MAIN TEXT
  6.         Dim fnt As New Font("Microsoft Sans Serif", NumericUpDown1.Value, FontStyle.Regular)
  7.         Dim location_x, location_y As Single 'USED IT FOR THE LOCATION
  8.         Dim i As Integer
  9.  
  10.         'CREATE A GRAPHIC OBJECT IN THE PICTUREBOX.
  11.         grafx = PictureBox1.CreateGraphics()
  12.         'CLEAR THE PICTUREBOX
  13.         grafx.Clear(Color.White)
  14.  
  15.         'LOOK THE REQUIRED SIZE TO DRAW THE TEXT
  16.         text_size = grafx.MeasureString(Me.TextBox1.Text, fnt)
  17.  
  18.         'ELIMINATE THE REDUNDANT CAlCULATION AFTER GETTING THE LOCATION.
  19.         location_x = (PictureBox1.Width - text_size.Width) / 2
  20.         location_y = (PictureBox1.Height - text_size.Height) / 2
  21.  
  22.  
  23.  
  24.         'FIRST, DRAW THE BLACK BACKGROUND TO GET THE EFFECT,
  25.         'AND THE TEXT MUST BE DRAWN REAPETEDLY FROM THE OFFSET RIGHT, UP TO THE MAIN TEXT IS DRAWN.
  26.         For i = CInt(nupDepth.Value) To 0 Step -1
  27.             grafx.DrawString(TextBox1.Text, fnt, back_brush, _
  28.                     location_x - i, location_y + i)
  29.         Next
  30.  
  31.         'DRAW THE ROYAL BLUE FOR THE MAIN TEXT OVER THE BLACk TEXT
  32.         grafx.DrawString(TextBox1.Text, fnt, fore_brush, location_x, location_y)
  33.     End Sub
Then, in the “effectlist” sub procedure add the Block item in the Combobox. It will look like this.
  1. Private Sub effectlist()
  2.         With ComboBox1.Items
  3.             .Clear()
  4.             .Add("Reflect")
  5.             .Add("Block")
  6.         End With
After that, update the code of the “draw_text” sub procedure and do this following code. The effects perform when the value of the ComboBox is changed.
  1. Private Sub draw_text()
  2.         If ComboBox1.SelectedItem Is Nothing Then
  3.             effectlist()
  4.             ComboBox1.SelectedIndex = 0
  5.         End If
  6.  
  7.         Select Case ComboBox1.SelectedItem.ToString()
  8.             Case "Reflect"
  9.                 Draw_Reflect_Text()
  10.                 nupDepth.Enabled = False
  11.             Case "Block"
  12.                 draw_block_text()
  13.                 nupDepth.Enabled = True
  14.         End Select
  15.     End Sub
Lastly, for the UIChange sub procedure add this "ComboBox1.SelectedValueChanged , nupDepth.ValueChanged” to the events handler. It will look like this.
  1.    Private Sub UIChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
  2.         Handles TextBox1.TextChanged, NumericUpDown1.ValueChanged, PictureBox1.MouseHover, _
  3.         ComboBox1.SelectedValueChanged, nupDepth.ValueChanged
  4.  
  5.         If NumericUpDown1.Value = 0 Then
  6.             NumericUpDown1.Value = 50
  7.         End If
  8.         draw_text()
  9.  
  10.     End Sub
Output: Output

Add new comment