Welcome to Dream.In.Code
Become a C# Expert!

Join 136,930 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,832 people online right now. Registration is fast and FREE... Join Now!




Resizing borderless form

 
Reply to this topicStart new topic

Resizing borderless form

cygnusX
7 Dec, 2007 - 04:42 AM
Post #1

D.I.C Head
**

Joined: 19 May, 2007
Posts: 159



Thanked: 2 times
My Contributions
Look at this code,i'm trying to resize borderless form.It works but there is one thing which i don't know how to achieve.When you click in the upper left corner of a window(i'm not talking about my application) and hold the mouse and then begin resizing,the window is resized from that point,i mean the right side and the lower side of the window are not affected by the resizing.But with the code i've posted,the form is resized always from lower left corner to upper right corner.Ofcourse that's ok if i'm trying to resize the form from the right side or from the lower right corner,but if i try to resize it from left side or upper/lower left corner the things go wrong.Yeah,i know this explanation is really stupid but i can't find way to explain it properly.

CODE

        private int North
        {
            get
            {
                return this.Height - this.Height + 10;
            }
            set
            {
                North = value;
            }
        }

        private int South
        {
            get
            {
                return this.Height - 10;
            }
            set
            {
                South = value;
            }
        }

        private int East
        {
            get
            {
                return this.Width - 10;
            }
            set
            {
                East = value;
            }
        }

        private int West
        {
            get
            {
                return this.Width - this.Width + 10;
            }
            set
            {
                West = value;
            }
        }

        bool inRegion = false;
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
                bool inN = false;
                bool inS = false;
                bool inE = false;
                bool inW = false;

                if (e.X <= West)
                    inW = true;
                if (e.X >= East)
                    inE = true;
                if (e.Y <= North)
                    inN = true;
                if (e.Y >= South)
                    inS = true;

                if (inW)
                {
                    this.Cursor = Cursors.PanWest;
                    inRegion = true;
                }
                if (inE)
                {
                    this.Cursor = Cursors.PanEast;
                    inRegion = true;
                }
                if (inN)
                {
                    this.Cursor = Cursors.PanNorth;
                    inRegion = true;
                }
                if (inS)
                {
                    this.Cursor = Cursors.PanSouth;
                    inRegion = true;
                }
                if (inN && inE)
                {
                    this.Cursor = Cursors.PanNE;
                    inRegion = true;
                }
                if (inN && inW)
                {
                    this.Cursor = Cursors.PanNW;
                    inRegion = true;
                }
                if (inS && inE)
                {
                    this.Cursor = Cursors.PanSE;
                    inRegion = true;
                }
                if (inS && inW)
                {
                    this.Cursor = Cursors.PanSW;
                    inRegion = true;
                }
                else if (!inN && !inS && !inE && !inW)
                {
                    this.Cursor = Cursors.Default;
                    inRegion = false;
                }
                  if (clicked && inRegion)
                  {
                    this.Size = new Size(e.X, e.Y);
                  }
        }

        bool clicked = false;

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (inRegion)
            {
                clicked = true;
            }
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            clicked = false;
        }

User is offlineProfile CardPM
+Quote Post

jay_t55
RE: Resizing Borderless Form
5 Oct, 2008 - 04:36 AM
Post #2

New D.I.C Head
*

Joined: 10 Aug, 2008
Posts: 3

hey i am having the same problem with my borderless C# form except i don't know how to resize it at all can u please maybe post your resize code or something or show me where a really easy to understand tutorial is thanks lots :-)

regards,
jt
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Resizing Borderless Form
5 Oct, 2008 - 04:59 AM
Post #3

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,551



Thanked: 98 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
This thread is almost a year old~

Anyway. You could try to determine the mouse coordinates, and if they're on the edge of the form, change the cursor to the resize cursor.

Then, have MouseDown, MouseMove, and MouseUp events.

In MouseDown, determine the location of the mouse coordinates. If it is in the right place, assign a boolean to true, so you know to resize it in the MouseMove event. MouseUp, simply assign that boolean back to false.

Hope this helps smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 10:32PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month