Text Effects in Visual Basic 2008 (Shear)
Submitted by janobe on Tuesday, May 6, 2014 - 17:43.
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.
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.
Update the “effectlist” sub procedure. Add the item in the ComboBox which is “Shear”.
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.
Add the “
Output:
- Private Sub draw_shear_text()
- Dim text_size As SizeF
- Dim grafx As Graphics
- Dim fore_brush As Brush = Brushes.Blue
- Dim fnt As New Font("Microsoft Sans Serif", NumericUpDown1.Value, FontStyle.Regular)
- Dim tranform As Matrix
- Dim location_x, location_y As Single
- 'CREATE THE GRAPHICS OBJECT IN THE PICTUREBOX.
- grafx = PictureBox1.CreateGraphics()
- 'CLEAR THE GRAPHICS OBJECT
- grafx.Clear(Color.White)
- 'SET THE REQUIRE SIZE TO DRAW THE TEXT.
- text_Size = grafx.MeasureString(TextBox1.Text, fnt)
- 'ELIMINATE THE REDUNDANT CALCULATION AFTER GETTING THE LOCATION.
- location_x = (PictureBox1.Width - text_size.Width) / 2
- location_y = (PictureBox1.Height - text_size.Height) / 2
- 'REPOSITION THE ORIGIN OF THE GRAPHICS OBJECT (0,0) TO THE (location_x,
- ' location_y) POINT.
- grafx.TranslateTransform(location_x, location_y)
- 'SPECIFY THE AMOUNT TO TRANSFORM THE CURRENT GRAPHICS OBJECT TO A SHEAR TEXT.
- tranform = grafx.Transform
- tranform.Shear(nudShear.Value, 0)
- grafx.Transform = tranform
- 'MAIN TEXT DRAWN.
- grafx.DrawString(TextBox1.Text, fnt, fore_brush, 0, 0)
- End Sub
- Private Sub effectlist()
- With ComboBox1.Items
- .Clear()
- .Add("Reflect")
- .Add("Block")
- .Add("Shear")
- End With
- End Sub
- Private Sub draw_text()
- If ComboBox1.SelectedItem Is Nothing Then
- effectlist()
- ComboBox1.SelectedIndex = 0
- End If
- Select Case ComboBox1.SelectedItem.ToString()
- Case "Reflect"
- Draw_Reflect_Text()
- nupDepth.Enabled = False
- nudShear.Enabled = False
- Case "Block"
- draw_block_text()
- nupDepth.Enabled = True
- nudShear.Enabled = False
- Case "Shear"
- draw_shear_text()
- nupDepth.Enabled = False
- nudShear.Enabled = True
- End Select
- End Sub
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.
- Private Sub UIChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
- Handles TextBox1.TextChanged, NumericUpDown1.ValueChanged, PictureBox1.MouseHover, _
- ComboBox1.SelectedValueChanged, nupDepth.ValueChanged, nudShear.ValueChanged
- If NumericUpDown1.Value = 0 Then
- NumericUpDown1.Value = 50
- End If
- draw_text()
- End Sub
Add new comment
- 57 views