Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, September 6, 2006 3:59 AM
using " FormBorderStyle = FormBorderStyle.None; ", I can not change the location of the form when running...
Is there any way to drag the form around as I like?
Thanks!
All replies (6)
Wednesday, September 6, 2006 12:37 PM ✅Answered
indeed you can do that. to minimize:
this.WindowState = FormWindowState.Minimize;
to maximize:
this.WindowState = FormWindowState.Maximize;
Wednesday, September 6, 2006 1:49 PM ✅Answered
Take a look at the examples on my site:
http://www.dotnetrix.co.uk/misc.html
- Move a borderless form.
- An example of a moveable/resizable shaped form. (This one adds a System Menu to the Taskbar Button)
Wednesday, September 6, 2006 4:15 AM
you would have to change the FormBorderStyle in this case to do so, if its set to none then it won't allow you to move the form
closest one probably is the SizableToolWindow however it wont appear in the taskbar or when you do the ALT + TAB combo to look at your current running programs
Wednesday, September 6, 2006 4:37 AM
Well, may I add buttons to the form and try the event handler to define the maxmize/minimize/close
functions?
Friday, November 3, 2006 4:11 AM | 2 votes
Oh, I find the way to move the form with "FormBorderStyle" is "None"
public partial class Form1 : Form
{
// create a new object of Point, it will be used as a variable later
private Point mouse_offset;
public Form1()
{
InitializeComponent();
}
//the Event of MouseDown, record the offset of the mouse
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
mouse_offset = new Point(-e.X, -e.Y);
}
//the Event of MouseMove, move the form if user click the left button of the mouse
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouse_offset.X, mouse_offset.Y);
this.Location = mousePos; //move the form to the desired location
}
}
}
And for the minimize and maximize and close buttons, user can add buttons on the form, then the text on the buttons could be "--" "X"... which will look like the original buttons. To achieve the required function, just use the statements here:
this.WindowState = FormWindowState.Minimized;
this.WindowState = FormWindowState.Maximized;
this.Close();
So it's OK now, we can create a form with the shape we'd like using the pre-made background image and set the transparent key to the background color of the image:)
Enjoy DIY!!
Monday, January 11, 2010 4:00 AM | 1 vote
Thanks Packey for sharing your own answer. Your answer helped me a lot when im struggling with the same scenario right now (about 4 years after your post).