Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
how do i add a button side of close button in C# form when form boder style is sizable...
like microsoft office word ... ( add undo ,...)
Posted
Comments
BillWoodruff 15-Mar-14 5:36am    
If you are speaking of adding a Button to the TitleBar area of a Windows Form (the non-client area), then you are going to have to get involved with Windows API code, and a custom WndProc. Are you ready to do that ? If you are fairly new to .NET, I'd suggest you forget that idea, and just make a custom Form with no TitleBar, and add your own custom buttons (or, a ToolStrip containing them) to it to close the Form, minimize/maximize the Form, and do your custom stuff.
ZurdoDev 15-Mar-14 8:56am    
I think you should post as solution.
Sergey Alexandrovich Kryukov 16-Mar-14 14:04pm    
Agree, but there are at least two more approaches I explained in my answer, please see:
—SA

Bill explained one way of solving such problems; this way can certainly work. However, it will require using raw Windows API, which in turn, will require the use of P/Invoke and badly compromise platform compatibility of your application. So, my first and and main advice would be: consider giving up this additional non-client feature and limiting your application by standard non-client behavior provided by .NET FCL.

There is one more, alternative approach. You can create the application form or window without any non-client areas. (Sorry, I don't know which UI library/framework you are using, so you have to look at documentation to find out how to do it; it depends on your application type and is easy to do.) And then you have to simulate all the non-client elements in the client area. It can include: title bar, system icon (system menu area), title bar icons, resize control areas and border, implement windows move (and optionally resize) behavior.

—SA
 
Share this answer
 
Comments
pasztorpisti 16-Mar-14 23:00pm    
+5, that's it. I've used the second approach many many times (win32 api, and dlephi also had such a feature). Messing around with the titlebar is not a good idea especially nowdays that windows has many skins, not to mention the platform independence of your C# code. Messing with hooks is a bad idea in many caseses especially when it comes to customizing the looks of controls, unfortunately windows/comctrls weren't really invented for this.
Sergey Alexandrovich Kryukov 16-Mar-14 23:12pm    
Thank you very much.
—SA
Joezer BH 17-Mar-14 4:06am    
5ed!
Sergey Alexandrovich Kryukov 17-Mar-14 10:08am    
Thank you.
—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