8 Replies - 1709 Views - Last Post: 05 May 2013 - 08:47 AM Rate Topic: -----

#1 volvagia224  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-May 13

Resizing a Borderless Form?

Posted 04 May 2013 - 07:15 PM

Hello,

I've been searching around for a solution or a tutorial on how to do this but haven't found a simple explanation for it or how to do it.

I'm looking to apply a re-sizing ability to a border-less form, normally, with the default settings applied to a border-less form, this isn't possible, and I really have 0 idea how to go about doing it.

The exact functionality I'm looking for would be being able to put your mouse over any edge of the application and be able to shrink/pull it to your desired size. This includes diagonals.

Could anyone give me any insight on where to start with this? When googling "Resize borderless form c#" I don't get many clear path results, especially for someone just learning the application language like myself.

All help would be appreciated, thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Resizing a Borderless Form?

#2 volvagia224  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-May 13

Re: Resizing a Borderless Form?

Posted 04 May 2013 - 07:30 PM

Forgot to include this - this is my code so far;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        Point lastClick;

        public Form1()
        {
            InitializeComponent();
            this.DoubleBuffered = true;;
        }

        private void closeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void alwaysOnTopToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.TopMost = alwaysOnTopToolStripMenuItem.Checked;
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            lastClick = e.Location;

        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Left += e.X - lastClick.X;
                this.Top += e.Y - lastClick.Y;
            }
        }
    }
}


Was This Post Helpful? 0
  • +
  • -

#3 Janzerfaust  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-January 13

Re: Resizing a Borderless Form?

Posted 05 May 2013 - 01:33 AM

Did your form fly all over the place when you moved your cursor left button down? Because Control.Left property as in MSDN: "Gets or sets the distance, in pixels, between the left edge of the control and the left edge of its container's client area." This is the same for the Right, Top and Bottom properties as well.

You should implement some sort of margins to the form if you want it to behave like a form with borders. And do checks if the cursors is over the lower margin or right margin.


Feel free to strike me down if I'm wrong.
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5467
  • View blog
  • Posts: 11,745
  • Joined: 02-June 10

Re: Resizing a Borderless Form?

Posted 05 May 2013 - 06:53 AM

Personally I'd suggest you get with the times and forget about doing this as old-fashioned WinForms. If you do this as a WPF project you'll have a lot more control over the presentation.

A WPF window separates the border style from the resizeablity. So you can pick any window type and choose whether or not you can resize it.

Attached Image

Was This Post Helpful? 1
  • +
  • -

#5 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3331
  • View blog
  • Posts: 11,278
  • Joined: 12-December 12

Re: Resizing a Borderless Form?

Posted 05 May 2013 - 07:55 AM

The reason you are struggling to find information about this is that you are attempting to circumvent the standard Windows GUI behaviour. How often have you come across a window that you could resize that didn't have a border?

Most things are possible so, if you persist, you may be able to get this to work. But why struggle against standard, and expected, behaviour? Give the form a border or consider WPF as suggested by tlhIn`toq.
Was This Post Helpful? 0
  • +
  • -

#6 volvagia224  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-May 13

Re: Resizing a Borderless Form?

Posted 05 May 2013 - 08:08 AM

View PosttlhIn`toq, on 05 May 2013 - 06:53 AM, said:

Personally I'd suggest you get with the times and forget about doing this as old-fashioned WinForms. If you do this as a WPF project you'll have a lot more control over the presentation.

A WPF window separates the border style from the resizeablity. So you can pick any window type and choose whether or not you can resize it.



Interesting, sorry like I said I'm very new to c#, I'm learning how to do this out of just pure curiosity - my main focus has always been server side scripting (PHP, Ruby on Rails) and such and haven't really looked into languages like C# other than C in college and a tiny portion of C++.

I'll look into using these, I never knew it actually had a lot more control than the WinForms or even which one was older than the other. Thank-you for steering me in the correct direction.

View Postandrewsw, on 05 May 2013 - 07:55 AM, said:

The reason you are struggling to find information about this is that you are attempting to circumvent the standard Windows GUI behaviour. How often have you come across a window that you could resize that didn't have a border?

Most things are possible so, if you persist, you may be able to get this to work. But why struggle against standard, and expected, behaviour? Give the form a border or consider WPF as suggested by tlhIn`toq.



I'm curious because I've seen .NET applications providing this functionality, trying to re-create functionality in other programs is how I generally learned the basics of creating applications in my normal environment and expanding upon things once I understood how to do it. I'm sorry if this doesn't compel to your standards of learning or if you think that what I'm trying to do is needless in terms of application behavior, but if it's possible and it looks nice - I'd rather learn how to do it in case I ever wanted to implement it.

View PostJanzerfaust, on 05 May 2013 - 01:33 AM, said:

Did your form fly all over the place when you moved your cursor left button down? Because Control.Left property as in MSDN: "Gets or sets the distance, in pixels, between the left edge of the control and the left edge of its container's client area." This is the same for the Right, Top and Bottom properties as well.

You should implement some sort of margins to the form if you want it to behave like a form with borders. And do checks if the cursors is over the lower margin or right margin.


Feel free to strike me down if I'm wrong.


No, it doesn't fly around the place. Only on mouse click over the application window will it allow you to drag the application window around. Releasing the button would leave the window fixed to the place you left it. I was surprised when it worked myself, probably since I'm new at this still though. :)
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5467
  • View blog
  • Posts: 11,745
  • Joined: 02-June 10

Re: Resizing a Borderless Form?

Posted 05 May 2013 - 08:10 AM

If you insist on doing Winforms you could follow this logic:

  • Click a button to make resizable: that changes the form to have a border
  • user resizes as expected
  • Click the [RESIZE] button a second time to
  • Get the dimensions
  • turn off the border
  • Set to saved dimensions

Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3331
  • View blog
  • Posts: 11,278
  • Joined: 12-December 12

Re: Resizing a Borderless Form?

Posted 05 May 2013 - 08:34 AM

Quote

I'm sorry if this doesn't compel to your standards of learning or if you think that what I'm trying to do is needless in terms of application behavior, but if it's possible and it looks nice - I'd rather learn how to do it in case I ever wanted to implement it.

I am simply trying to forewarn you that implementing non-standard behaviour can be challenging, and can confuse your user, who is not expecting this behaviour.

tlhIn`toq has suggested a good compromise.
Was This Post Helpful? 0
  • +
  • -

#9 volvagia224  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-May 13

Re: Resizing a Borderless Form?

Posted 05 May 2013 - 08:47 AM

View PosttlhIn`toq, on 05 May 2013 - 08:10 AM, said:

If you insist on doing Winforms you could follow this logic:

  • Click a button to make resizable: that changes the form to have a border
  • user resizes as expected
  • Click the [RESIZE] button a second time to
  • Get the dimensions
  • turn off the border
  • Set to saved dimensions


Looking into WPF now actually, now that I know it's actually the more modern way to do things. Glad I found this out before I really got deep into things. Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1