Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Easy Desktop Web Stats

, 23 Oct 2012
Create a Windows desktop app to display daily web stats from your personal site
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Media;

using Compatibility;
using ContextMenuBuilder;

namespace Desktop_Web_Stats
{
    public partial class Main : Form
    {
        private delegate void AppInitializeDelegate();
        private AppInitializeDelegate performAppInitialize;
        
        private Properties.Settings settings = Properties.Settings.Default;

        private ContextMenu formContextMenu = new ContextMenu();  
        private Point nullRefPoint = new Point(-1, -1);
        private Timer savePositionTimer = new Timer();

        Form preferencesForm = new Desktop_Web_Stats.Preferences();

        public static bool preferencesChanged = false;

        public Main()
        {           
            InitializeComponent();            

            // declare Form context menu;
            string[] formMenuItemDescriptions = {"Preferences",
                                                 "Close the program"};

            EventHandler[] formMenuItemEventHandlers = {Preferences_Item_Click,
                                                        Close_Item_Click};

            this.ContextMenu = formContextMenu;            

            // append initialize methods to delegate;           
            performAppInitialize += RestoreLastPosition;
            performAppInitialize += Manage.StartupFolderLnk;
            performAppInitialize += (() => { Build.Menu(formMenuItemDescriptions, formMenuItemEventHandlers, formContextMenu); });    
            performAppInitialize += (() => { savePositionTimer.Tick += new EventHandler(savePositionTimer_Tick); });
            performAppInitialize += CreateDataRequestCycle;
        }        

        private void Main_Load(object sender, EventArgs e)
        {                    
            VouchSafe Verified = new VouchSafe();

            if (!Verified.compatibility())
            {
                CloseAndDispose();
            }            
            
            performAppInitialize();            
        }              

        private void RestoreLastPosition()
        {           
            if (settings.preferredLocation != nullRefPoint)
            {
                this.Location = settings.preferredLocation;
            }
        }
        
        private void savePositionTimer_Tick(object sender, EventArgs e)
        {
            savePositionTimer.Stop();
            settings.preferredLocation = this.Location;
            settings.Save();
        }

        private void CloseAndDispose()
        {           
            Dispose(true);
            Application.Exit();
        }

        private void Main_Move(object sender, EventArgs e)
        {
            // stop the timer if it is already running;
            savePositionTimer.Stop();
            // wait 8 seconds, then save the new position;
            savePositionTimer.Interval = 8000;
            savePositionTimer.Start();
        }             
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Michael J Hill - OH

United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 23 Oct 2012
Article Copyright 2012 by Michael J Hill - OH
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid