0% found this document useful (0 votes)
53 views8 pages

Assignment VBDOTNET

This VB.NET code sample demonstrates how to programmatically access and modify performance counters. It populates dropdowns with available counter categories and counters. When a counter is selected, it displays metadata and refreshes the value every 500 milliseconds. Buttons allow incrementing/decrementing custom counters. Built-in counters are read-only.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views8 pages

Assignment VBDOTNET

This VB.NET code sample demonstrates how to programmatically access and modify performance counters. It populates dropdowns with available counter categories and counters. When a counter is selected, it displays metadata and refreshes the value every 500 milliseconds. Buttons allow incrementing/decrementing custom counters. Built-in counters are read-only.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

RICHTEXT BOX

CODE:
Public Class Form1
Private Sub btnBoldAndItalic_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnBoldAndItalic.Click
rtxtBoldAndItalic.SelectionStart = rtxtBoldAndItalic.Find("will")
Dim ifont As New Font(rtxtBoldAndItalic.Font, FontStyle.Italic)
rtxtBoldAndItalic.SelectionFont = ifont
rtxtBoldAndItalic.SelectionStart = rtxtBoldAndItalic.Find("way")
Dim bfont As New Font(rtxtBoldAndItalic.Font, FontStyle.Bold)
rtxtBoldAndItalic.SelectionFont = bfont
End Sub

Private Sub btnFontColor_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnFontColor.Click
rtxtFontColor.Text = rtxtBoldAndItalic.Text
rtxtFontColor.SelectionStart = rtxtFontColor.Find("will")
rtxtFontColor.SelectionColor = Color.Blue
rtxtFontColor.SelectionStart = rtxtFontColor.Find("way")
rtxtFontColor.SelectionColor = Color.BurlyWood
End Sub
End Class

FORM DESIGN:

1|Page
OUTPUT:

2|Page
DESCRIPTION:
RichTextBoxes are similar to textboxes but they provide some advanced features over the standard
toolbox. RichTextBox allows formatting the text, say adding colors, displaying particular font types and
so on. The RichTextBox, like the TextBox is based on the TextBoxBase class which is based on
the Control class.

To set colors in a rich text box, you can make a selection using the property SelectionStart and
set the rich text box's SelectionColor property. One way to set colors in VB .NET is with the Colors
enumeration, using colors such as Colors.Red, Colors.Green, and so on. The particular word can be
selected using the find () method.

Enter some text in the RichTextBox and the click event of btnBoldAndItalic. The
following code will search for text we mentioned in code and sets it to be display as Bold or Italic based
on what text is searched for. Similarly when the btnFontColor event is clicked, code will search
for text we mentioned in code and sets it to be display in Font floor based on what text is searched for.

3|Page
PERFORMANCE COUNTER

Private counter As PerformanceCounter

Private Sub btnDecrementCounter_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnDecrementCounter.Click

Try
counter.ReadOnly = False

If counter.RawValue > 0 Then


counter.Decrement()
ToolStripStatusLabel1.Text = ""
Else
ToolStripStatusLabel1.Text = "Counter is already zero."
End If
Catch exc As Exception
ToolStripStatusLabel1.Text = "Could not decrement counter."
End Try

End Sub

Private Sub btnIncrementCounter_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnIncrementCounter.Click

Try
counter.ReadOnly = False
counter.Increment()
ToolStripStatusLabel1.Text = ""
Catch
ToolStripStatusLabel1.Text = "Could not increment counter."
End Try
End Sub

Private Sub btnRefreshCategories_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnRefreshCategories.Click
Me.cboCategories.Items.Clear()
Me.cboCounters.Items.Clear()
Me.counter = Nothing
Me.txtBuiltInOrCustom.Text = ""
Me.txtCounterHelp.Text = ""
Me.txtCounterType.Text = ""
Me.txtCounterValue.Text = ""
Me.btnDecrementCounter.Enabled = False
Me.btnIncrementCounter.Enabled = False
Me.cboCategories.Text = ""
Me.cboCounters.Text = ""
Me.Form1_Load(Me, New System.EventArgs())
End Sub

