Click here to Skip to main content
15,885,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey there,

I want to create a form which has only the windows-aero border (in win 10 the blue line with the shadow) without the title bar.
It is very important to keep the resizing function.

My problem is the white line at the top which you can see on this screenshot:
problem.PNG - Google Drive[^]


Please help me

Best Regards
Tobias Wälde

What I have tried:

this.BorderStyle = FormBorderStyle.SizableToolWindow;
this.ControlBox = false;
this.Text = String.Empty;
Posted
Updated 16-Nov-21 22:57pm

Winform is too hard to do like that. but Without Shadow it's possible, May be - You need to create your own custom shadow.
by convert yourWinform to control libary
then use WindowsFormsIntegration and try it in WPF, if its possible
 
Share this answer
 
v2
Comments
Tobias Wälde 1-Oct-16 18:17pm    
thanks, helpful answer, but unfortunatel i can't develop in wpf, maybe i will try a tutorial of buy a book :D
I haven't done WinForms in a long time, but try FormBorderStyle.FixedSingle instead.

EDIT =============================

You can always use interop and use the Win32 API to set the window style. It's kind of involved, but it's entirely possible do do. Keep in mind that once you take off the titlebar, the user can't move the window unless you write code to allow it (if I recall correctly, the API method you're interested in is CreateWindowEx). Check out www.pinvoke.net - they have prototypes and constants available fot support most Windows API methods.

What you're trying to do does not comply with the Windows UI best practice, so expect to have to write a bunch of weird code to realize your dream. It has been my experience that a non-standard UI are wasted on your typical user, who simply want to get the job done and close the app. Just sayin...
 
Share this answer
 
v3
Comments
Tobias Wälde 29-Sep-16 16:28pm    
thanks for your fast answer.
first, i have tried every formborderstyle and creating own borders...
then, fixed windows are useless in my project.

thanks anyway
#realJSOP 30-Sep-16 10:32am    
I updated my answer.
Tobias Wälde 30-Sep-16 11:05am    
thanks, very helpful
About the best you can do is to set the ControlBox property to false, and the Text property to an empty string. It leaves a "short" bar at the top (about 5 pixels) but it remains usable and sizeable.
 
Share this answer
 
Comments
Tobias Wälde 29-Sep-16 16:24pm    
first, thanks for your fast answer.

this bar is very very annoying, because i want to add an icon and change the backcolor-property...

is there any possibility to draw a panel or sth like this over this bar?
OriginalGriff 30-Sep-16 5:43am    
You can...but it's not nice.
See here for the background and some warnings:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd162743(v=vs.85).aspx
And have a look at this:
http://www.codeproject.com/Articles/55180/Extending-the-Non-Client-Area-in-Aero
for an example of doing something like what you want.
Do be aware that Aero (Win7) and Win10 may not work quite the same, so be prepared to do some experimenting.
Tobias Wälde 30-Sep-16 6:40am    
thanks, i'm going to try this
OriginalGriff 30-Sep-16 6:43am    
You're welcome!
check this c# - How to move and resize a form without a border? - Stack Overflow[^]

tested it, working..
not sure it will fit your requirement. give a try.
 
Share this answer
 
Comments
Tobias Wälde 30-Sep-16 6:41am    
thanks, moving the form is no problem
but i want to keep the original windows border to have the shadow around the form
Karthik_Mahalingam 30-Sep-16 6:46am    
check this
http://stackoverflow.com/a/19164145/1147428
Here's one solution that results in no Form Border, and renders the Form re-sizable:

1. set 'FormBorderStyle to 'FixedToolWindow, and hide the other usual stuff.

2. this example does not include code for moving the Form; that's left for you to write.
C#
using System;
using System.Drawing;
using System.Windows.Forms;

namespace YourNameSpace
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        const int MoveZoneSize = 16;
        const int ReSizeThreshold = 4;

        private Rectangle scrnBounds;
        private Rectangle moveZone;

        // for use when making the Form movable
        private int mdx, mdy, dx, dy;
        
        private bool mouseIsUp = true;

        private void Form1_Load(object sender, EventArgs e)
        {
            UpdateScreenSize();
        }

        private void UpdateScreenSize()
        {
            moveZone = new Rectangle(0,0,MoveZoneSize,MoveZoneSize);
            scrnBounds = this.DisplayRectangle;
            moveZone.Offset(scrnBounds.Right - MoveZoneSize, scrnBounds.Bottom - MoveZoneSize);    
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (ModifierKeys == Keys.Alt && e.KeyCode == Keys.Escape)
            {
                this.MouseMove -= Form1_MouseMove;
                this.Close();
            }
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (moveZone.Contains(e.Location))
            {
                mdx = e.X;
                mdy = e.Y;

                this.MouseMove += Form1_MouseMove;
            }
        }
        
        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            this.MouseMove -= Form1_MouseMove;
            UpdateScreenSize();
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            dx = Math.Abs(e.X - mdx);
            dy = Math.Abs(e.Y - mdy);

            if (dx < ReSizeThreshold && dy < ReSizeThreshold) return;

            this.Width = e.X;
            this.Height = e.Y;
        }
    }
}
Notes:

1. a Rectangle (square) 'moveZone is created that encloses an area of the bottom-right of the Form of size 'MoveZoneSize.

2. a threshold for "dampening" mouse move events 'ReSizeThreshold is defined. this may make the resizing of the Form visually smoother.

3. mouse down is detected and if the mouse down location is in the 'moveZone bounds, the mouse move handler is wired up to the Form.

4. in the mouse move event, the delta of mouse movement is calculated, and if it's smaller than 'ReSizeThreshold the method exits. if the delta is larger, then the Form is resized, and the current bounds of the form and the bounds of the 'moveZone rectangle are re-calculated.

Other comments:

1. depending on computer, graphics card, memory, etc., and the possible complexity of Form elements and their use of Anchor and Dock, Padding, Margin, etc. Properties: the visual quality the Form resize by mouse at run-time ... may vary. Of course, you should set the Form's 'DoubleBuffered Property to 'true.
 
Share this answer
 
Comments
Tobias Wälde 30-Sep-16 6:42am    
thanks, but it doesn't remove this annoying white bar on the top...
BillWoodruff 30-Sep-16 7:11am    
It works on my machine running Win 10. Check to make sure you have set:

1. FormBorderStyle to 'FixedToolWindow
2. ShowIcon to 'None
3. Padding to 0,0,0,0
4. SizeGripStyle to 'None

Have you customized Window appearance in Win 10 ?

cheers, Bill
Member 12239906 29-Nov-18 1:49am    
It doesn't work yet
BillWoodruff 29-Nov-18 3:35am    
Then open a new question, post your code, and clearly describe what is not working.

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