先在来看如何使用的例子:
![]()
具体代码:
( 注意要添加引用上面程序编译成功的程序集:Session.dll)
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication2
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.TextBox tbxAdd;
private System.Windows.Forms.TextBox tbxDel;
private Session a;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public Form1()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
{
a=Session.GetSession();
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if( disposing )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (components != null)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
Windows 窗体设计器生成的代码 Windows 窗体设计器生成的代码
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.tbxAdd = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.tbxDel = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// listBox1
//
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(136, 144);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(120, 88);
this.listBox1.TabIndex = 0;
//
// tbxAdd
//
this.tbxAdd.Location = new System.Drawing.Point(144, 32);
this.tbxAdd.Name = "tbxAdd";
this.tbxAdd.Size = new System.Drawing.Size(112, 21);
this.tbxAdd.TabIndex = 1;
this.tbxAdd.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(336, 24);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "add";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// tbxDel
//
this.tbxDel.Location = new System.Drawing.Point(144, 72);
this.tbxDel.Name = "tbxDel";
this.tbxDel.Size = new System.Drawing.Size(112, 21);
this.tbxDel.TabIndex = 3;
this.tbxDel.Text = "";
//
// button2
//
this.button2.Location = new System.Drawing.Point(336, 72);
this.button2.Name = "button2";
this.button2.TabIndex = 4;
this.button2.Text = "del";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(336, 176);
this.button3.Name = "button3";
this.button3.TabIndex = 5;
this.button3.Text = "look";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(528, 273);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.tbxDel);
this.Controls.Add(this.button1);
this.Controls.Add(this.tbxAdd);
this.Controls.Add(this.listBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
#endregion
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Application.Run(new Form1());
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void button1_Click(object sender, System.EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// a.Add(this.tbxAdd.Text.Trim(),this.tbxAdd);
a[this.tbxAdd.Text.Trim()]=this.tbxAdd;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void button2_Click(object sender, System.EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
{
a.Remove(this.tbxDel.Text.Trim());
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void button3_Click(object sender, System.EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
this.listBox1.Items.Add(((TextBox)a[this.tbxAdd.Text.Trim()]).Text.Trim());
}
}
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
现在你可以到处使用Session.dll了,让它帮你处理页面传值。