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

Text Effects in Visual Basic 2008 (Block)

TheReaper989

Multithreading Wizard
T Rep
0
0
0
Rep
0
T Vouches
0
0
0
Vouches
0
Posts
123
Likes
54
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
This is the continuation of my last tutorial which is Text Effects in Visual Basic 2008. Now, I will teach you how to “Block” Effect on the text. With this, it will create the text with an embossed look. You can adjust the Depth and even the font size of the text.

So let’s get started:

Open Visual Basic 2008 and open the file which is the Effects in Visual Basic 2008. Then, add the Label and NumericDownUp named it “nudDepth” and set the value to 10 And it will look like this.

firstform2_0.png


After that, go to the code viewer and create a sub procedure for the ” Block” effects.

  1. Private

    Sub

    draw_block_text(

    )
  2. Dim

    text_size As

    SizeF
  3. Dim

    grafx As

    Graphics
  4. Dim

    back_brush As

    Brush =

    Brushes.

    Black

    'COLOR FOR THE BOARDER TEXT
  5. Dim

    fore_brush As

    Brush =

    Brushes.

    RoyalBlue

    'COLOR FOR THE MAIN TEXT
  6. Dim

    fnt As

    New

    Font(

    "Microsoft Sans Serif"

    , NumericUpDown1.

    Value

    , FontStyle.

    Regular

    )
  7. Dim

    location_x, location_y As

    Single

    'USED IT FOR THE LOCATION
  8. Dim

    i As

    Integer

  9. 'CREATE A GRAPHIC OBJECT IN THE PICTUREBOX.
  10. grafx =

    PictureBox1.

    CreateGraphics

    (

    )
  11. 'CLEAR THE PICTUREBOX
  12. grafx.

    Clear

    (

    Color.

    White

    )

  13. 'LOOK THE REQUIRED SIZE TO DRAW THE TEXT
  14. text_size =

    grafx.

    MeasureString

    (

    Me

    .

    TextBox1

    .

    Text

    , fnt)

  15. 'ELIMINATE THE REDUNDANT CAlCULATION AFTER GETTING THE LOCATION.
  16. location_x =

    (

    PictureBox1.

    Width

    -

    text_size.

    Width

    )

    /

    2
  17. location_y =

    (

    PictureBox1.

    Height

    -

    text_size.

    Height

    )

    /

    2



  18. 'FIRST, DRAW THE BLACK BACKGROUND TO GET THE EFFECT,
  19. 'AND THE TEXT MUST BE DRAWN REAPETEDLY FROM THE OFFSET RIGHT, UP TO THE MAIN TEXT IS DRAWN.
  20. For

    i =

    CInt

    (

    nupDepth.

    Value

    )

    To

    0

    Step

    -

    1
  21. grafx.

    DrawString

    (

    TextBox1.

    Text

    , fnt, back_brush, _
  22. location_x -

    i, location_y +

    i)
  23. Next

  24. 'DRAW THE ROYAL BLUE FOR THE MAIN TEXT OVER THE BLACk TEXT
  25. grafx.

    DrawString

    (

    TextBox1.

    Text

    , fnt, fore_brush, location_x, location_y)
  26. End

    Sub

Then, in the “effectlist” sub procedure add the Block item in the Combobox. It will look like this.

  1. Private

    Sub

    effectlist(

    )
  2. With

    ComboBox1.

    Items
  3. .

    Clear

    (

    )
  4. .

    Add

    (

    "Reflect"

    )
  5. .

    Add

    (

    "Block"

    )
  6. End

    With

After that, update the code of the “draw_text” sub procedure and do this following code. The effects perform when the value of the ComboBox is changed.

  1. Private

    Sub

    draw_text(

    )
  2. If

    ComboBox1.

    SelectedItem

    Is

    Nothing

    Then
  3. effectlist(

    )
  4. ComboBox1.

    SelectedIndex

    =

    0
  5. End

    If

  6. Select

    Case

    ComboBox1.

    SelectedItem

    .

    ToString

    (

    )
  7. Case

    "Reflect"
  8. Draw_Reflect_Text(

    )
  9. nupDepth.

    Enabled

    =

    False
  10. Case

    "Block"
  11. draw_block_text(

    )
  12. nupDepth.

    Enabled

    =

    True
  13. End

    Select
  14. End

    Sub

Lastly, for the UIChange sub procedure add this "ComboBox1.SelectedValueChanged

, nupDepth.ValueChanged

” to the events handler. 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

  4. If

    NumericUpDown1.

    Value

    =

    0

    Then
  5. NumericUpDown1.

    Value

    =

    50
  6. End

    If
  7. draw_text(

    )

  8. End

    Sub

Output:

output2_0.png


 

452,292

323,341

323,350

Top