How to Apply Shear Effects to a Text in VB.Net
This tutorial is all about How to Apply Shear Effects to a Text in VB.Net.
This is the continuation of my last topic which is “How to Apply “Block Effects” to a Text in VB.Net“. 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.
What is Visual Basic’s purpose?
The third-generation programming language was created to aid developers in the creation of Windows applications. It has a programming environment that allows programmers to write code in.exe or executable files. They can also utilize it to create in-house front-end solutions for interacting with huge databases. Because the language allows for continuing changes, you can keep coding and revising your work as needed.
However, there are some limits to the Microsoft Visual Basic download. If you want to make applications that take a long time to process, this software isn’t for you. That implies you won’t be able to use VB to create games or large apps because the system’s graphic interface requires a lot of memory and space. Furthermore, the language is limited to Microsoft and does not support other operating systems.
What are the most important characteristics of Visual Basic?
Microsoft Visual Basic for Applications Download, unlike other programming languages, allows for speedier app creation. It has string processing capabilities and is compatible with C++, MFC, and F#. Multi-targeting and the Windows Presentation Framework are also supported by the system, allowing developers to create a variety of Windows apps, desktop tools, metro-style programs, and hardware drivers.
Let’s begin:
First, open the file of “How to Apply “Shear Effects” to a Text in VB.Net”. 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.
[vbnet]
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
[/vbnet]
Update the “effectlist” sub procedure. Add the item in the ComboBox which is “Shear”.
[vbnet]
Private Sub effectlist()
With ComboBox1.Items
.Clear()
.Add(“Reflect”)
.Add(“Block”)
.Add(“Shear”)
End With
End Sub
[/vbnet]
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.
[vbnet]
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
[/vbnet]
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.
[vbnet]
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
[/vbnet]
Output:
Download the complete sourcecode here
Readers might read also: