Click here to Skip to main content
15,885,914 members
Articles / Programming Languages / Visual Basic

Drag and Resize - Borderless Form

Rate me:
Please Sign up or sign in to vote.
4.71/5 (5 votes)
17 Dec 2012CPOL1 min read 51.1K   5.2K   8  
This code allows to drag and resize a borderless form!
namespace Borderless_Form
{
    partial class Borderless
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <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);
        }

        #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.components = new System.ComponentModel.Container();
            this.panel1 = new System.Windows.Forms.Panel();
            this.labelName = new System.Windows.Forms.Label();
            this.buttonMin = new System.Windows.Forms.Button();
            this.buttonClos = new System.Windows.Forms.Button();
            this.buttonMax = new System.Windows.Forms.Button();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.panel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // panel1
            // 
            this.panel1.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.panel1.BackgroundImage = global::Borderless_Form.Properties.Resources.Orange;
            this.panel1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            this.panel1.Controls.Add(this.labelName);
            this.panel1.Controls.Add(this.buttonMin);
            this.panel1.Controls.Add(this.buttonClos);
            this.panel1.Controls.Add(this.buttonMax);
            this.panel1.Location = new System.Drawing.Point(3, 3);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(444, 26);
            this.panel1.TabIndex = 3;
            this.panel1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDoubleClick);
            this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
            this.panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove);
            this.panel1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseUp);
            // 
            // labelName
            // 
            this.labelName.AutoSize = true;
            this.labelName.BackColor = System.Drawing.Color.Transparent;
            this.labelName.Font = new System.Drawing.Font("Georgia", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.labelName.Location = new System.Drawing.Point(9, 6);
            this.labelName.Name = "labelName";
            this.labelName.Size = new System.Drawing.Size(106, 15);
            this.labelName.TabIndex = 4;
            this.labelName.Text = "Selfmade Form";
            // 
            // buttonMin
            // 
            this.buttonMin.BackgroundImage = global::Borderless_Form.Properties.Resources.minimize2;
            this.buttonMin.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            this.buttonMin.Location = new System.Drawing.Point(370, 3);
            this.buttonMin.Name = "buttonMin";
            this.buttonMin.Size = new System.Drawing.Size(20, 20);
            this.buttonMin.TabIndex = 2;
            this.buttonMin.UseVisualStyleBackColor = true;
            this.buttonMin.Click += new System.EventHandler(this.buttonMin_Click);
            // 
            // buttonClos
            // 
            this.buttonClos.BackgroundImage = global::Borderless_Form.Properties.Resources.close2;
            this.buttonClos.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            this.buttonClos.Location = new System.Drawing.Point(422, 3);
            this.buttonClos.Name = "buttonClos";
            this.buttonClos.Size = new System.Drawing.Size(20, 20);
            this.buttonClos.TabIndex = 0;
            this.buttonClos.UseVisualStyleBackColor = true;
            this.buttonClos.Click += new System.EventHandler(this.buttonClos_Click);
            // 
            // buttonMax
            // 
            this.buttonMax.BackgroundImage = global::Borderless_Form.Properties.Resources.maximize2;
            this.buttonMax.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            this.buttonMax.Location = new System.Drawing.Point(396, 3);
            this.buttonMax.Name = "buttonMax";
            this.buttonMax.Size = new System.Drawing.Size(20, 20);
            this.buttonMax.TabIndex = 1;
            this.buttonMax.UseVisualStyleBackColor = true;
            this.buttonMax.Click += new System.EventHandler(this.buttonMax_Click);
            // 
            // timer1
            // 
            this.timer1.Enabled = true;
            this.timer1.Interval = 50;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            // 
            // Borderless
            // 
            this.ClientSize = new System.Drawing.Size(449, 210);
            this.Controls.Add(this.panel1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.Name = "Borderless";
            this.Text = "Selfmade Form";
            this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Borderless_MouseDown);
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Borderless_MouseMove);
            this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Borderless_MouseUp);
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Button buttonClos;
        private System.Windows.Forms.Button buttonMax;
        private System.Windows.Forms.Button buttonMin;
        private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.Label labelName;
        private System.Windows.Forms.Timer timer1;
    }
}

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)



Comments and Discussions