Click here to Skip to main content
15,886,689 members
Articles / Programming Languages / C#

Simple Ping Utility with GUI

Rate me:
Please Sign up or sign in to vote.
4.89/5 (80 votes)
3 Feb 2012CPOL10 min read 305.3K   28K   226  
Using the Ping class in .NET Framework
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using NetUtils;

namespace NetPinger
{
	public partial class GraphForm : Form
	{

		private Dictionary<HostPinger, HostDataSeries>.ValueCollection _series = null;

		public Dictionary<HostPinger, HostDataSeries>.ValueCollection Series
		{
			get { return _series; }
			set { _series = value; }
		}

		private GraphManager _graphManager;

		public GraphForm(GraphManager graphManager)
		{
			_graphManager = graphManager;

			InitializeComponent();

			if (_graphManager.IsError)
			{
				_cbGraph.Text = "An error occured while opening settings file!";
				_btnLoad.Enabled = _btnSave.Enabled = _btnRemove.Enabled = _cbGraph.Enabled = false;
			}
			else
			{
				foreach (string g in _graphManager.Graphs)
					_cbGraph.Items.Add(g);

				_graphManager.OnGraphCollectionUpdate += new GraphManager.GraphCollectionUpdate(_graphManager_OnGraphCollectionUpdate);
			}
		}

		void _graphManager_OnGraphCollectionUpdate()
		{
			_cbGraph.Items.Clear();

			foreach (string g in _graphManager.Graphs)
				_cbGraph.Items.Add(g);
		}

		private void _gcGraphs_OnAddView(LiveGraph.GraphControl control, LiveGraph.Graph graph)
		{
			AddDataSeriesForm dlg = new AddDataSeriesForm();
			dlg.Series = _series;

			if (dlg.ShowDialog(this) == DialogResult.OK)
				graph.AddView(dlg.SelectedSeries, dlg.Color);
		}

		private void _btnLoad_Click(object sender, EventArgs e)
		{
			_graphManager.LoadGraphCollection(_cbGraph.Text, _gcGraphs);
		}

		private void _btnSave_Click(object sender, EventArgs e)
		{
			_graphManager.AddGraphCollection(_cbGraph.Text, _gcGraphs);
		}

		private void _btnRemove_Click(object sender, EventArgs e)
		{
			_graphManager.RemoveGraphCollection(_cbGraph.Text);
		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Serbia Serbia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions