diff --git a/BlazorCanvas/BlazorCanvas/Pages/Index.razor b/BlazorCanvas/BlazorCanvas/Pages/Index.razor
index d1aeb09..ab4bf37 100644
--- a/BlazorCanvas/BlazorCanvas/Pages/Index.razor
+++ b/BlazorCanvas/BlazorCanvas/Pages/Index.razor
@@ -8,33 +8,38 @@
@inject IJSRuntime jsRuntime
-
+
-
CanvasDrawing
-
@code {
ElementReference divCanvas;
- BECanvasComponent myCanvas;
- Canvas2DContext currentCanvasContext;
+ BECanvasComponent myCanvas = new();
+ Canvas2DContext? currentCanvasContext;
- private string currentcolor { get; set; }// = "Black";
+ private string currentcolor { get; set; } = "Black";
+ private int pointsize { get; set; } = 1;
- async void OnMouseMove(MouseEventArgs eventArgs)
- {
+ async void OnMouseMove(MouseEventArgs eventArgs) {
double mouseX = 0, mouseY = 0;
if (eventArgs.Buttons == 0)
@@ -49,14 +54,11 @@
mouseX = eventArgs.ClientX - offsets.Value
("offsetLeft");
mouseY = eventArgs.ClientY - offsets.Value("offsetTop");
}
+ if (currentCanvasContext is null)
+ currentCanvasContext = await myCanvas.CreateCanvas2DAsync();
- currentCanvasContext = await myCanvas.CreateCanvas2DAsync();
-
- //await currentCanvasContext.ClearRectAsync(0, 0, 800, 800);
await currentCanvasContext.SetFillStyleAsync(currentcolor);
- await currentCanvasContext.FillRectAsync(mouseX, mouseY, 1, 1);
- //await currentCanvasContext.StrokeTextAsync("ClientX: " + mouseX +
- // " Client Y: " + mouseY, 20, 20);
+ await currentCanvasContext.FillRectAsync(mouseX, mouseY, pointsize, pointsize);
}
}