Borderless + Sizeable form

This is a discussion on Borderless + Sizeable form within the C# Programming forums, part of the General Programming Boards category; hi! i'm doing some paint overriding of a form to get a note/memo like window. this works fine, but i ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    244

    Borderless + Sizeable form

    hi!
    i'm doing some paint overriding of a form to get a note/memo like window. this works fine, but i have to set the FormBorderStyle to None, because i don't want the window border to be displayed. but then, i can't resize the window, so how can i create a Form that is sizeable, but still has no border?
    thanx

  2. #2
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    Hi, this is pretty simple, you need to use the form's MouseMove, MouseUp, and MouseDown events to create your own resize logic.

    Example:

    Code:
    using System.Drawing;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            private bool resizing = false;
            private Point last = new Point(0, 0);
    
            public Form1()
            {
                InitializeComponent();
                this.FormBorderStyle = FormBorderStyle.None;
            }
    
            private void Form1_MouseMove(object sender, MouseEventArgs e)
            {
                if (!resizing) // handle cursor type
                {
                    bool resize_x = e.X > (this.Width - 8);
                    bool resize_y = e.Y > (this.Height - 8);
    
                    if (resize_x && resize_y)
                        this.Cursor = Cursors.SizeNWSE;
                    else if (resize_x)
                        this.Cursor = Cursors.SizeWE;
                    else if (resize_y)
                        this.Cursor = Cursors.SizeNS;
                    else this.Cursor = Cursors.Default;
                }
                else // handle resize
                {
                    int w = this.Size.Width;
                    int h = this.Size.Height;
    
                    if (this.Cursor.Equals(Cursors.SizeNWSE))
                        this.Size = new Size(w + (e.Location.X - this.last.X), h + (e.Location.Y - this.last.Y));
                    else if (this.Cursor.Equals(Cursors.SizeWE))
                        this.Size = new Size(w + (e.Location.X - this.last.X), h);
                    else if (this.Cursor.Equals(Cursors.SizeNS))
                        this.Size = new Size(w, h + (e.Location.Y - this.last.Y));
    
                    this.last = e.Location;
                }
            }
    
            private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                this.resizing = true;
                this.last = e.Location;
            }
    
            private void Form1_MouseUp(object sender, MouseEventArgs e)
            {
                this.resizing = false;
            }
        }
    }
    This principle could also be used to make your form movable.
    Last edited by theoobe; 12-20-2009 at 07:08 AM.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    cool thanks man

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calling datas from another form?
    By Aga^^ in forum C# Programming
    Replies: 2
    Last Post: 02-06-2009, 02:17 AM
  2. Windows Form App as parent, Directx as child??
    By yetti82 in forum C++ Programming
    Replies: 3
    Last Post: 05-29-2006, 04:04 AM
  3. Accessing main form from functions in other classes
    By pj_martins in forum C++ Programming
    Replies: 1
    Last Post: 11-05-2004, 09:27 AM
  4. My UserControls dissapear off my form
    By zMan in forum C# Programming
    Replies: 2
    Last Post: 09-15-2004, 09:55 AM
  5. Making an MFC form to suit
    By TJJ in forum Windows Programming
    Replies: 1
    Last Post: 04-17-2004, 12:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21