assignmentVBDOTNET

download assignmentVBDOTNET

of 8

Transcript of assignmentVBDOTNET

  • 8/6/2019 assignmentVBDOTNET

    1/8

    1 | P a g e

    RICHTEXT BOX

    CODE:

    Public Class Form1Private Sub btnBoldAndItalic_Click( ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles btnBoldAndItalic.ClickrtxtBoldAndItalic.SelectionStart = rtxtBoldAndItalic.Find( "will" )Dim ifont As New Font(rtxtBoldAndItalic.Font, FontStyle.Italic)rtxtBoldAndItalic.SelectionFont = ifontrtxtBoldAndItalic.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.TextrtxtFontColor.SelectionStart = rtxtFontColor.Find( "will" )rtxtFontColor .SelectionColor = Color.BluertxtFontColor .SelectionStart = rt xtFontColor.Find( "way" )rtxtFontColor .SelectionColor = Color.BurlyWood

    End SubEnd Class

    FORM DESIGN:

  • 8/6/2019 assignmentVBDOTNET

    2/8

    2 | P a g e

    OUTPUT:

  • 8/6/2019 assignmentVBDOTNET

    3/8

    3 | P a g e

    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 andso on. The RichTextBox, like the TextBox is based on the TextBoxBase class which is based onthe Control class.

    To set colors in a rich text box, you can make a selection using the property SelectionStart andset 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 beselected using the find () method.

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

  • 8/6/2019 assignmentVBDOTNET

    4/8

    4 | P a g e

    PERFORMANCE COUNTER

    Private counter As PerformanceCounter

    Private Sub btnDecrementCounter_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecrementCounter.Click

    Trycounter.ReadOnly = False

    If counter.RawValue > 0 Thencounter.Decrement()ToolStripStatusLabel1.Text = ""

    ElseToolStripStatusLabel1.Text = "Counter is already zero."

    End IfCatch 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

    Trycounter.ReadOnly = Falsecounter.Increment()ToolStripStatusLabel1.Text = ""

    CatchToolStripStatusLabel1.Text = "Could not increment counter."

    End TryEnd 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 = NothingMe.txtBuiltInOrCustom.Text = ""Me.txtCounterHelp.Text = ""Me.txtCounterType.Text = ""Me.txtCounterValue.Text = ""Me.btnDecrementCounter.Enabled = FalseMe.btnIncrementCounter.Enabled = FalseMe.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 PerformanceCounterCategoryDim counters As New ArrayList()Dim thisCounter As PerformanceCounterDim counterNames() As String

    If cboCategories.SelectedIndex -1 ThenTry

    category = New PerformanceCounterCategory( _Me.cboCategories.SelectedItem.ToString())

    counterNames = category.GetInstanceNames()

  • 8/6/2019 assignmentVBDOTNET

    5/8

    5 | P a g e

    If counterNames.Length = 0 Thencounters.AddRange(category.GetCounters())

    ElseDim i As IntegerFor i = 0 To counterNames.Length - 1

    counters.AddRange( _category.GetCounters(counterNames(i)))

    NextEnd 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 IfEnd Sub

    Private Sub cboCounters_SelectedIndexChanged( ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles cboCounters.SelectedIndexChanged

    Dim displayItem As CounterDisplayItemTry

    displayItem = CType (cboCounters.SelectedItem, Cou nterDisplayItem)counter = displayItem.Counter

    Me.txtCounterType.Text = counter.CounterType.ToString()Me.txtCounterHelp.Text = counter.CounterHelp.ToString()ToolStripStatusLabel1.Text = ""

    If displayItem.IsCustom ThenMe.txtBuiltInOrCustom.Text = "Custom"Me.btnDecrementCounter.Enabled = TrueMe.btnIncrementCounter.Enabled = True

    ElseMe.txtBuiltInOrCustom.Text = "Built-In"Me.btnDecrementCounter.Enabled = FalseMe.btnIncrementCounter.Enabled = False

    End If

    Catch exc As Exceptioncounter = Nothing

    End TryEnd Sub

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

    Dim category As PerformanceCounterCategoryDim categories() As PerformanceCounterCategorycategories = Performa nceCounterCategory.GetCategories()

    Dim categoryNames(categories.Length - 1) As StringDim i As Integer = 0 ' Used as a counter

    For Each category In categoriescategoryNames(i) = category.CategoryName

  • 8/6/2019 assignmentVBDOTNET

    6/8

    6 | P a g e

    i += 1NextArray.Sort(categoryNames)

    Dim nameString As StringFor Each nameString In categoryNames

    Me.cboCategories.Items.Add(nameString)Next

    Me.tmrUpdateUI.Interval = 500Me.tmrUpdateUI.Enabled = True

    End SubPrivate Sub tmrUpdateUI_Tick( ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles tmrUpdateUI.TickTry

    If Not counter Is Nothing ThenMe.txtCounterValue.Text = counter.NextValue().ToString()

    End IfCatch exc As Exception

    Me.txtCounterValue.Text = ""End Try

    End Sub

    End Class

    FORM DESIGN

  • 8/6/2019 assignmentVBDOTNET

    7/8

    7 | P a g e

    OUTPUT SCREEN

    Initiate the performance counter with your Manually Created Performance counter

    After refreshing it and choosing the Processor Category

  • 8/6/2019 assignmentVBDOTNET

    8/8

    8 | P a g e

    DESCRIPTION:

    P erformance Counters are Windows OS objects that capture metrics about the performance of hardware and applications. For example, performance counters can capture performance metrics forprocessors, memory, threads, events, and processes. Metrics can be used to detect problems or to

    tune applications and hardware for maximum performance.

    P erformance Counter objects may be accessed programmatically or with the Windows P erformanceMonitor Application ( P erfMon).

    y L isting categories P erformance counter categories are retrieved using the GetCategoriesmethod and displayed in a ComboBox control.

    y L isting counters P erformance counters are retrieved using the GetCounters method anddisplayed in a ComboBox control. Only the counters from the selected category are retrieved.

    y Retrieving data The NextValue method is used to retrieve the current value of the selectedcounter.

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