Text Effects in Visual Basic 2008 (Shear)

This is the continuation of my last topic which is Text Effects in Visual Basic 2008 (Block). This time, I’m going to add another text effect which is the ”Shear”. With the use of “Shear”, you can slide the text from left to right or right to left. At the same time, you can adjust the slide effects of the text whatever sliding position you like. Let’s begin: First, open the file of Text Effects in Visual Basic 2008 (Block). After that, add new “NumericUpDown” and name it “nudShear”. It will look like this. First Form Then, go to the Solution Explorer and click the code view. After that, do the following code in creating a sub procedure for the "Shear" effects.
  1. Private Sub draw_shear_text()
  2. Dim text_size As SizeF
  3. Dim grafx As Graphics
  4. Dim fore_brush As Brush = Brushes.Blue
  5. Dim fnt As New Font("Microsoft Sans Serif", NumericUpDown1.Value, FontStyle.Regular)
  6. Dim tranform As Matrix
  7. Dim location_x, location_y As Single
  8.  
  9. 'CREATE THE GRAPHICS OBJECT IN THE PICTUREBOX.
  10. grafx = PictureBox1.CreateGraphics()
  11. 'CLEAR THE GRAPHICS OBJECT
  12. grafx.Clear(Color.White)
  13.  
  14. 'SET THE REQUIRE SIZE TO DRAW THE TEXT.
  15. text_Size = grafx.MeasureString(TextBox1.Text, fnt)
  16.  
  17. 'ELIMINATE THE REDUNDANT CALCULATION AFTER GETTING THE LOCATION.
  18. location_x = (PictureBox1.Width - text_size.Width) / 2
  19. location_y = (PictureBox1.Height - text_size.Height) / 2
  20.  
  21.  
  22. 'REPOSITION THE ORIGIN OF THE GRAPHICS OBJECT (0,0) TO THE (location_x,
  23. ' location_y) POINT.
  24. grafx.TranslateTransform(location_x, location_y)
  25.  
  26.  
  27. 'SPECIFY THE AMOUNT TO TRANSFORM THE CURRENT GRAPHICS OBJECT TO A SHEAR TEXT.
  28. tranform = grafx.Transform
  29. tranform.Shear(nudShear.Value, 0)
  30. grafx.Transform = tranform
  31.  
  32.  
  33. 'MAIN TEXT DRAWN.
  34. grafx.DrawString(TextBox1.Text, fnt, fore_brush, 0, 0)
  35. End Sub
Update the “effectlist” sub procedure. Add the item in the ComboBox which is “Shear”.
  1. Private Sub effectlist()
  2. With ComboBox1.Items
  3. .Clear()
  4. .Add("Reflect")
  5. .Add("Block")
  6. .Add("Shear")
  7. End With
  8. End Sub
Update the “draw_text” sub procedure. Add another condition which is “Shear”. The function of this condition is when the value of a ComboBox is changed, the effect of the text will be changed too.
  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.  
  11. nupDepth.Enabled = False
  12. nudShear.Enabled = False
  13. Case "Block"
  14.  
  15. draw_block_text()
  16. nupDepth.Enabled = True
  17. nudShear.Enabled = False
  18. Case "Shear"
  19.  
  20. draw_shear_text()
  21. nupDepth.Enabled = False
  22. nudShear.Enabled = True
  23.  
  24. End Select
  25. End Sub
Add the “ nudShear.ValueChanged ” for the events of the “UIChanged” sub procedure. With this, when the value of “nudShear” is changed, the slide of the text will be changed too. And 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, nudShear.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