Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WFoS - WinForms on Steroids

Version: 1.0.0

RU

Винформс на стероидах - это

  1. Доступ к множеству событий формы и системы
  2. Взаимодействие с другими окнами
  3. Возможность блокировать нежелательное вмешательство в форму
  4. Работа как на современном .NET 10+, так и на устаревшем .NET 4.8

В отличии от многих других библиотек, WFoS не предоставляет никаких новых контролов, а лишь расширяет возможности самой формы. Используйте любые другие библиотеки контролов вместе с WFoS!

Некоторые возможности

  • Регистрация и обработка горячих клавиш
  • Запрет скриншотов
  • Продолжение работы без спящего режима \ выключения дисплея
  • Получение данных о заряде и батарее
  • Перетаскивание формы мышью
  • Мигание иконкой на панели задач
  • Принудительная активация окна на первый план
  • Прогрессбар в иконке на панели задач
  • Запрет перерисовки
  • Прозрачность с альфа-ключом по цвету одновременно
  • Включение возможностей Windows 10+ (акрилового блюра, тёмной темы для заголовка)
  • Обмен текстовыми сообщениями между формами и окнами
  • Запрет перетаскивания формы
  • Реакция на системные события: изменение времени, настроек, подключение устройств и т.д.
  • Проверка запуска от имени админа и перезапуск с ними

Для кого?

Для тех, кто:

  1. вынужден долго гуглить решение проблем через WinAPI, читать документацию и pinvoke
  2. по каким-то причинам не хочет или не может использовать WPF\Avalonia\MAUI\Uno
  3. работает на Windows 10+ и хочет использовать новые возможности

Как начать?

  1. Поставьте зависимость от библиотеки WFoS
  2. Унаследуйте формой класс WFoS.ExtendedForm, вместо System.Windows.Form
  3. Теперь вы можете использовать все возможности WFoS!

Примеры

Пример 1. Подписка на новые события

public partial class Form1 : ExtendedForm
{
	protected override void OnHandleCreated(EventArgs e)
	{
		// ваши подписки на события

		base.OnHandleCreated(e);
	}
}

Обратите внимание, что подписываться из конструктора НЕ нужно!

Пример 2. Ловим события перерисовки

public partial class Form1 : ExtendedForm
{
	protected override bool UseExtendedPaintEvents = true;
	
	protected override void OnHandleCreated(EventArgs e)
	{
		this.PaintMessageReceived += (_, _) => Debug.WriteLine("WM_PAINT");
		this.OnEraseBackground += (_, _) => Debug.WriteLine("WM_ERASEBKGND");

		base.OnHandleCreated(e);
	}
}

События вроде WM_PAINT и WM_ERASEBKGND поступают слишком часто, поэтому их получение нужно предварительно активировать.

Пример 3. Взаимодействие с внешним миром

_ = Process.Start("calc");
Thread.Sleep(2000);
var calc = NativeWindowMethods.FindWindow("Калькулятор");
var rect = NativeWindowMethods.GetWindowRectangle(calc);
Debug.WriteLine(rect);

Вместе с ExtendedForm в библиотеке вам доступны несколько классов-хелперов:

  • NativeWindowMethods - работа с окнами
  • NativeSystemMethods - работа с системой
  • NativeDrawingMethods - работа с графикой
  • NativeInputMethods - работа с вводом
  • NativeTextBoxMethods - работа с текстовыми полями

Смотрите проекты

  • Simple WFoS app (.NET 10+) - демонстрация всех событий
  • Legacy WFoS app (.NET 4.8) - небольшая демонстрация запуска на фреймворке

Частые вопросы

Не срабатывает событие

Убедитесь в том, что вы подписались на событиями не из конструктора. Для специфических свойств нужно активировать свойства. Некоторые WM могут не приходить по не зависящим от библиотеки причинам.

EN

Winforms on steroids is

  1. Access to a variety of form and system events
  2. Interaction with other windows
  3. The ability to block unwanted interference in the form
  4. Work like a modern one.NET 10+, and on legacy .NET 4.8

Unlike many other libraries, WFOs does not provide any new controls, but only expands the capabilities of the form itself. Use any other control libraries with WFOs!

Some possibilities

  • Registration and processing of hotkeys
  • Prohibition of screenshots
  • Continued operation without sleep mode / turning off the display
  • Receiving data about the charge and battery
  • Dragging the shape with the mouse
  • Flashing of the icon on the taskbar
  • Forced activation of the window to the foreground
  • Progress bar in the icon on the taskbar
  • Prohibition of redrawing
  • Transparency with alpha key by color at the same time
  • Enabling Windows 10+ features (acrylic blur, dark title theme)
  • Text message exchange between forms and windows
  • Prohibition of dragging the form
  • Reaction to system events: changing time, settings, connecting devices, etc.
  • Check the startup on behalf of the admin and restart with them

For whom?

For those who:

  1. have to Google problem solving through WinAPI for a long time, read the documentation and pinvoke
  2. for some reason, he does not want or cannot use WPF\Avalonia\MAUI\Uno
  3. Works on Windows 10+ and wants to use new features

How do I get started?

  1. Make a dependency on the WFOs library
  2. Inherit the form class WFOs.ExtendedForm, instead of System.Windows.Form
  3. Now you can use all the features of WFOs!

Examples

Example 1. Subscribing to new events

public partial class Form1 : ExtendedForm
{
protected override void OnHandleCreated(EventArgs e)
{
// your event subscriptions

		base.OnHandleCreated(e);
	}
}

Please note that you do NOT *** need to subscribe from the constructor!

Example 2. Catching redraw events

public partial class Form1 : ExtendedForm
{
	protected override bool UseExtendedPaintEvents = true;
	
	protected override void OnHandleCreated(EventArgs e)
	{
		this.PaintMessageReceived += (_, _) => Debug.WriteLine("WM_PAINT");
		this.OnEraseBackground += (_, _) => Debug.WriteLine("WM_ERASEBKGND");

		base.OnHandleCreated(e);
	}
}

Events like WM_PAINT and WM_ERASEBKGND are received too often, so they must be activated beforehand.

Example 3. Interaction with the outside world

_ = Process.Start("calc");
Thread.Sleep(2000);
var calc = NativeWindowMethods.FindWindow("Calculator");
var rect = NativeWindowMethods.GetWindowRectangle(calc);
Debug.WriteLine(rect);

Along with the ExtendedForm, several helper classes are available in the library.:

  • NativeWindowMethods - working with windows
  • NativeSystemMethods - working with the system
  • NativeDrawingMethods - working with graphics
  • NativeInputMethods - working with input
  • NativeTextBoxMethods - working with text fields

See the projects

  • Simple WFoS app (.NET 10+) - demonstration of all events
  • Legacy WFOs app (.NET 4.8) - a small demo of running on the framework

Frequently asked questions

The event is not triggered

Make sure that you have subscribed to events that are not from the constructor. For specific properties, you need to activate the properties. Some WMS may not arrive for reasons beyond the control of the library.

About

WinForms in Steroids - extended Forms and WinAPI support

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages