Form Component inheriting CommonDialog

别说谁变了你拦得住时间么 提交于 2019-12-12 06:24:23

问题


well, as the title says, I need to create a component inheriting from the commonDialog. I have a form already created and working, but I need to create it as a component (like OpenFileDialog) to use in later project (like a "pop-up").

Any ideas ?

Thanks !


回答1:


CommonDialog is a very specific base class that was designed to act as a common base class for dialogs that are built into Windows. It is not an appropriate base class for your own component. Simply derive from Component instead.

A simple example:

using System;
using System.ComponentModel;
using System.Windows.Forms;

class MyComponent : Component {

    public bool ShowDialog() {
        using (var dlg = new WindowsFormsApplication1.Form2()) {
            if (dlg.ShowDialog() == DialogResult.OK) {
                // Retrieve properties
                //...
                return true;
            }
            else return false;
        }
    }

    // Add your own properties here
    //...

}


来源:https://stackoverflow.com/questions/11680601/form-component-inheriting-commondialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!