Quantcast
Channel: AuthorCode » Windows Controls
Viewing all articles
Browse latest Browse all 10

Change font color and style of the all label controls on the form using menu.

$
0
0

In the following example you can see that how you can change the font color and font style of all label controls using defined menu items.

 
change font and fore color of the controls  using menu
 
The example requires a menu control and label controls on the windows form. See the above picture. User can change the fore color of the all used labels from the menu options.

  1. Public Class Form1
  2.     Private Sub BlackToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BlackToolStripMenuItem.Click
  3.         For Each ctrl As Control In Me.Controls
  4.             If TypeOf (ctrl) Is Label Then
  5.                 ctrl.ForeColor = Color.Black
  6.             End If
  7.         Next
  8.     End Sub
  9.  
  10.     Private Sub BlueToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BlueToolStripMenuItem.Click
  11.         For Each ctrl As Control In Me.Controls
  12.             If TypeOf (ctrl) Is Label Then
  13.                 ctrl.ForeColor = Color.Blue
  14.             End If
  15.         Next
  16.     End Sub
  17.  
  18.     Private Sub RedToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedToolStripMenuItem.Click
  19.         For Each ctrl As Control In Me.Controls
  20.             If TypeOf (ctrl) Is Label Then
  21.                 ctrl.ForeColor = Color.Red
  22.             End If
  23.         Next
  24.     End Sub
  25.  
  26.     Private Sub BoldToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BoldToolStripMenuItem.Click
  27.         For Each ctrl As Control In Me.Controls
  28.             If TypeOf (ctrl) Is Label Then
  29.                 ctrl.Font = New Font(ctrl.Font.FontFamily, ctrl.Font.Size, ctrl.Font.Style Xor FontStyle.Bold)
  30.             End If
  31.         Next
  32.     End Sub
  33.  
  34.     Private Sub ItalicToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ItalicToolStripMenuItem.Click
  35.         For Each ctrl As Control In Me.Controls
  36.             If TypeOf (ctrl) Is Label Then
  37.                 ctrl.Font = New Font(ctrl.Font.FontFamily, ctrl.Font.Size, ctrl.Font.Style Xor FontStyle.Italic)
  38.             End If
  39.         Next
  40.     End Sub
  41.  
  42.     Private Sub RegularToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RegularToolStripMenuItem.Click
  43.         For Each ctrl As Control In Me.Controls
  44.             If TypeOf (ctrl) Is Label Then
  45.                 ctrl.Font = New Font(ctrl.Font.FontFamily, ctrl.Font.Size, ctrl.Font.Style Xor FontStyle.Regular)
  46.             End If
  47.         Next
  48.     End Sub
  49. End Class

Viewing all articles
Browse latest Browse all 10

Trending Articles