本文介绍了表单组件继承CommonDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,正如标题所说,我需要创建一个从commonDialog继承的组件.我已经创建了一个表单并且可以正常工作,但是我需要将其创建为组件(例如OpenFileDialog),以便在以后的项目中使用(例如弹出窗口").

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").

有什么想法吗?

谢谢!

推荐答案

CommonDialog是一个非常特定的基类,旨在用作Windows内置对话框的通用基类.它不是您自己的组件的适当基类.只需从Component派生.

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.

一个简单的例子:

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
    //...

}

这篇关于表单组件继承CommonDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 17:07