Widow – Rev 1

Subversion Repositories:
Rev:
using System;

namespace Widow
{
    public class Apply : IDisposable
    {
        #region Public Enums, Properties and Fields

        public bool OnWindowCreate { get; set; }

        public Form1 Form { get; set; }

        #endregion

        #region Private Delegates, Events, Enums, Properties, Indexers and Fields

        private Windows.Windows Windows { get; }

        #endregion

        #region Constructors, Destructors and Finalizers

        public Apply()
        {
        }

        public Apply(Form1 form1) : this()
        {
            Form = form1;

            Form.WindowCreated += Form_WindowCreated;
        }

        public Apply(Form1 form1, Windows.Windows windows) : this(form1)
        {
            Windows = windows;
        }

        public void Dispose()
        {
            Form.WindowCreated -= Form_WindowCreated;
        }

        #endregion

        #region Event Handlers

        private void Form_WindowCreated(object sender, WindowCreatedEventArgs e)
        {
            if (!OnWindowCreate)
            {
                return;
            }

            foreach (var window in Windows.Window)
            {
                if (window.Name != e.Name)
                {
                    continue;
                }

                var hWnd = Helpers.FindWindowByTitle(window.Name);
                if (hWnd == IntPtr.Zero)
                {
                    continue;
                }

                Natives.MoveWindow(hWnd, window.Left, window.Top, window.Width, window.Height, true);
            }
        }

        #endregion
    }
}

Generated by GNU Enscript 1.6.5.90.