• We just launched and are currently in beta. Join us as we build and grow the community.

Text Effects in Visual Basic 2008.. (Reflect)

jolle23

Blockchain Validator
J Rep
0
0
0
Rep
0
J Vouches
0
0
0
Vouches
0
Posts
84
Likes
46
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 600 XP
In this tutorial I will teach you how to put an effect in the text using Visual Basic 2008. In here, I use the reflected text for the effect. It reflects any kind of text that you will type at the bottom and you can also change its font size. Others may think that reflected text is just easy to do. But, they were wrong. You have to take a closer look at each codes and calculate everything to make it accurate.

Let’s begin:

Open Visual Basic 2008, create a new Windows Application and drag a PictureBox, a TextBox, a ComboBox and a NumericUpDown. It will look like this.

first_form_1.png


Double click the Form, go to the solution explorer and click the view code. After that, create a sub procedure for the reflect effects.

  1. Private

    Sub

    DrawReflectText(

    )
  2. Dim

    text_size As

    SizeF
  3. Dim

    grafx As

    Graphics
  4. Dim

    back_brush As

    Brush =

    Brushes.

    Gray
  5. Dim

    fore_brush As

    Brush =

    Brushes.

    Black
  6. Dim

    Fnt As

    New

    Font(

    "Microsoft Sans Serif"

    , NumericUpDown1.

    Value

    , FontStyle.

    Regular

    )
  7. Dim

    my_state As

    GraphicsState 'STORE THE CURRENT STATE OF GRAPHICS
  8. Dim

    x_location, y_location As

    Single

    'USED FOR THE LOCATION
  9. Dim

    text_height As

    Single

  10. 'CREATE A GRAPHIC OBJECT IN THE PICTURE BOX
  11. grafx =

    PictureBox1.

    CreateGraphics

    (

    )
  12. 'CLEAR THE GRAPHIC OBJECT
  13. grafx.

    Clear

    (

    Color.

    White

    )

  14. 'SIZE IS REQUIRED TO DRAW THE TEXT
  15. text_size =

    grafx.

    MeasureString

    (

    TextBox1.

    Text

    , Fnt)

  16. 'ELIMINATE THE REDUNDANT CALCULATIONS AFTER THE LOCATIONS' ONCE GET
  17. x_location =

    (

    PictureBox1.

    Width

    -

    text_size.

    Width

    )

    /

    2
  18. y_location =

    (

    PictureBox1.

    Height

    -

    text_size.

    Height

    )

    /

    2

  19. 'IN SCALING THE ENTIRE GRAPHIC OBJECTS, WE NEED TO REPOSITION THE ORIGIN OF
  20. 'IT (0,0) TO THE (xLocation, yLocation) POINT.
  21. 'IF NOT, WHEN YOU FLIP THE TEXT WITH A SCALING TRANSFORM,
  22. 'IT WILL DRAW REFLECTED TEXT AT (xLocation, -yLocation)THAT IS OUTSITDE THE VIEWABLE AREA
  23. grafx.

    TranslateTransform

    (

    x_location, y_location)

  24. Dim

    line_ascent As

    Integer
  25. Dim

    line_spacing As

    Integer
  26. Dim

    line_height As

    Single

  27. 'USE GETCELLASCENT TO CALCULATE THE HIEGHT ABOVE THE BASELINE.
  28. 'SINCE IT RETURNS A DESIGN METRIC VALUE YOU HAVE TO CONVERT IT
  29. 'INTO PIXELS AND SCALED FOR THE FONT SIZE.
  30. line_ascent =

    Fnt.

    FontFamily

    .

    GetCellAscent

    (

    Fnt.

    Style

    )
  31. line_spacing =

    Fnt.

    FontFamily

    .

    GetLineSpacing

    (

    Fnt.

    Style

    )
  32. line_height =

    Fnt.

    GetHeight

    (

    grafx)
  33. text_height =

    line_height *

    line_ascent /

    line_spacing

  34. 'THIS REFLECTS OVER THE LOWEST PORTION OF THE TEXT.
  35. Dim

    line_descent As

    Integer

    'REFLECT TO THE DESCENDING CHARACTERS
  36. line_descent =

    Fnt.

    FontFamily

    .

    GetCellDescent

    (

    Fnt.

    Style

    )
  37. text_height =

    line_height *

    (

    line_ascent +

    line_descent)

    /

    line_spacing


  38. 'DRAW THE REFLECTED ONE FIRST TO DEMONSTRATE THE USE OF GRAPHICS STATE OBJECT.
  39. 'A GRAPHICSSTATE OBJECT MAINTAINS THE GRAPHICS OBJECT.

  40. 'GRAPHICSSTATE SAVE FIRST.
  41. my_state =

    grafx.

    Save

    (

    )

    S

  42. 'USE THE SCALETRANSFORM WITH A NEGATIVE VALUE TO DRAW THE REFLECTIION
  43. 'AND USING -1 THE REFLECTED TEXT WILL NOT DISTORT.
  44. grafx.

    ScaleTransform

    (

    1

    , -

    1.

    0F)

    ' REFLECTING THE Y DIRECTION
  45. grafx.

    DrawString

    (

    TextBox1.

    Text

    , Fnt, back_brush, 0

    , -

    text_height)

  46. 'BEFORE IT TRANFORM RESET THE GRAPHICS STATE
  47. grafx.

    Restore

    (

    my_state)

  48. 'MAIN TEXT DRAWN.
  49. grafx.

    DrawString

    (

    TextBox1.

    Text

    , Fnt, fore_brush, 0

    , -

    text_height)

  50. End

    Sub

Then, create a sub procedure for the name of the effect. Clear and add the item in the ComboBox.

  1. Private

    Sub

    effectlist(

    )
  2. With

    ComboBox1.

    Items
  3. .

    Clear

    (

    )
  4. .

    Add

    (

    "Reflect"

    )
  5. End

    With
  6. End

    Sub

Then, create a sub procedure to draw the text.

  1. Private

    Sub

    draw_text(

    )
  2. effectlist(

    )
  3. If

    ComboBox1.

    SelectedItem

    Is

    Nothing

    Then
  4. ComboBox1.

    SelectedIndex

    =

    0
  5. End

    If
  6. Select

    Case

    ComboBox1.

    SelectedItem

    .

    ToString

    (

    )
  7. Case

    "Reflect"
  8. Draw_Reflect_Text(

    )
  9. End

    Select
  10. End

    Sub

Lastly, create a sub procedure for the UIchange.

  1. Private

    Sub

    UIChanged(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    _
  2. Handles

    TextBox1.

    TextChanged

    , NumericUpDown1.

    ValueChanged

    , PictureBox1.

    MouseHover
  3. If

    NumericUpDown1.

    Value

    =

    0

    Then
  4. NumericUpDown1.

    Value

    =

    50
  5. End

    If
  6. draw_text(

    )
  7. End

    Sub

Ouput:

output_20.png



Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,496

331,932

331,940

Top