d2phap / DXControl

🖌️ A WinForms hybrid control that supports Direct2D and GDI+ drawing
MIT License
24 stars 5 forks source link
csharp direct2d direct2d-bitmap direct2d-demo direct2d1 directwrite directx dotnet dotnet-core gdi-plus wic win2d windows-imaging-component winforms

D2Phap.DXControl

Nuget

Resource links

Features

Requirements:

Installation

Run the command

Install-Package D2Phap.DXControl

Example

Draws a rectangle, then moves it to the right side.

using D2Phap;

// create a WinForms custom control that extends from DXControl
public class DXCanvas : DXControl
{
    private RectangleF animatableRectangle = new(100, 100, 400, 200);

    public DXCanvas()
    {
        EnableAnimation = true;

        // use Direct2D
        UseHardwareAcceleration = true;
    }

    protected override void OnRender(IGraphics g)
    {
        // draw a yellow rectangle with green border
        g.FillRectangle(rectText, Color.FromArgb(100, Yellow));
        g.DrawRectangle(rectText, Color.Green);
    }

    // Update frame logics for animation
    protected override void OnFrame(FrameEventArgs e)
    {
        // animate the rectangle to the right
        animatableRectangle.left++;
    }
}

See Demo project for full details.

License

MIT

Support this project

Thanks for your gratitude and finance help!