Add file open dialog to dll library

Several forms from my application use the same open file dialog. Each time I need to duplicate the code for the "open file" dialog and its parameters. I want to add a "file open dialog" to split the dll library to avoid duplication. How to do it?

WinForms, Visual Studio 2008.

+3
source share
1 answer

If you want to put the code in a separate dll, follow these steps:

  • In your solution, add a new class library project to create your DLL
  • In this newly created project, add a link to System.Windows.Forms
  • Add customization code to the OpenFileDialogclass library project
  • Windows Forms ()

, , , , DLL. :

class SpecializedOpenFileDialog 
{
    private OpenFileDialog ofd = new OpenFileDialog();

    public SpecializedOpenFileDialog()
    {
        ofd.Multiselect = false;
        ofd.Filter = "*.html";
    }

    public DialogResult ShowDialog()
    {
        return ofd.ShowDialog();
    }

    public string FileName
    {
        get 
        {
            return ofd.FileName;
        }
    }
}
+5

Source: https://habr.com/ru/post/1752043/


All Articles