问题
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