先在来看如何使用的例子:
![]()
具体代码:
( 注意要添加引用上面程序编译成功的程序集:Session.dll)
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication2

{

/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form

{
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;

/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()

{
a=Session.GetSession();
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}


/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )

{
if( disposing )

{
if (components != null)

{
components.Dispose();
}
}
base.Dispose( disposing );
}


Windows 窗体设计器生成的代码 Windows 窗体设计器生成的代码

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()

{
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);

}
#endregion


/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()

{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)

{
// a.Add(this.tbxAdd.Text.Trim(),this.tbxAdd);
a[this.tbxAdd.Text.Trim()]=this.tbxAdd;
}

private void button2_Click(object sender, System.EventArgs e)

{
a.Remove(this.tbxDel.Text.Trim());
}

private void button3_Click(object sender, System.EventArgs e)

{

this.listBox1.Items.Add(((TextBox)a[this.tbxAdd.Text.Trim()]).Text.Trim());
}
}
}

现在你可以到处使用Session.dll了,让它帮你处理页面传值。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端