|
1 | | -# DXControls |
| 1 | +# DXControl |
| 2 | + |
| 3 | +- A WinForms hybrid controls that supports Direct2D and GDI+ drawing thanks to [DirectN](https://github.com/smourier/DirectN) and [WicNet](https://github.com/smourier/WicNet). |
| 4 | +- This control is used in [ImageGlass](https://github.com/d2phap/ImageGlass) software since version 9.0. |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +## Resource links |
| 10 | +- Project url: [https://github.com/d2phap/DXControl](https://github.com/d2phap/DXControl) |
| 11 | +- Nuget package: [https://www.nuget.org/packages/D2Phap.DXControl](https://www.nuget.org/packages/D2Phap.DXControl) |
| 12 | +- About: [https://imageglass.org/about](https://imageglass.org/about) |
| 13 | + |
| 14 | +## Features |
| 15 | +- High performance drawing using Direct2D. |
| 16 | +- Names and types are exactly the same as the native concepts of Direct2D (interfaces, enums, structures, constants, methods, arguments, guids, etc...). So you can read the official documentation, use existing C/C++ samples, and start coding with .NET right away. |
| 17 | +- All native COM interfaces are generated as .NET (COM) interfaces, this makes .NET programming easier, but they are not strictly needed. |
| 18 | +- Option to draw by GDI+. |
| 19 | +- Supports animation drawing for both Direct2D and GDI+. |
| 20 | + |
| 21 | +## Requirements: |
| 22 | +- .NET 6.0 |
| 23 | + |
| 24 | +## Installation |
| 25 | +Run the command |
| 26 | +```bash |
| 27 | +Install-Package D2Phap.DXControl |
| 28 | +``` |
| 29 | + |
| 30 | + |
| 31 | +## Example |
| 32 | +Draw 2 rectangles by Direct2D and GDI+ graphics, then animate it to the right side. |
| 33 | + |
| 34 | +```cs |
| 35 | +using D2phap; |
| 36 | + |
| 37 | +// create a WinForms custom control that extends from DXControl |
| 38 | +public class DXCanvas : DXControl |
| 39 | +{ |
| 40 | + private D2D_RECT_F animatableRectangle = new(100f, 100f, new(400, 200)); |
| 41 | + |
| 42 | + public DXCanvas() |
| 43 | + { |
| 44 | + EnableAnimation = true; |
| 45 | + } |
| 46 | + |
| 47 | + // use Direct2D graphics |
| 48 | + protected override void OnRender(DXGraphics g) |
| 49 | + { |
| 50 | + // draw a yellow rectangle with green border |
| 51 | + g.FillRectangle(rectText, _D3DCOLORVALUE.FromCOLORREF(_D3DCOLORVALUE.Yellow.Int32Value, 100)); |
| 52 | + g.DrawRectangle(rectText, _D3DCOLORVALUE.Green); |
| 53 | + } |
| 54 | + |
| 55 | + |
| 56 | + // Use GDI+ graphics |
| 57 | + protected override void OnRender(Graphics g) |
| 58 | + { |
| 59 | + // draw a yellow rectangle with green border |
| 60 | + using var pen = new Pen(Color.Red, 5); |
| 61 | + g.DrawRectangle(pen, new Rectangle((int)rectText.left, (int)rectText.top - 50, (int)rectText.Width, (int)rectText.Height)); |
| 62 | + } |
| 63 | + |
| 64 | + |
| 65 | + // Update frame logics for animation |
| 66 | + protected override void OnFrame(FrameEventArgs e) |
| 67 | + { |
| 68 | + // animate the rectangle to the right |
| 69 | + animatableRectangle.left++; |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +See Demo project for full details. |
| 74 | +``` |
| 75 | + |
| 76 | +## License |
| 77 | +[MIT](LICENSE) |
| 78 | + |
| 79 | +## Support this project |
| 80 | +- [GitHub sponsor](https://github.com/sponsors/d2phap) |
| 81 | +- [Patreon](https://www.patreon.com/d2phap) |
| 82 | +- [PayPal](https://www.paypal.me/d2phap) |
| 83 | +- [Wire Transfers](https://donorbox.org/imageglass) |
| 84 | +
|
| 85 | +Thanks for your gratitude and finance help! |
2 | 86 |
|
3 | | -This project is to create Direct2D control for .NET (WinForms, WPF) thanks to [WicNet](https://github.com/smourier/WicNet). |
|
0 commit comments