锐英源软件
第一信赖

精通

英语

开源

擅长

开发

培训

胸怀四海 

第一信赖

当前位置:锐英源 / 开源技术 / nVLC / WinForm
服务方向
人工智能数据处理
人工智能培训
kaldi数据准备
小语种语音识别
语音识别标注
语音识别系统
语音识别转文字
kaldi开发技术服务
软件开发
运动控制卡上位机
机械加工软件
软件开发培训
Java 安卓移动开发
VC++
C#软件
汇编和破解
驱动开发
联系方式
固话:0371-63888850
手机:138-0381-0136
Q Q:396806883

WinForm Extended


Introduction

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:

  • Paint on the title bar and form Frame
  • Attach a Form to the desktop, like Windows Vista and 7 sidebar
  • Set the Form in Full Screen mode (covers everything including task bar)
  • Make the Form Unmovable
  • Make the Form Unsizable (Even when FormBorderStyle is not Fixed)
  • Get the KeyState (Up and Down / Toggled and Untoggled) at any moment
  • Disable the Close Button of the Window's Title Bar.

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.

Using the Code

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:

  • Add the binary provided on the top of the article to your project. You do this by going to Solution Explorer -> Your Project -> Right-Click References... -> Add Reference... -> Browse -> Locate and Select theFormEx.dll
  • Alternatively, you can include the project with source code (also provided) and Add the Reference the same way as above, but select Projects instead of Browse.

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:

  • KeyState GetKeyState(Keys key) - The return type as an enum that has two possible values: 0 - KeyState.Up and 1 - KeyState.Down. The parameter is the standard Keys enumprovided by Windows Forms
  • KeyValue GetKeyValue(Keys key) - The return type as an enum that has two possible values: 0 - KeyValue.Untoggled and 1 - KeyValue.Toggled. The parameter is the standard Keys enum provided by Windows Forms

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()

友情链接
版权所有 Copyright(c)2004-2021 锐英源软件
公司注册号:410105000449586 豫ICP备08007559号 最佳分辨率 1024*768
地址:郑州大学北校区院(文化路97号院)内