zoukankan      html  css  js  c++  java
  • 限制一个form被同时打开的数量 Limite The Number of Forms Opened at the same time


    There is a kind of forms that you only want to show 1 instance for users, because multi instances is unnecessary and may cause concurrency problems. To achieve this, I tried in several ways:

    1. Bad practise: Make the form a singleton class, however, it's not the solution. Because once you closed it, the singleton object will be disposed, then if you try to open it again by call the Show() method, an exception will be thrown said:"Cannot access a disposed object Form_Name"...

    2. Actually, the easiest way is just show the form as a model dialog, by using the ShowDialog() method. Since a form is usually launched by an event from UI components(such as button click or menu item click), set the form to model will prevent user launch the same form once again before they closing the current one. However, the cons are also apparent: users are prevented from doing any operations on the parent forms, this may make them feel quite inconvenient.

    3. Another solution is just use singleton patter, but hide the form other than close it when user try to close it, this can be implemented by cancel the Form_Closing event.

     

  • 相关阅读:
    [转]使用RDLC报表
    WPF 导出Excel 导出图片
    细说WPF自定义路由事件
    [转]WPF更换主题
    推荐5款超实用的.NET性能分析工具
    Hibernate框架
    C#的protected internal
    C#的类修饰符和成员修饰符
    C#的foreach
    C#接口
  • 原文地址:https://www.cnblogs.com/k330/p/1060649.html
Copyright © 2011-2022 走看看