精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
In this article, I present you with an extended version Windows Form. It has a few more features than regular Forms provided by the .NET Framework.
Originally, I implemented these features separately to help MSDN users on their requests. So I've decided to put it all together and build a Form to present in this article.
The additional features of the FormEx are:
All of these features, except getting the key state, are available through the designer, so it's very easy to use as I'll explain below.
As I mentioned, it's very easy to use the features. In the sample project provided, you can see everyone of them just as the screenshot. We will go through them one by one, but first, let's see how we use the form.
You have two ways to add the new Form to your solution:
When you have done that, you're ready to start coding. First select a form from your project and edit its source code. You'll have to modify it to inherit from FormEx instead of Form:
using FormExNS; namespace TestProject { public partial class TestForm : FormEx {
Now, to the features:
1 . Paint on the title bar and form Frame:
As you can see in the screenshot, I drew over the title bar. To do that, I implemented a new event:PaintFrameArea. All you have to do is go to the Events in the designer and create an event handler just the same way you would do with the Paint method. It works exactly the same and the Graphics object is set to cover the whole window minus the client area.
The drawing of this is done after Windows draws the window in its themed style, so you might experience some flicker while resizing. You should also not draw over the ControlBox because it will cover the minimize, maximize and close buttons (but not forever, if you mouse over them, they will reappear).
2 . Attach the Form to the Desktop:
I added a new property called DesktopAttached. By setting this property to true, the window will get "glued" to the desktop and will not show on the task bar. It will be below all regular windows, much like windows side bar.
3. Full Screen Mode:
I added a new property called FullScreen. By setting this property to true, the window will take all the area of the current monitor and will be always over the taskbar and any other non TopMostwindows. Note that if you use this in combination with DesktopAttached, the Window will take the whole screen, but will remain under every window and the taskbar. Also note that the window will remember its previous state automatically when you set FullScreen to false again.
4.Movable:
I added a new property called Movable. By setting this property to false, the window will no longer be movable. The user won't be able to move the window by dragging it through the title bar. When the form is unmovable, it also implicates that it's not Sizable either
5.Sizable:
I added a new property called Sizable. By setting this property to false, the window will no longer be sizable, despite its FormBorderStyle being set to Sizable. This might be useful if you want the look of a sizable form, but want it fixed. This property has no interference with the Movable property.
6.Get Key State:
I added two new methods for the Form that are related to the KeyState. They are:
7.CloseButton:
I added a new property called CloseButton. By setting this property to false, the window close button will be grayed out and the user will no longer be able to close the form. The form is still closable if: The parent form gets closed, the task manager closes the application, windows shuts down or there is a call to Application.Exit()