© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago
Bớp

draw board caro

Hi! I want when the user drags up, down, left or right, it will draw more! I am new to C# (MAUI). Below is the code for drawing the mechanical table
namespace CaroGame.Source;

internal class Board : IDrawable {
    private readonly float cellSize = 100f;
    
    public void Draw(ICanvas canvas, RectF rect) {
        canvas.StrokeColor = Colors.Black;
        canvas.StrokeSize = 1;

        int numberOfLinesHorizontal = (int)Math.Ceiling(rect.Height / cellSize);
        int numberOfLinesVertical = (int)Math.Ceiling(rect.Width / cellSize);

        for (int i = 0; i <= numberOfLinesHorizontal; i++) {
            float y = i * cellSize;
            canvas.DrawLine(rect.Left, y, rect.Right, y);
        }

        for (int j = 0; j <= numberOfLinesVertical; j++) {
            float x = j * cellSize;
            canvas.DrawLine(x, rect.Top, x, rect.Bottom);
        }
    }
}
namespace CaroGame.Source;

internal class Board : IDrawable {
    private readonly float cellSize = 100f;
    
    public void Draw(ICanvas canvas, RectF rect) {
        canvas.StrokeColor = Colors.Black;
        canvas.StrokeSize = 1;

        int numberOfLinesHorizontal = (int)Math.Ceiling(rect.Height / cellSize);
        int numberOfLinesVertical = (int)Math.Ceiling(rect.Width / cellSize);

        for (int i = 0; i <= numberOfLinesHorizontal; i++) {
            float y = i * cellSize;
            canvas.DrawLine(rect.Left, y, rect.Right, y);
        }

        for (int j = 0; j <= numberOfLinesVertical; j++) {
            float x = j * cellSize;
            canvas.DrawLine(x, rect.Top, x, rect.Bottom);
        }
    }
}

Thanks!
Screenshot_2024-06-14_at_11.39.31.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Draw border for borderless form...
C#CC# / help
3y ago
❔ Wpf chess board problem
C#CC# / help
4y ago
Draw polygons on a Livecharts2 chart
C#CC# / help
7mo ago