WinForm缓存机制
来源:互联网 发布:文泰软件baiduyun 编辑:程序博客网 时间:2024/06/06 02:05
本人才疏学浅,幸得高人相助,在第一次发表文章之际,向他表示衷心地感谢!
首先定义一个类
using System;
using System.Windows.Forms;
using System.Collections;
using System.Reflection;
namespace WinFormTest
{
public class FormCache
{
private static System.Collections.Hashtable ht = new System.Collections.Hashtable();
public static System.Windows.Forms.Form GetForm(string formtype)
{
if (ht.Contains(formtype))
{
}
else
{
ht.Add(formtype, System.Activator.CreateInstance(System.Type.GetType(formtype)));
}
Form temp= ht[formtype] as Form;
temp.FormClosing += new FormClosingEventHandler(temp_FormClosing);
return temp;
}
public static System.Windows.Forms.Form GetForm(string formtype,object[] obj)
{
if (ht.Contains(formtype))
{
}
else
{
Type type=System.Type.GetType(formtype);
//object obj2=System.Activator.CreateInstance(type, obj, null);
//object obj3 = System.Activator.CreateInstance(type, obj);
ht.Add(formtype, System.Activator.CreateInstance(type,obj));
}
Form temp = ht[formtype] as Form;
temp.FormClosing += new FormClosingEventHandler(temp_FormClosing);
return temp;
}
static void temp_FormClosing(object sender, FormClosingEventArgs e)
{
Form f = sender as Form;
f.Hide();
e.Cancel = true;
//throw new Exception("The method or operation is not implemented.");
}
}
}
调用代码是:
private void button1_Click(object sender, EventArgs e)
{
FormCache.GetForm("WinFormTest.Form2").Show();
}
private void button2_Click(object sender, EventArgs e)
{
FormCache.GetForm("WinFormTest.Form3",new object[1]{"123"}).Show();
}
- WinForm缓存机制
- 缓存机制
- 缓存机制
- 缓存机制
- 缓存机制
- 缓存机制
- 缓存机制
- 缓存机制
- 缓存机制
- 缓存机制
- 缓存机制
- 缓存机制
- 【缓存】-浏览器缓存机制
- winform绑定机制
- winform绑定机制
- winform绑定机制
- WinForm使用的缓存类
- Winform里面的缓存使用
- 用newxy新坐标标签美化介面
- 中间件的分类
- Java环境配置大全
- linux is perfect
- loadrunner的用法
- WinForm缓存机制
- 熟悉C++标准库
- 16 预处理指令
- Apache与Tomcat的区别 ,几种长见得web/应用服务器
- HUNAN UNIVERSITY ACM/ICPC Judge Online —— Problem 10026 谁拿了最多奖学金
- PHP常量__FILE__
- 操作系统学习记录:VC中的CreateProcess函数
- 我心已疯狂 灵肉孰为殃
- 使用XML 序列化和反序列化类对象的方法