VB. NET implements various special effects of Text

Source: Internet
Author: User

(1) create a project named "drawfont", add four buttons to the Form Designer, and set the properties of the form and controls as follows:
Form1 text attribute: Text effect backgroupimage attribute: C: \ WINDOWS \ WEB \ wallpaper \ bliss.jpg
Name attribute of button1: btnsd text attribute: 3D text
Name attribute of button1: btnyy text attribute: Shadow text
Name attribute of button1: btnjb text attribute: gradient text
Name attribute of button1: btnta text attribute: Pattern text
Run the following command:

(2) Add the corresponding code for the control. The complete code is as follows:

Imports system. Drawing
Imports system. Drawing. drawing2d

Public class form1
Inherits system. Windows. Forms. Form
Private flag as integer

Private sub form1_paint (byval sender as system. Object, byval e as system. Windows. Forms. painteventargs) handles mybase. Paint
Dim fnttext = new font ("", 40)
Dim G as graphics = E. Graphics
Dim BRB, BRF as brush
Dim BM as image = image. fromfile ("D: \ windows \ WEB \ wallpaper \ mongojpg ")
Dim I as integer
Dim p1, p2 as point
P1.x = 20
P1.y = 20
P2.x= 200
P2.y = 20
Select case flag
Case 1
BRB = new solidbrush (color. fromargb (100, color. Black ))
BRF = new solidbrush (color. Red)
For I = 1 to 10
G. drawstring ("Visual Basic. Net", fnttext, BRB, p1.x + I, p1.y + I)
G. drawstring ("Program Design", fnttext, BRB, p1.x + 150 + I, p1.y + 50 + I)
Next
G. drawstring ("Visual Basic. Net", fnttext, BRB, p1.x, p1.y)
G. drawstring ("Program Design", fnttext, BRB, p1.x + 150, p1.y + 50)
Case 2
BRB = new solidbrush (color. fromargb (120, color. Black ))
BRF = new solidbrush (color. Red)
G. drawstring ("Visual Basic. Net", fnttext, BRB, p1.x + 5, p1.y + 5)
G. drawstring ("Program Design", fnttext, BRB, p1.x + 150 + 5, p1.y + 50 + 5)
G. drawstring ("Visual Basic. Net", fnttext, BRB, p1.x, p1.y)
G. drawstring ("Program Design", fnttext, BRB, p1.x + 150, p1.y + 50)
Case 3
BRF = new lineargradientbrush (P1, P2, color. Red, color. Yellow)
G. drawstring ("Visual Basic. Net", fnttext, BRF, p1.x, p1.y)
G. drawstring ("Program Design", fnttext, BRF, p1.x + 150, p1.y + 50)
Case 4
BRF = new texturebrush (BM)
G. drawstring ("Visual Basic. Net", fnttext, BRF, p1.x, p1.y)
G. drawstring ("Program Design", fnttext, BRF, p1.x + 150, p1.y + 50)
End select
End sub

Private sub btnsd_click (byval sender as system. Object, byval e as system. eventargs) handles btnsd. Click
Flag = 1
Me. invalidate ()
End sub

Private sub btnyy_click (byval sender as system. Object, byval e as system. eventargs) handles btnyy. Click
Flag = 2
Me. invalidate ()

End sub

Private sub btnjb_click (byval sender as system. Object, byval e as system. eventargs) handles btnjb. Click
Flag = 3
Me. invalidate ()

End sub

Private sub btnta_click (byval sender as system. Object, byval e as system. eventargs) handles btnta. Click
Flag = 4
Me. invalidate ()

End sub
End Class

(3) procedures:
Two namespaces are used at the beginning of the program, so two lines of code are added:
Imports system. Drawing
Imports system. Drawing. drawing2d
The second is to add a painting event to the form. The 3D, shadow, gradient, and pattern effects of the text are all implemented in the form painting event. The so-called form painting event, it is simply a drawing event.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.