Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Desktop Applications

RSS
Modified on Sat, Feb 06, 2010, 5:10 PM by Administrator Categorized as Design Patterns

Overview

  • Building a menu of available modules
  • Managing MDI windows
  • Loading DLL files Just-In-Time
  • Managing Save-able documents
  • Building a menu of MRU items
  • Handling events
  • Displaying a Busy Panel
  • Managing an Internet connection
  • Handling exceptions

Building an Icon Bar

(similar to Outlook Bar)

Managing MDI Windows

Opening an Existing Document

private void OpenFile(string fileName, bool mustExist, bool showCoverPage)
{
    try
    {
        string initialPath = ObjectMain.GetSetting(OptionSetting.DefaultPath);
        DialogResult result = DialogResult.OK;
        if (fileName.Length == 0)
        {
            result = OpenFileForm.GetFileToOpen(initialPath);
            fileName = OpenFileForm.FileSelected;
            showCoverPage = OpenFileForm.ShowCoverPage;
        }
        bool isPdf = fileName.ToUpper().EndsWith(".PDF");

        if (mustExist & !File.Exists(fileName))

            MessageBox.Show("File not found\n" + fileName, Application.ProductName, 
                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        
        else if (result != DialogResult.Cancel)
        {
            if (_documents.ContainsKey(fileName))
            {
                _documents[fileName].BringToFront();
            }
            else
            {
                DocumentWindow w = WindowFactory.CreateDocumentWindowForFile(fileName);

                if (w == null)

                    MessageBox.Show("Couldn't create document window for file\n" + 
                        fileName, Application.ProductName,  MessageBoxButtons.OK, 
                        MessageBoxIcon.Exclamation);

                else
                {
                    if (isPdf)
                    {
                        IPdfViewer p = (IPdfViewer)w;
                        p.ShowCoverPage = showCoverPage;
                        w.OpenFile(fileName, uxMainToolStrip, FormWindowState.Maximized);
                    }
                    else
                    {
                        w.OpenFile(fileName, uxMainToolStrip, uxDockPanel);
                    }
                    _documents.Add(w.Key, w);
                    w.FormClosed += new FormClosedEventHandler(DocumentWindow_FormClosed);
                }
            }
        }
    }
    catch (Exception ex)
    {
        LibSystem.Diagnostics.ExceptionHandler.Show(ex);
    }

}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.