欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來(lái)到入門(mén)教程網(wǎng)!

C#教程

當(dāng)前位置:主頁(yè) > 軟件編程 > C#教程 >

WinForm單例窗體用法實(shí)例

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C#教程|點(diǎn)擊: 次

本文實(shí)例講述了WinForm單例窗體。分享給大家供大家參考,具體如下:

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
namespace Common
{
  /// <summary>
  /// 窗體的單例模式
  /// </summary>
  /// <typeparam name="T"></typeparam>
  public class FormSingle<T> where T : Form, new()
  {
    private static T form;
    private static IList<T> list { get; set; }
    public static T GetForm(T t1)
    {
      //檢查是否存在窗體
      if (!IsExist(t1))
      {
        CreateNewForm(t1);
      }
      return form;
    }
    /// <summary>釋放對(duì)象
    /// </summary>
    /// <param name="obj"></param>
    /// <param name="args"></param>
    private static void Display(object obj, FormClosedEventArgs args)
    {
      form = null;
      list.Remove(form);
    }
    /// <summary>創(chuàng)建新窗體
    /// </summary>
    private static void CreateNewForm(T t1)
    {
      form = t1;
      form.FormClosed += new FormClosedEventHandler(Display);//訂閱窗體的關(guān)閉事件,釋放對(duì)象
    }
    /// <summary>
    /// 是否存在該窗體
    /// </summary>
    /// <param name="T1"></param>
    /// <returns></returns>
    private static bool IsExist(T T1)
    {
      if (list == null)
      {
        list=new List<T>();
        list.Add(T1);
        return false;
      }
      //如果窗體的文本相同則認(rèn)為是同一個(gè)窗體
      foreach (var t in list)
      {
        if (t.Text == T1.Text)
          return true;
      }
      list.Add(T1);
      return false;
    }
  }
}

調(diào)用如下:

不帶參數(shù)的構(gòu)造函數(shù)

Customer.AddCustomer customer = Common.FormSingle<Customer.AddCustomer>.GetForm(new Customer.AddCustomer());
customer.MdiParent = this;//Mdi窗體
customer.WindowState = FormWindowState.Maximized;//最大化
customer.Show();
customer.Activate();

帶參數(shù)的構(gòu)造函數(shù)

Customer.AddCustomer customer = Common.FormSingle<Customer.AddCustomer>.GetForm(new Customer.AddCustomer(customerid));
customer.MdiParent = this;
customer.WindowState = FormWindowState.Maximized;
customer.Show();
customer.Activate();

更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《WinForm控件用法總結(jié)》、《C#窗體操作技巧匯總》、《C#常見(jiàn)控件用法教程》、《C#程序設(shè)計(jì)之線程使用技巧總結(jié)》、《C#操作Excel技巧總結(jié)》、《C#中XML文件操作技巧匯總》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#數(shù)組操作技巧總結(jié)》及《C#面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》

希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。

上一篇:C#實(shí)現(xiàn)的字符串轉(zhuǎn)MD5碼函數(shù)實(shí)例

欄    目:C#教程

下一篇:C#信號(hào)量用法簡(jiǎn)單示例

本文標(biāo)題:WinForm單例窗體用法實(shí)例

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/6377.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有