Private Sub cboCategories_SelectedIndexChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles cboCategories.SelectedIndexChanged

Dim category As PerformanceCounterCategory


Dim counters As New ArrayList()
Dim thisCounter As PerformanceCounter
Dim counterNames() As String

If cboCategories.SelectedIndex <> -1 Then


Try

category = New PerformanceCounterCategory( _


Me.cboCategories.SelectedItem.ToString())
4|Page
counterNames = category.GetInstanceNames()

If counterNames.Length = 0 Then
counters.AddRange(category.GetCounters())
Else
Dim i As Integer
For i = 0 To counterNames.Length - 1
counters.AddRange( _
category.GetCounters(counterNames(i)))
Next
End If

Me.cboCounters.Items.Clear()
Me.cboCounters.Text = ""
For Each thisCounter In counters
Me.cboCounters.Items.Add(New CounterDisplayItem(thisCounter))
Next

Catch exc As Exception

MsgBox("Unable to list the Counters in this Category." + _


"Please select another Category.")
End Try

End If
End Sub

Private Sub cboCounters_SelectedIndexChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles cboCounters.SelectedIndexChanged

Dim displayItem As CounterDisplayItem


Try
displayItem = CType(cboCounters.SelectedItem, CounterDisplayItem)
counter = displayItem.Counter
Me.txtCounterType.Text = counter.CounterType.ToString()
Me.txtCounterHelp.Text = counter.CounterHelp.ToString()
ToolStripStatusLabel1.Text = ""

If displayItem.IsCustom Then
Me.txtBuiltInOrCustom.Text = "Custom"
Me.btnDecrementCounter.Enabled = True
Me.btnIncrementCounter.Enabled = True
Else
Me.txtBuiltInOrCustom.Text = "Built-In"
Me.btnDecrementCounter.Enabled = False
Me.btnIncrementCounter.Enabled = False
End If

Catch exc As Exception


counter = Nothing
End Try
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load

Dim category As PerformanceCounterCategory


Dim categories() As PerformanceCounterCategory
categories = PerformanceCounterCategory.GetCategories()

Dim categoryNames(categories.Length - 1) As String


Dim i As Integer = 0 ' Used as a counter

For Each category In categories


5|Page
categoryNames(i) = category.CategoryName
i += 1
Next
Array.Sort(categoryNames)

Dim nameString As String


For Each nameString In categoryNames
Me.cboCategories.Items.Add(nameString)
Next

Me.tmrUpdateUI.Interval = 500
Me.tmrUpdateUI.Enabled = True
End Sub
Private Sub tmrUpdateUI_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmrUpdateUI.Tick
Try
If Not counter Is Nothing Then
Me.txtCounterValue.Text = counter.NextValue().ToString()
End If
Catch exc As Exception
Me.txtCounterValue.Text = ""
End Try

End Sub

End Class

FORM DESIGN

6|Page
OUTPUT SCREEN

Initiate the performance counter with your Manually Created Performance counter

After refreshing it and choosing the Processor Category

7|Page
DESCRIPTION:
Performance Counters are Windows OS objects that capture metrics about the performance of
hardware and applications. For example, performance counters can capture performance metrics for
processors, memory, threads, events, and processes. Metrics can be used to detect problems or to
“tune” applications and hardware for maximum performance.

Performance Counter objects may be accessed programmatically or with the Windows Performance
Monitor Application (PerfMon).
 
 Listing categories   Performance counter categories are retrieved using the GetCategories
method and displayed in a ComboBox control.

 Listing counters   Performance counters are retrieved using the GetCounters method and
displayed in a ComboBox control. Only the counters from the selected category are retrieved.

 Retrieving data   The NextValue method is used to retrieve the current value of the selected
counter.

 Custom counters   The application only allows you to increment custom counters. A custom
counter is defined as a counter where you cannot call the NextValue method.

8|Page

You might also like