在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → C# 获取本地拨号列表并实现拨号/创建拨号功能

C# 获取本地拨号列表并实现拨号/创建拨号功能

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:0.22M
  • 下载次数:29
  • 浏览次数:381
  • 发布时间:2013-10-11
  • 实例类别:C#语言基础
  • 发 布 人:crazycode
  • 文件格式:.zip
  • 所需积分:2
 相关标签: C# 拨号 adsl

实例介绍

【实例简介】

【实例截图】

【核心代码】

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
using System.Resources;
using Ras;

namespace RasDemo
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.StatusBarPanel sbpStatus;
		private Ras.RasConnection rasConn;
		private System.Windows.Forms.ContextMenu cmMenu;
		private System.Windows.Forms.MenuItem miClear;
		private System.Windows.Forms.StatusBar sbStatus;
		private System.Windows.Forms.TabControl tabControl1;
		private System.Windows.Forms.TabPage tabPage1;
		private System.Windows.Forms.TabPage tabPage2;
		private System.Windows.Forms.Label lbDomain;
		private System.Windows.Forms.Label lbPassword;
		private System.Windows.Forms.Label lbUserName;
		private System.Windows.Forms.Label lbPhoneNumber;
		private System.Windows.Forms.Button btnHandup;
		private System.Windows.Forms.Button btnDial;
		private System.Windows.Forms.ListBox lbMsg;
		private System.Windows.Forms.TextBox txtDomain;
		private System.Windows.Forms.TextBox txtPassword;
		private System.Windows.Forms.TextBox txtUserName;
		private System.Windows.Forms.TextBox txtPhoneNumber;
		private System.Windows.Forms.ListBox lbConnections;
		private System.Windows.Forms.Button btnRefresh;
		private System.Windows.Forms.Button btnHandup2;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.Label lbCallback;
		private System.Windows.Forms.TextBox txtCallback;
		private System.Windows.Forms.NotifyIcon rasNotify;
		private System.Windows.Forms.ImageList imageList1;
		private System.Windows.Forms.Label label1;
		private ResourceManager _Res;
		private RasConnection[] _RasConns;
		private RasEntry[]	_RasEntrys;
		private bool _FlashFlag;

		private Icon IconConn,IconStat1,IconStat2,IconDisconn;
		private System.Windows.Forms.ContextMenu cmContext;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MenuItem menuItem3;
		private System.Windows.Forms.TabPage tabPage3;
		private System.Windows.Forms.ComboBox cboEntryName;
		private System.Windows.Forms.GroupBox gbEntryInfo;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label lblType;
		private System.Windows.Forms.Label lblDeviceName;
		private System.Windows.Forms.Label lblDeviceType;
		private System.Windows.Forms.Label lblCountryCode;
		private System.Windows.Forms.Label lblCountryID;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.ComboBox cboAltNumbers;
		private System.Windows.Forms.Button btnModify;
		private System.Windows.Forms.TextBox txtAeraNumber;
		private System.Windows.Forms.TextBox txtLocalPhoneNumber;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.CheckBox cbAutoMonitor;
		private Ras.RasConnectionNotify rcnNotify;
		private System.Windows.Forms.MenuItem menuItem4;

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			_Res=new ResourceManager("RasDemo.StatIcons",Assembly.GetEntryAssembly());
			IconConn=(Icon)_Res.GetObject("IconConn");
			IconStat1=(Icon)_Res.GetObject("IconStat1");
			IconStat2=(Icon)_Res.GetObject("IconStat2");
			IconDisconn=(Icon)_Res.GetObject("IconDisconn");
			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.cmMenu = new System.Windows.Forms.ContextMenu();
			this.miClear = new System.Windows.Forms.MenuItem();
			this.sbStatus = new System.Windows.Forms.StatusBar();
			this.sbpStatus = new System.Windows.Forms.StatusBarPanel();
			this.rasConn = new Ras.RasConnection(this.components);
			this.tabControl1 = new System.Windows.Forms.TabControl();
			this.tabPage1 = new System.Windows.Forms.TabPage();
			this.lbCallback = new System.Windows.Forms.Label();
			this.txtCallback = new System.Windows.Forms.TextBox();
			this.lbDomain = new System.Windows.Forms.Label();
			this.lbPassword = new System.Windows.Forms.Label();
			this.lbUserName = new System.Windows.Forms.Label();
			this.lbPhoneNumber = new System.Windows.Forms.Label();
			this.btnHandup = new System.Windows.Forms.Button();
			this.btnDial = new System.Windows.Forms.Button();
			this.lbMsg = new System.Windows.Forms.ListBox();
			this.txtDomain = new System.Windows.Forms.TextBox();
			this.txtPassword = new System.Windows.Forms.TextBox();
			this.txtUserName = new System.Windows.Forms.TextBox();
			this.txtPhoneNumber = new System.Windows.Forms.TextBox();
			this.tabPage2 = new System.Windows.Forms.TabPage();
			this.cbAutoMonitor = new System.Windows.Forms.CheckBox();
			this.label1 = new System.Windows.Forms.Label();
			this.btnHandup2 = new System.Windows.Forms.Button();
			this.btnRefresh = new System.Windows.Forms.Button();
			this.lbConnections = new System.Windows.Forms.ListBox();
			this.tabPage3 = new System.Windows.Forms.TabPage();
			this.gbEntryInfo = new System.Windows.Forms.GroupBox();
			this.button2 = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.txtLocalPhoneNumber = new System.Windows.Forms.TextBox();
			this.txtAeraNumber = new System.Windows.Forms.TextBox();
			this.btnModify = new System.Windows.Forms.Button();
			this.cboAltNumbers = new System.Windows.Forms.ComboBox();
			this.label10 = new System.Windows.Forms.Label();
			this.lblType = new System.Windows.Forms.Label();
			this.lblDeviceName = new System.Windows.Forms.Label();
			this.lblDeviceType = new System.Windows.Forms.Label();
			this.lblCountryCode = new System.Windows.Forms.Label();
			this.lblCountryID = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.cboEntryName = new System.Windows.Forms.ComboBox();
			this.rasNotify = new System.Windows.Forms.NotifyIcon(this.components);
			this.cmContext = new System.Windows.Forms.ContextMenu();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			this.menuItem4 = new System.Windows.Forms.MenuItem();
			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
			this.rcnNotify = new Ras.RasConnectionNotify(this.components);
			((System.ComponentModel.ISupportInitialize)(this.sbpStatus)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.rasConn)).BeginInit();
			this.tabControl1.SuspendLayout();
			this.tabPage1.SuspendLayout();
			this.tabPage2.SuspendLayout();
			this.tabPage3.SuspendLayout();
			this.gbEntryInfo.SuspendLayout();
			this.SuspendLayout();
			// 
			// cmMenu
			// 
			this.cmMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																				   this.miClear});
			// 
			// miClear
			// 
			this.miClear.Index = 0;
			this.miClear.Text = "Clear";
			this.miClear.Click  = new System.EventHandler(this.miClear_Click);
			// 
			// sbStatus
			// 
			this.sbStatus.Location = new System.Drawing.Point(0, 361);
			this.sbStatus.Name = "sbStatus";
			this.sbStatus.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
																						this.sbpStatus});
			this.sbStatus.ShowPanels = true;
			this.sbStatus.Size = new System.Drawing.Size(362, 22);
			this.sbStatus.SizingGrip = false;
			this.sbStatus.TabIndex = 11;
			// 
			// sbpStatus
			// 
			this.sbpStatus.Text = "Disconnect";
			// 
			// rasConn
			// 
			this.rasConn.CallbackNumber = null;
			this.rasConn.Domain = null;
			this.rasConn.EntryName = null;
			this.rasConn.Password = null;
			this.rasConn.Phonebook = "";
			this.rasConn.PhoneNumber = null;
			this.rasConn.SynchronizingObject = this;
			this.rasConn.UserName = null;
			this.rasConn.DialNotify1  = new Ras.RasDialNotify1EventHandler(this.rasConn_DialNotify1);
			this.rasConn.Error  = new Ras.RasErrorEventHandler(this.rasConn_Error);
			this.rasConn.Disconnected  = new System.EventHandler(this.rasConn_Disconnected);
			this.rasConn.Connected  = new System.EventHandler(this.rasConn_Connected);
			// 
			// tabControl1
			// 
			this.tabControl1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					  this.tabPage1,
																					  this.tabPage2,
																					  this.tabPage3});
			this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.tabControl1.Name = "tabControl1";
			this.tabControl1.SelectedIndex = 0;
			this.tabControl1.Size = new System.Drawing.Size(362, 361);
			this.tabControl1.TabIndex = 12;
			this.tabControl1.SelectedIndexChanged  = new System.EventHandler(this.tabControl1_SelectedIndexChanged);
			// 
			// tabPage1
			// 
			this.tabPage1.Controls.AddRange(new System.Windows.Forms.Control[] {
																				   this.lbCallback,
																				   this.txtCallback,
																				   this.lbDomain,
																				   this.lbPassword,
																				   this.lbUserName,
																				   this.lbPhoneNumber,
																				   this.btnHandup,
																				   this.btnDial,
																				   this.lbMsg,
																				   this.txtDomain,
																				   this.txtPassword,
																				   this.txtUserName,
																				   this.txtPhoneNumber});
			this.tabPage1.Location = new System.Drawing.Point(4, 21);
			this.tabPage1.Name = "tabPage1";
			this.tabPage1.Size = new System.Drawing.Size(354, 336);
			this.tabPage1.TabIndex = 0;
			this.tabPage1.Text = "Dial";
			// 
			// lbCallback
			// 
			this.lbCallback.Location = new System.Drawing.Point(16, 88);
			this.lbCallback.Name = "lbCallback";
			this.lbCallback.Size = new System.Drawing.Size(72, 16);
			this.lbCallback.TabIndex = 23;
			this.lbCallback.Text = "Callback";
			// 
			// txtCallback
			// 
			this.txtCallback.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txtCallback.Location = new System.Drawing.Point(96, 80);
			this.txtCallback.Name = "txtCallback";
			this.txtCallback.Size = new System.Drawing.Size(232, 21);
			this.txtCallback.TabIndex = 22;
			this.txtCallback.Text = "";
			// 
			// lbDomain
			// 
			this.lbDomain.Location = new System.Drawing.Point(16, 112);
			this.lbDomain.Name = "lbDomain";
			this.lbDomain.Size = new System.Drawing.Size(72, 16);
			this.lbDomain.TabIndex = 21;
			this.lbDomain.Text = "Domain";
			// 
			// lbPassword
			// 
			this.lbPassword.Location = new System.Drawing.Point(16, 64);
			this.lbPassword.Name = "lbPassword";
			this.lbPassword.Size = new System.Drawing.Size(72, 16);
			this.lbPassword.TabIndex = 20;
			this.lbPassword.Text = "Password";
			// 
			// lbUserName
			// 
			this.lbUserName.Location = new System.Drawing.Point(16, 40);
			this.lbUserName.Name = "lbUserName";
			this.lbUserName.Size = new System.Drawing.Size(72, 16);
			this.lbUserName.TabIndex = 19;
			this.lbUserName.Text = "UserName";
			// 
			// lbPhoneNumber
			// 
			this.lbPhoneNumber.Location = new System.Drawing.Point(16, 16);
			this.lbPhoneNumber.Name = "lbPhoneNumber";
			this.lbPhoneNumber.Size = new System.Drawing.Size(72, 16);
			this.lbPhoneNumber.TabIndex = 18;
			this.lbPhoneNumber.Text = "PhoneNumber";
			// 
			// btnHandup
			// 
			this.btnHandup.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			this.btnHandup.Location = new System.Drawing.Point(208, 304);
			this.btnHandup.Name = "btnHandup";
			this.btnHandup.TabIndex = 17;
			this.btnHandup.Text = "Handup";
			this.btnHandup.Click  = new System.EventHandler(this.btnHandup_Click);
			// 
			// btnDial
			// 
			this.btnDial.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			this.btnDial.Location = new System.Drawing.Point(72, 304);
			this.btnDial.Name = "btnDial";
			this.btnDial.TabIndex = 16;
			this.btnDial.Text = "Dial";
			this.btnDial.Click  = new System.EventHandler(this.btnDial_Click);
			// 
			// lbMsg
			// 
			this.lbMsg.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.lbMsg.ContextMenu = this.cmMenu;
			this.lbMsg.ItemHeight = 12;
			this.lbMsg.Location = new System.Drawing.Point(16, 136);
			this.lbMsg.Name = "lbMsg";
			this.lbMsg.Size = new System.Drawing.Size(320, 148);
			this.lbMsg.TabIndex = 15;
			// 
			// txtDomain
			// 
			this.txtDomain.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txtDomain.Location = new System.Drawing.Point(96, 104);
			this.txtDomain.Name = "txtDomain";
			this.txtDomain.Size = new System.Drawing.Size(232, 21);
			this.txtDomain.TabIndex = 14;
			this.txtDomain.Text = "";
			// 
			// txtPassword
			// 
			this.txtPassword.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txtPassword.Location = new System.Drawing.Point(96, 56);
			this.txtPassword.Name = "txtPassword";
			this.txtPassword.PasswordChar = '*';
			this.txtPassword.Size = new System.Drawing.Size(232, 21);
			this.txtPassword.TabIndex = 13;
			this.txtPassword.Text = "ras";
			// 
			// txtUserName
			// 
			this.txtUserName.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txtUserName.Location = new System.Drawing.Point(96, 32);
			this.txtUserName.Name = "txtUserName";
			this.txtUserName.Size = new System.Drawing.Size(232, 21);
			this.txtUserName.TabIndex = 12;
			this.txtUserName.Text = "ras";
			// 
			// txtPhoneNumber
			// 
			this.txtPhoneNumber.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txtPhoneNumber.Location = new System.Drawing.Point(96, 8);
			this.txtPhoneNumber.Name = "txtPhoneNumber";
			this.txtPhoneNumber.Size = new System.Drawing.Size(232, 21);
			this.txtPhoneNumber.TabIndex = 11;
			this.txtPhoneNumber.Text = "363";
			// 
			// tabPage2
			// 
			this.tabPage2.Controls.AddRange(new System.Windows.Forms.Control[] {
																				   this.cbAutoMonitor,
																				   this.label1,
																				   this.btnHandup2,
																				   this.btnRefresh,
																				   this.lbConnections});
			this.tabPage2.Location = new System.Drawing.Point(4, 21);
			this.tabPage2.Name = "tabPage2";
			this.tabPage2.Size = new System.Drawing.Size(354, 336);
			this.tabPage2.TabIndex = 1;
			this.tabPage2.Text = "Conntions";
			// 
			// cbAutoMonitor
			// 
			this.cbAutoMonitor.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.cbAutoMonitor.Location = new System.Drawing.Point(11, 240);
			this.cbAutoMonitor.Name = "cbAutoMonitor";
			this.cbAutoMonitor.Size = new System.Drawing.Size(92, 17);
			this.cbAutoMonitor.TabIndex = 4;
			this.cbAutoMonitor.Text = "AutoMonitor";
			this.cbAutoMonitor.CheckedChanged  = new System.EventHandler(this.cbAutoMonitor_CheckedChanged);
			// 
			// label1
			// 
			this.label1.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.label1.Location = new System.Drawing.Point(8, 264);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(344, 39);
			this.label1.TabIndex = 3;
			this.label1.Text = "If phonebook is not empty string that is normal dial,Double click the connection "  
				"you can see detail connection info";
			// 
			// btnHandup2
			// 
			this.btnHandup2.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			this.btnHandup2.Location = new System.Drawing.Point(264, 304);
			this.btnHandup2.Name = "btnHandup2";
			this.btnHandup2.TabIndex = 2;
			this.btnHandup2.Text = "Handup";
			this.btnHandup2.Click  = new System.EventHandler(this.btnHandup2_Click);
			// 
			// btnRefresh
			// 
			this.btnRefresh.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			this.btnRefresh.Location = new System.Drawing.Point(152, 304);
			this.btnRefresh.Name = "btnRefresh";
			this.btnRefresh.TabIndex = 1;
			this.btnRefresh.Text = "Refresh";
			this.btnRefresh.Click  = new System.EventHandler(this.btnRefresh_Click);
			// 
			// lbConnections
			// 
			this.lbConnections.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.lbConnections.ItemHeight = 12;
			this.lbConnections.Name = "lbConnections";
			this.lbConnections.Size = new System.Drawing.Size(354, 232);
			this.lbConnections.TabIndex = 0;
			this.lbConnections.DoubleClick  = new System.EventHandler(this.lbConnections_DoubleClick);
			// 
			// tabPage3
			// 
			this.tabPage3.Controls.AddRange(new System.Windows.Forms.Control[] {
																				   this.gbEntryInfo,
																				   this.cboEntryName});
			this.tabPage3.Location = new System.Drawing.Point(4, 21);
			this.tabPage3.Name = "tabPage3";
			this.tabPage3.Size = new System.Drawing.Size(354, 336);
			this.tabPage3.TabIndex = 2;
			this.tabPage3.Text = "EntryInfo";
			// 
			// gbEntryInfo
			// 
			this.gbEntryInfo.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.gbEntryInfo.Controls.AddRange(new System.Windows.Forms.Control[] {
																					  this.button2,
																					  this.button1,
																					  this.txtLocalPhoneNumber,
																					  this.txtAeraNumber,
																					  this.btnModify,
																					  this.cboAltNumbers,
																					  this.label10,
																					  this.lblType,
																					  this.lblDeviceName,
																					  this.lblDeviceType,
																					  this.lblCountryCode,
																					  this.lblCountryID,
																					  this.label8,
																					  this.label7,
																					  this.label6,
																					  this.label5,
																					  this.label4,
																					  this.label3,
																					  this.label2});
			this.gbEntryInfo.Location = new System.Drawing.Point(6, 34);
			this.gbEntryInfo.Name = "gbEntryInfo";
			this.gbEntryInfo.Size = new System.Drawing.Size(342, 296);
			this.gbEntryInfo.TabIndex = 1;
			this.gbEntryInfo.TabStop = false;
			this.gbEntryInfo.Text = "EntryInfo";
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(238, 266);
			this.button2.Name = "button2";
			this.button2.TabIndex = 20;
			this.button2.Text = "Create";
			this.button2.Click  = new System.EventHandler(this.button2_Click);
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(134, 266);
			this.button1.Name = "button1";
			this.button1.TabIndex = 19;
			this.button1.Text = "Delete";
			this.button1.Click  = new System.EventHandler(this.button1_Click);
			// 
			// txtLocalPhoneNumber
			// 
			this.txtLocalPhoneNumber.Location = new System.Drawing.Point(147, 119);
			this.txtLocalPhoneNumber.Name = "txtLocalPhoneNumber";
			this.txtLocalPhoneNumber.Size = new System.Drawing.Size(174, 21);
			this.txtLocalPhoneNumber.TabIndex = 18;
			this.txtLocalPhoneNumber.Text = "";
			// 
			// txtAeraNumber
			// 
			this.txtAeraNumber.Location = new System.Drawing.Point(147, 89);
			this.txtAeraNumber.Name = "txtAeraNumber";
			this.txtAeraNumber.Size = new System.Drawing.Size(174, 21);
			this.txtAeraNumber.TabIndex = 17;
			this.txtAeraNumber.Text = "";
			// 
			// btnModify
			// 
			this.btnModify.Location = new System.Drawing.Point(30, 266);
			this.btnModify.Name = "btnModify";
			this.btnModify.TabIndex = 16;
			this.btnModify.Text = "Modify";
			this.btnModify.Click  = new System.EventHandler(this.btnModify_Click);
			// 
			// cboAltNumbers
			// 
			this.cboAltNumbers.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.cboAltNumbers.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboAltNumbers.Location = new System.Drawing.Point(147, 237);
			this.cboAltNumbers.Name = "cboAltNumbers";
			this.cboAltNumbers.Size = new System.Drawing.Size(174, 21);
			this.cboAltNumbers.TabIndex = 15;
			// 
			// label10
			// 
			this.label10.Location = new System.Drawing.Point(16, 238);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(123, 12);
			this.label10.TabIndex = 14;
			this.label10.Text = "Alternate Numbers:";
			// 
			// lblType
			// 
			this.lblType.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.lblType.Location = new System.Drawing.Point(147, 208);
			this.lblType.Name = "lblType";
			this.lblType.Size = new System.Drawing.Size(174, 12);
			this.lblType.TabIndex = 13;
			// 
			// lblDeviceName
			// 
			this.lblDeviceName.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.lblDeviceName.Location = new System.Drawing.Point(147, 179);
			this.lblDeviceName.Name = "lblDeviceName";
			this.lblDeviceName.Size = new System.Drawing.Size(174, 12);
			this.lblDeviceName.TabIndex = 12;
			// 
			// lblDeviceType
			// 
			this.lblDeviceType.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.lblDeviceType.Location = new System.Drawing.Point(147, 150);
			this.lblDeviceType.Name = "lblDeviceType";
			this.lblDeviceType.Size = new System.Drawing.Size(174, 12);
			this.lblDeviceType.TabIndex = 11;
			// 
			// lblCountryCode
			// 
			this.lblCountryCode.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.lblCountryCode.Location = new System.Drawing.Point(147, 63);
			this.lblCountryCode.Name = "lblCountryCode";
			this.lblCountryCode.Size = new System.Drawing.Size(174, 12);
			this.lblCountryCode.TabIndex = 8;
			// 
			// lblCountryID
			// 
			this.lblCountryID.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.lblCountryID.Location = new System.Drawing.Point(147, 34);
			this.lblCountryID.Name = "lblCountryID";
			this.lblCountryID.Size = new System.Drawing.Size(174, 12);
			this.lblCountryID.TabIndex = 7;
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(16, 209);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(123, 12);
			this.label8.TabIndex = 6;
			this.label8.Text = "Type:";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(16, 180);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(123, 12);
			this.label7.TabIndex = 5;
			this.label7.Text = "Device Name:";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(16, 151);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(123, 12);
			this.label6.TabIndex = 4;
			this.label6.Text = "Device Type:";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(16, 122);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(123, 12);
			this.label5.TabIndex = 3;
			this.label5.Text = "Local Phone Number:";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(16, 93);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(123, 12);
			this.label4.TabIndex = 2;
			this.label4.Text = "Aera Number:";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 64);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(123, 12);
			this.label3.TabIndex = 1;
			this.label3.Text = "Country Code:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 35);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(123, 12);
			this.label2.TabIndex = 0;
			this.label2.Text = "Country ID:";
			// 
			// cboEntryName
			// 
			this.cboEntryName.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.cboEntryName.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboEntryName.Location = new System.Drawing.Point(13, 9);
			this.cboEntryName.Name = "cboEntryName";
			this.cboEntryName.Size = new System.Drawing.Size(329, 21);
			this.cboEntryName.TabIndex = 0;
			this.cboEntryName.SelectedIndexChanged  = new System.EventHandler(this.cboEntryName_SelectedIndexChanged);
			// 
			// rasNotify
			// 
			this.rasNotify.ContextMenu = this.cmContext;
			this.rasNotify.Icon = ((System.Drawing.Icon)(resources.GetObject("rasNotify.Icon")));
			this.rasNotify.Text = "Disconnect";
			this.rasNotify.Visible = true;
			this.rasNotify.MouseMove  = new System.Windows.Forms.MouseEventHandler(this.rasNotify_MouseMove);
			// 
			// cmContext
			// 
			this.cmContext.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem2,
																					  this.menuItem3,
																					  this.menuItem4});
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 0;
			this.menuItem2.Text = "ConnectStats";
			this.menuItem2.Click  = new System.EventHandler(this.menuItem2_Click);
			// 
			// menuItem3
			// 
			this.menuItem3.Index = 1;
			this.menuItem3.Text = "-";
			// 
			// menuItem4
			// 
			this.menuItem4.Index = 2;
			this.menuItem4.Text = "About";
			this.menuItem4.Click  = new System.EventHandler(this.menuItem4_Click);
			// 
			// imageList1
			// 
			this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
			this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// rcnNotify
			// 
			this.rcnNotify.Enabled = false;
			this.rcnNotify.SynchronizingObject = this;
			this.rcnNotify.Notify  = new Ras.RasNotifyEventHandler(this.rcnNotify_Notify);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(362, 383);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.tabControl1,
																		  this.sbStatus});
			this.MinimumSize = new System.Drawing.Size(370, 410);
			this.Name = "Form1";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "RAS Dial Demo";
			((System.ComponentModel.ISupportInitialize)(this.sbpStatus)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.rasConn)).EndInit();
			this.tabControl1.ResumeLayout(false);
			this.tabPage1.ResumeLayout(false);
			this.tabPage2.ResumeLayout(false);
			this.tabPage3.ResumeLayout(false);
			this.gbEntryInfo.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void rasConn_Connected(object sender, System.EventArgs e)
		{
			this.rasNotify.Icon=IconConn;
			this.rasNotify.Text=this.sbpStatus.Text="Connected";
		}

		private void rasConn_DialNotify1(object sender, Ras.RasDialNotify1EventArgs e)
		{
			this.rasNotify.Icon=_FlashFlag?IconStat1:IconStat2;
			_FlashFlag=!_FlashFlag;
			this.rasNotify.Text=string.Format("{0},{1}",e.ConnectionState,e.Message);
			this.lbMsg.Items.Add(string.Format("{0},{1}",e.ConnectionState,e.Message));
			if(e.Error>0)
			{
				MessageBox.Show(string.Format("{0},{1}",e.Error,e.Message));
			}
		}

		private void rasConn_Disconnected(object sender, System.EventArgs e)
		{
			this.rasNotify.Icon=IconDisconn;
			this.rasNotify.Text=this.sbpStatus.Text="Disconnect";
		}

		private void rasConn_Error(object sender, Ras.RasErrorEventArgs e)
		{
			MessageBox.Show(this,string.Format("Error:{0},{1}",e.ErrorCode,e.ErrorMessage),
							"Error information",
							MessageBoxButtons.OK,
							MessageBoxIcon.Error);
		}

		private void btnDial_Click(object sender, System.EventArgs e)
		{
			rasConn.PhoneNumber=txtPhoneNumber.Text;
			rasConn.UserName=txtUserName.Text;
			rasConn.Password=txtPassword.Text;
			rasConn.CallbackNumber=txtCallback.Text;
			rasConn.Domain=txtDomain.Text;
			rasConn.Dial();
		}

		private void btnHandup_Click(object sender, System.EventArgs e)
		{
			rasConn.HandUp();
		}

		private void miClear_Click(object sender, System.EventArgs e)
		{
			this.lbMsg.Items.Clear();
		}

		private void btnRefresh_Click(object sender, System.EventArgs e)
		{
			this.lbConnections.Items.Clear();
			this._RasConns=RasConnectionEnumerator.GetConnections();
			foreach(RasConnection conn in this._RasConns)
			{
				this.lbConnections.Items.Add(string.Format("Handle:{0},Phonebook:{1},EntryName:{2},IP:{3},ServerIP:{4}",
					new object[]{conn.Handle,conn.Phonebook,conn.EntryName,conn.IpAddress,conn.ServerIpAddress}));
			}
		}

		private void btnHandup2_Click(object sender, System.EventArgs e)
		{
			int index=this.lbConnections.SelectedIndex;
			if(index<0)
				return;
			this._RasConns[index].HandUp();
			this.btnRefresh_Click(null,null);
		}

		private void rasNotify_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if(this.rasNotify.Icon==this.IconConn)
			{
				RasStats rs=this.rasConn.GetStats();
				this.rasNotify.Text=string.Format("BytesRcved:{0}\nAlignmentErr:{1}\nBps:{2}\nConnectDuration:{3}",new object[]{
								rs.dwBytesRcved,rs.dwAlignmentErr,rs.dwBps,rs.dwConnectDuration});
			}
		}

		private void menuItem4_Click(object sender, System.EventArgs e)
		{
			new FormAbout().ShowDialog(this);
		}

		private void menuItem2_Click(object sender, System.EventArgs e)
		{
			new FormStats(this.rasConn).Show();
		}

		private void lbConnections_DoubleClick(object sender, System.EventArgs e)
		{
			int index=this.lbConnections.SelectedIndex;
			if(index<0)
				return;
			new FormStats(this._RasConns[index]).Show();
		}

		private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(tabControl1.SelectedTab==this.tabPage3)
			{
				InitEntryNameList();
				//this.cboEntryName.DataSource
			}
		}

		private void InitEntryNameList()
		{
			_RasEntrys=RasEntry.GetEntrys();
			//string[] names=RasEntryEnumerator.GetEntryNames();
			this.cboEntryName.Items.Clear();
			foreach(RasEntry entry in _RasEntrys)
			{
				this.cboEntryName.Items.Add(entry.EntryName);
			}
			if(cboEntryName.Items.Count>0)
				cboEntryName.SelectedIndex=0;
		}

		private void cboEntryName_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int index=this.cboEntryName.SelectedIndex;
			if(index>=0)
			{
				DisplayEntryInfo(index);
			}
		}

		private void DisplayEntryInfo(int index)
		{
			this.cboAltNumbers.Items.Clear();
			RasEntry re=_RasEntrys[index];
			this.lblCountryID.Text=re.CountryID.ToString();
			this.lblCountryCode.Text=re.CountryCode.ToString();
			this.txtAeraNumber.Text=re.AreaCode;
			this.txtLocalPhoneNumber.Text=re.LocalPhoneNumber;
			this.lblDeviceName.Text=re.DeviceName;
			this.lblDeviceType.Text=re.DeviceType;
			this.lblType.Text=re.Type.ToString();
			foreach(string s in re.AlternateNumbers)
			{
				this.cboAltNumbers.Items.Add(s);
			}
			if(cboAltNumbers.Items.Count>0)
				cboAltNumbers.SelectedIndex=0;
			//this.lblOtherNumbers.Text=otherNumbers;
		}

		private void btnModify_Click(object sender, System.EventArgs e)
		{
			if(this.cboEntryName.SelectedIndex>=0)
			{
				RasEntry re=_RasEntrys[cboEntryName.SelectedIndex];
				re.AreaCode=this.txtAeraNumber.Text;
				re.LocalPhoneNumber=this.txtLocalPhoneNumber.Text;
				RasEntry.SetEntry(re);
				InitEntryNameList();
			}
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			if(this.cboEntryName.SelectedIndex>=0)
			{
				RasEntry.DeleteEntry(this.cboEntryName.Text);
				InitEntryNameList();
			}
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			CreateEntryForm cef=new CreateEntryForm();
			if(cef.ShowDialog(this)==DialogResult.OK)
			{
				RasEntry re=new RasEntry(cef.txtEntryName.Text,
									cef.txtPhoneNum.Text,
									cef.lblDeviceType.Text,
									cef.cmbDeviceName.Text);
				foreach(string s in cef.lbAltNum.Items)
				{
					re.AlternateNumbers.Add(s);
				}
				RasEntry.SetEntry(re);
				InitEntryNameList();
			}
		}

		private void cbAutoMonitor_CheckedChanged(object sender, System.EventArgs e)
		{
			this.rcnNotify.Enabled=this.cbAutoMonitor.Checked;
		}

		private void rcnNotify_Notify(object sender, Ras.RasNotifyEventArgs e)
		{
			MessageBox.Show(e.Notification.ToString());
			this.btnRefresh_Click(null,EventArgs.Empty);
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(rasConn.IpAddress);
		}
	}
}

标签: C# 拨号 adsl

实例下载地址

C# 获取本地拨号列表并实现拨号/创建拨号功能

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警