WPF C# Tutorial - Dynamically add and remove items from canvas in visual studio

Опубликовано: 06 Октябрь 2024
на канале: Moo ICT
30,711
379

Source code - https://www.mooict.com/wpf-c-tutorial...
Hi welcome to another fun tutorial from moo ict. in this tutorial I will show you how to add and remove rectangles dynamically from a canvas using wpf and c#. We will be using lots of rectangles to make fun games very soon so its important to understand the attributes of them inside of the canvas element. we will be linking a mouse event directly to the canvas then use c# to find if we have clicked on a empty spot inside of the canvas or have we clicked on a existing rectangle. if we clicked on a rectangle then we will remove it and if not we will spawn a rectangle on the canvas with few extra bonus such as giving it a random colour and a border.

this was a fun tutorial to make and again this is a quick tutorial that you can use just to the hang of it before we move into making games.

Hope you enjoy it and happy programming.