Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| ' <snippet100> | |
| ' <snippet101> | |
| Imports System | |
| Imports System.Collections.Generic | |
| Imports System.ComponentModel | |
| Imports System.Diagnostics | |
| Imports System.Drawing | |
| Imports System.Windows.Forms | |
| Imports AttributesDemoControlLibrary | |
| ' </snippet101> | |
| ' This sample demonstrates using the AttributesDemoControl to log | |
| ' data from a data source. | |
| Public Class Form1 | |
| Inherits Form | |
| Private bindingSource1 As BindingSource | |
| Private performanceCounter1 As System.Diagnostics.PerformanceCounter | |
| Private WithEvents startButton As Button | |
| Private WithEvents stopButton As Button | |
| Private WithEvents timer1 As System.Timers.Timer | |
| Private statusStrip1 As ToolStripStatusLabel | |
| Private statusStripPanel1 As ToolStripStatusLabel | |
| Private WithEvents numericUpDown1 As NumericUpDown | |
| Private groupBox1 As GroupBox | |
| Private groupBox2 As GroupBox | |
| Private tableLayoutPanel1 As TableLayoutPanel | |
| Private WithEvents attributesDemoControl1 As AttributesDemoControl | |
| Private components As System.ComponentModel.IContainer = Nothing | |
| ' This form uses an AttributesDemoControl to display a stream | |
| ' of LogEntry objects. The data stream is generated by polling | |
| ' a performance counter and communicating the counter values | |
| ' to the control with data binding. | |
| Public Sub New() | |
| InitializeComponent() | |
| ' Set the initial value of the threshold up/down control | |
| ' to the control's threshold value. | |
| Me.numericUpDown1.Value = _ | |
| System.Convert.ToDecimal( _ | |
| System.Convert.ToSingle(Me.attributesDemoControl1.Threshold)) | |
| ' Assign the performance counter's name to the control's | |
| ' title text. | |
| Me.attributesDemoControl1.TitleText = _ | |
| Me.performanceCounter1.CounterName | |
| End Sub | |
| ' This method handles the ThresholdExceeded event. It posts | |
| ' a the value that exceeded the threshold to the status strip. | |
| Private Sub attributesDemoControl1_ThresholdExceeded( _ | |
| ByVal e As ThresholdExceededEventArgs) _ | |
| Handles attributesDemoControl1.ThresholdExceeded | |
| Dim msg As String = String.Format( _ | |
| "{0}: Value {1} exceeded threshold {2}", _ | |
| Me.attributesDemoControl1.CurrentLogTime, _ | |
| e.ExceedingValue, _ | |
| e.ThresholdValue) | |
| Me.ReportStatus(msg) | |
| End Sub | |
| ' <snippet110> | |
| ' This method handles the timer's Elapsed event. It queries | |
| ' the performance counter for the next value, packs the | |
| ' value in a LogEntry object, and adds the new LogEntry to | |
| ' the list managed by the BindingSource. | |
| Private Sub timer1_Elapsed( _ | |
| ByVal sender As Object, _ | |
| ByVal e As System.Timers.ElapsedEventArgs) _ | |
| Handles timer1.Elapsed | |
| ' Get the latest value from the performance counter. | |
| Dim val As Single = Me.performanceCounter1.NextValue() | |
| ' The performance counter returns values of type float, | |
| ' but any type that implements the IComparable interface | |
| ' will work. | |
| Dim entry As LogEntry(Of Single) = _ | |
| New LogEntry(Of Single)(val, DateTime.Now) | |
| ' Add the new LogEntry to the BindingSource list. | |
| Me.bindingSource1.Add(entry) | |
| End Sub | |
| ' </snippet110> | |
| Private Sub numericUpDown1_ValueChanged( _ | |
| ByVal sender As Object, _ | |
| ByVal e As EventArgs) _ | |
| Handles numericUpDown1.ValueChanged | |
| Me.attributesDemoControl1.Threshold = _ | |
| System.Convert.ToSingle(Me.numericUpDown1.Value) | |
| Dim msg As String = String.Format( _ | |
| "Threshold changed to {0}", _ | |
| Me.attributesDemoControl1.Threshold) | |
| Me.ReportStatus(msg) | |
| End Sub | |
| Private Sub startButton_Click( _ | |
| ByVal sender As Object, _ | |
| ByVal e As EventArgs) _ | |
| Handles startButton.Click | |
| Me.ReportStatus((DateTime.Now.ToString() + ": Starting")) | |
| Me.timer1.Start() | |
| End Sub | |
| Private Sub stopButton_Click( _ | |
| ByVal sender As Object, _ | |
| ByVal e As EventArgs) _ | |
| Handles stopButton.Click | |
| Me.ReportStatus((DateTime.Now.ToString() + ": Stopping")) | |
| Me.timer1.Stop() | |
| End Sub | |
| Private Sub ReportStatus(msg As String) | |
| If (msg IsNot Nothing) Then | |
| Me.statusStripPanel1.Text = msg | |
| End If | |
| End Sub | |
| <STAThread()> _ | |
| Shared Sub Main() | |
| Application.EnableVisualStyles() | |
| Application.Run(New Form1()) | |
| End Sub | |
| Protected Overrides Sub Dispose(disposing As Boolean) | |
| If disposing AndAlso (components IsNot Nothing) Then | |
| components.Dispose() | |
| End If | |
| MyBase.Dispose(disposing) | |
| End Sub | |
| Private Sub InitializeComponent() | |
| Me.components = New System.ComponentModel.Container() | |
| Me.bindingSource1 = New System.Windows.Forms.BindingSource(Me.components) | |
| Me.performanceCounter1 = New System.Diagnostics.PerformanceCounter() | |
| Me.startButton = New System.Windows.Forms.Button() | |
| Me.stopButton = New System.Windows.Forms.Button() | |
| Me.timer1 = New System.Timers.Timer() | |
| Me.statusStripPanel1 = New System.Windows.Forms.ToolStripStatusLabel() | |
| Me.numericUpDown1 = New System.Windows.Forms.NumericUpDown() | |
| Me.groupBox1 = New System.Windows.Forms.GroupBox() | |
| Me.groupBox2 = New System.Windows.Forms.GroupBox() | |
| Me.tableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel() | |
| Me.attributesDemoControl1 = New AttributesDemoControlLibrary.AttributesDemoControl() | |
| CType(Me.bindingSource1, System.ComponentModel.ISupportInitialize).BeginInit() | |
| CType(Me.performanceCounter1, System.ComponentModel.ISupportInitialize).BeginInit() | |
| CType(Me.timer1, System.ComponentModel.ISupportInitialize).BeginInit() | |
| CType(Me.numericUpDown1, System.ComponentModel.ISupportInitialize).BeginInit() | |
| Me.groupBox1.SuspendLayout() | |
| Me.groupBox2.SuspendLayout() | |
| Me.tableLayoutPanel1.SuspendLayout() | |
| Me.SuspendLayout() | |
| ' | |
| ' performanceCounter1 | |
| ' | |
| Me.performanceCounter1.CategoryName = ".NET CLR Memory" | |
| Me.performanceCounter1.CounterName = "Gen 0 heap size" | |
| Me.performanceCounter1.InstanceName = "_Global_" | |
| ' | |
| ' startButton | |
| ' | |
| Me.startButton.Location = New System.Drawing.Point(31, 25) | |
| Me.startButton.Name = "startButton" | |
| Me.startButton.TabIndex = 1 | |
| Me.startButton.Text = "Start" | |
| ' | |
| ' stopButton | |
| ' | |
| Me.stopButton.Location = New System.Drawing.Point(112, 25) | |
| Me.stopButton.Name = "stopButton" | |
| Me.stopButton.TabIndex = 2 | |
| Me.stopButton.Text = "Stop" | |
| ' | |
| ' timer1 | |
| ' | |
| Me.timer1.Interval = 1000 | |
| Me.timer1.SynchronizingObject = Me | |
| ' | |
| ' statusStripPanel1 | |
| ' | |
| Me.statusStripPanel1.BorderStyle = System.Windows.Forms.Border3DStyle.SunkenOuter | |
| Me.statusStripPanel1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text | |
| Me.statusStripPanel1.Name = "statusStripPanel1" | |
| Me.statusStripPanel1.Text = "Ready" | |
| ' | |
| ' numericUpDown1 | |
| ' | |
| Me.numericUpDown1.Location = New System.Drawing.Point(37, 29) | |
| Me.numericUpDown1.Maximum = New Decimal(New Integer() {1410065408, 2, 0, 0}) | |
| Me.numericUpDown1.Name = "numericUpDown1" | |
| Me.numericUpDown1.TabIndex = 7 | |
| ' | |
| ' groupBox1 | |
| ' | |
| Me.groupBox1.Anchor = System.Windows.Forms.AnchorStyles.None | |
| Me.groupBox1.Controls.Add(Me.numericUpDown1) | |
| Me.groupBox1.Location = New System.Drawing.Point(280, 326) | |
| Me.groupBox1.Name = "groupBox1" | |
| Me.groupBox1.Size = New System.Drawing.Size(200, 70) | |
| Me.groupBox1.TabIndex = 13 | |
| Me.groupBox1.TabStop = False | |
| Me.groupBox1.Text = "Threshold Value" | |
| ' | |
| ' groupBox2 | |
| ' | |
| Me.groupBox2.Anchor = System.Windows.Forms.AnchorStyles.None | |
| Me.groupBox2.Controls.Add(Me.startButton) | |
| Me.groupBox2.Controls.Add(Me.stopButton) | |
| Me.groupBox2.Location = New System.Drawing.Point(26, 327) | |
| Me.groupBox2.Name = "groupBox2" | |
| Me.groupBox2.Size = New System.Drawing.Size(214, 68) | |
| Me.groupBox2.TabIndex = 14 | |
| Me.groupBox2.TabStop = False | |
| Me.groupBox2.Text = "Logging" | |
| ' | |
| ' tableLayoutPanel1 | |
| ' | |
| Me.tableLayoutPanel1.ColumnCount = 2 | |
| Me.tableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)) | |
| Me.tableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)) | |
| Me.tableLayoutPanel1.Controls.Add(Me.groupBox2, 0, 1) | |
| Me.tableLayoutPanel1.Controls.Add(Me.groupBox1, 1, 1) | |
| Me.tableLayoutPanel1.Controls.Add(Me.attributesDemoControl1, 0, 0) | |
| Me.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill | |
| Me.tableLayoutPanel1.Location = New System.Drawing.Point(0, 0) | |
| Me.tableLayoutPanel1.Name = "tableLayoutPanel1" | |
| Me.tableLayoutPanel1.Padding = New System.Windows.Forms.Padding(10) | |
| Me.tableLayoutPanel1.RowCount = 2 | |
| Me.tableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 80F)) | |
| Me.tableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F)) | |
| Me.tableLayoutPanel1.Size = New System.Drawing.Size(514, 411) | |
| Me.tableLayoutPanel1.TabIndex = 15 | |
| ' | |
| ' attributesDemoControl1 | |
| ' | |
| Me.tableLayoutPanel1.SetColumnSpan(Me.attributesDemoControl1, 2) | |
| Me.attributesDemoControl1.DataMember = "" | |
| Me.attributesDemoControl1.DataSource = Me.bindingSource1 | |
| Me.attributesDemoControl1.Dock = System.Windows.Forms.DockStyle.Fill | |
| Me.attributesDemoControl1.Location = New System.Drawing.Point(13, 13) | |
| Me.attributesDemoControl1.Name = "attributesDemoControl1" | |
| Me.attributesDemoControl1.Padding = New System.Windows.Forms.Padding(10) | |
| Me.attributesDemoControl1.Size = New System.Drawing.Size(488, 306) | |
| Me.attributesDemoControl1.TabIndex = 0 | |
| Me.attributesDemoControl1.Threshold = 200000F | |
| Me.attributesDemoControl1.TitleText = "TITLE" | |
| ' | |
| ' Form1 | |
| ' | |
| Me.BackColor = System.Drawing.SystemColors.Control | |
| Me.ClientSize = New System.Drawing.Size(514, 430) | |
| Me.Controls.Add(tableLayoutPanel1) | |
| Me.Name = "Form1" | |
| Me.Text = "Form1" | |
| CType(Me.bindingSource1, System.ComponentModel.ISupportInitialize).EndInit() | |
| CType(Me.performanceCounter1, System.ComponentModel.ISupportInitialize).EndInit() | |
| CType(Me.timer1, System.ComponentModel.ISupportInitialize).EndInit() | |
| CType(Me.numericUpDown1, System.ComponentModel.ISupportInitialize).EndInit() | |
| Me.groupBox1.ResumeLayout(False) | |
| Me.groupBox2.ResumeLayout(False) | |
| Me.tableLayoutPanel1.ResumeLayout(False) | |
| Me.ResumeLayout(False) | |
| Me.PerformLayout() | |
| End Sub | |
| End Class | |
| ' </snippet100> |