Click here to Skip to main content
15,942,710 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
please help me i want to make a clean windows form design with no border and lines on it also it have to be resizable and movable.
Posted
Comments
Sergey Alexandrovich Kryukov 26-May-15 17:02pm    
What have you tried so far?
—SA

1 solution

Borderless form is simple:
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.formborderstyle%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/hw8kes41%28v=vs.110%29.aspx[^] (use System.Windows.Forms.FormBorderStyle.None).

Now, how to implement move and resize operations? Well, there is no such thing as miracle. By removing borders, you lost non-client form areas, so you have to emulate similar behavior on the client area of the window.

Here is what you can do:
You can handle mouse events on the form itself, but you could better add some controls representing title bar and borders to put this functionality on them. Also, alternatively, you can adjust the client area size by using Control.SetClientSizeCore, as explained in my recent answer:
how can I change the thickness of a form border[^].

No matter what control you use, for move or resize operation, you do the same things by handling the events MouseDown, MouseUp and MouseMove, or, better yet, by overriding the Control's virtual methods OnMouseDown, OnMouseUp and OnMouseMove:
https://msdn.microsoft.com/en-us/library/system.windows.forms.control%28v=vs.110%29.aspx[^].

Have some flags, members of your window, such as modeMode, resizeMode or bitwise combinations in one byte. On "down" event, set move or resize mode. In case of resizing, you will also need to capture mouse to the form: https://msdn.microsoft.com/en-us/library/ms171545%28v=vs.110%29.aspx[^].

Capturing mouse is important because your next step, move of the mouse, may move the mouse pointer outside of the form area, but you still need to handle "move" and "up" events in your form.

Then, on mouse "move" event, perform resize or move, and on "up" event stop capturing mouse and go back to "normal" mouse mode. It will require some logic, so be patient and thorough. One more detail: you may want to work in screen coordinates instead of control coordinates, or in form coordinates (which is another control), instead of tool control coordinates. This is how:
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.pointtoscreen%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.pointtoclient%28v=vs.110%29.aspx[^].

That's all.

—SA
 
Share this answer
 
Comments
Sascha Lefèvre 26-May-15 22:39pm    
+5
Sergey Alexandrovich Kryukov 27-May-15 0:04am    
Thank you, Sascha.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900