Click here to Skip to main content
15,881,173 members
Articles / Programming Languages / C#

NUnit Starter

Rate me:
Please Sign up or sign in to vote.
4.92/5 (6 votes)
13 Oct 2009Zlib34 min read 42.4K   470   39  
How to create Visual Studio 2008 Add-in compatible with Visual Studio 2003
/*
 * Filename:    NUnitNotInstalledMessageBox.cs
 * Product:     NUnit Starter
 * Solution:    NUnitStarter.sln
 * Project:     AddIn
 * Description: Message box with a link to NUnit download page.
 * Copyright:   Julijan Šribar, 2009
 * 
 * This software is provided 'as-is', without any express or implied
 * warranty.  In no event will the author(s) be held liable for any damages
 * arising from the use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 *
 * 1. The origin of this software must not be misrepresented; you must not
 *    claim that you wrote the original software. If you use this software
 *    in a product, an acknowledgment in the product documentation would be
 *    appreciated but is not required.
 * 2. Altered source versions must be plainly marked as such, and must not be
 *    misrepresented as being the original software.
 * 3. This notice may not be removed or altered from any source distribution.
 */
using System;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace NUnitStarter
{
    class NUnitNotInstalledMessageBox : Form
    {
        #region ErrorIconBox class
        /// <summary>
        /// Wrapper around PictureBox which implements ISupportInitialize. Required
        /// since Designer "insists" on addig call to its methods but PictureBox in
        /// .NET 1.1 doesn't implement this interface.
        /// </summary>
        class ErrorIconBox : System.Windows.Forms.PictureBox, ISupportInitialize
        {
            protected override void OnPaint(PaintEventArgs pe)
            {
                pe.Graphics.DrawIcon(SystemIcons.Error, 0, 0);
            }

            void ISupportInitialize.BeginInit()
            {
            }

            void ISupportInitialize.EndInit()
            {
            }
        }
        #endregion

        #region Controls

        private System.Windows.Forms.Button m_buttonOK;
        private ErrorIconBox m_pictureBoxIcon;
        private System.Windows.Forms.Label m_label1;
        private System.Windows.Forms.LinkLabel m_linkLabel;
        private System.Windows.Forms.Label m_label2;
        private Panel m_panel;
        private Panel panel1;

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        #endregion Controls

        private NUnitNotInstalledMessageBox()
        {
            InitializeComponent();
            // some .NET 2.0 specific stuff
#if !TARGETTING_FX_1_1
            this.m_buttonOK.UseVisualStyleBackColor = true;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
#endif
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        /// <summary>
        ///   Resize dialog for the case that font has changed.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            Size = new Size(m_label2.Right + 24, Height);
            base.OnLoad(e);
        }

        /// <summary>
        ///   Activate link in the LinkLabel control.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void m_linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start(m_linkLabel.Text);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.m_buttonOK = new System.Windows.Forms.Button();
            this.m_pictureBoxIcon = new ErrorIconBox();
            this.m_label1 = new System.Windows.Forms.Label();
            this.m_linkLabel = new System.Windows.Forms.LinkLabel();
            this.m_label2 = new System.Windows.Forms.Label();
            this.m_panel = new System.Windows.Forms.Panel();
            this.panel1 = new System.Windows.Forms.Panel();
            ((System.ComponentModel.ISupportInitialize)(this.m_pictureBoxIcon)).BeginInit();
            this.m_panel.SuspendLayout();
            this.panel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // m_buttonOK
            // 
            this.m_buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.m_buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.m_buttonOK.Location = new System.Drawing.Point(308, 12);
            this.m_buttonOK.Name = "m_buttonOK";
            this.m_buttonOK.Size = new System.Drawing.Size(84, 25);
            this.m_buttonOK.TabIndex = 0;
            this.m_buttonOK.Text = "OK";
            // 
            // m_pictureBoxIcon
            // 
            this.m_pictureBoxIcon.Location = new System.Drawing.Point(24, 24);
            this.m_pictureBoxIcon.Name = "m_pictureBoxIcon";
            this.m_pictureBoxIcon.Size = new System.Drawing.Size(32, 32);
            this.m_pictureBoxIcon.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
            this.m_pictureBoxIcon.TabIndex = 1;
            this.m_pictureBoxIcon.TabStop = false;
            // 
            // m_label1
            // 
            this.m_label1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.m_label1.Location = new System.Drawing.Point(64, 20);
            this.m_label1.Name = "m_label1";
            this.m_label1.Size = new System.Drawing.Size(324, 32);
            this.m_label1.TabIndex = 2;
            this.m_label1.Text = "NUnit required to use this add-in is not installed or no compatible version found.";
            // 
            // m_linkLabel
            // 
            this.m_linkLabel.AutoSize = true;
            this.m_linkLabel.Location = new System.Drawing.Point(186, 68);
            this.m_linkLabel.Name = "m_linkLabel";
            this.m_linkLabel.Size = new System.Drawing.Size(75, 13);
            this.m_linkLabel.TabIndex = 3;
            this.m_linkLabel.TabStop = true;
            this.m_linkLabel.Text = "www.nunit.org";
            this.m_linkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.m_linkLabel_LinkClicked);
            // 
            // m_label2
            // 
            this.m_label2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.m_label2.AutoSize = true;
            this.m_label2.Location = new System.Drawing.Point(64, 50);
            this.m_label2.Name = "m_label2";
            this.m_label2.Size = new System.Drawing.Size(319, 13);
            this.m_label2.TabIndex = 4;
            this.m_label2.Text = "Please download and install the latest or a compatible version from";
            // 
            // m_panel
            // 
            this.m_panel.BackColor = System.Drawing.SystemColors.Window;
            this.m_panel.Controls.Add(this.m_label1);
            this.m_panel.Controls.Add(this.m_label2);
            this.m_panel.Controls.Add(this.m_pictureBoxIcon);
            this.m_panel.Controls.Add(this.m_linkLabel);
            this.m_panel.Dock = System.Windows.Forms.DockStyle.Fill;
            this.m_panel.Location = new System.Drawing.Point(0, 0);
            this.m_panel.Name = "m_panel";
            this.m_panel.Size = new System.Drawing.Size(402, 145);
            this.m_panel.TabIndex = 7;
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.m_buttonOK);
            this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.panel1.Location = new System.Drawing.Point(0, 96);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(402, 49);
            this.panel1.TabIndex = 6;
            // 
            // NUnitNotInstalledMessageBox
            // 
            this.AcceptButton = this.m_buttonOK;
            this.ClientSize = new System.Drawing.Size(402, 145);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.m_panel);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "NUnitNotInstalledMessageBox";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "NUnit Starter";
            ((System.ComponentModel.ISupportInitialize)(this.m_pictureBoxIcon)).EndInit();
            this.m_panel.ResumeLayout(false);
            this.m_panel.PerformLayout();
            this.panel1.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        #endregion

        public static new DialogResult Show()
        {
            NUnitNotInstalledMessageBox dlg = new NUnitNotInstalledMessageBox();
            return dlg.ShowDialog();
        }
    }
}

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 zlib/libpng License


Written By
Software Developer (Senior)
Croatia Croatia
Graduated at the Faculty of Electrical Engineering and Computing, University of Zagreb (Croatia) and received M.Sc. degree in electronics. For several years he was research and lecturing assistant in the fields of solid state electronics and electronic circuits, published several scientific and professional papers, as well as a book "Physics of Semiconductor Devices - Solved Problems with Theory" (in Croatian).
During that work he gained interest in C++ programming language and have co-written "C++ Demystified" (in Croatian), 1st edition published in 1997, 2nd in 2001, 3rd in 2010, 4th in 2014.
After book publication, completely switched to software development, programming mostly in C++ and in C#.
In 2016 coauthored the book "Python for Curious" (in Croatian).

Comments and Discussions