1. Draw Static and Dynamic Lines | Random Drawing WPF C# HD

25.02.2019
The simplest way to draw static and dynamic lines. Subscribe! ► https://www.youtube.com/c/QuasimodoPrograms?sub_confirmation=1 I will show you how to create a program for random drawing. Let’s look what you can have by the end of this video. Its main function is to draw connected lines randomly. It can also draw multiple lines with one click. The program supports all built-in colors. You are also free to delete lines one by one or clear the entire workspace. The program also allows you to draw with random colors. You can choose different thickness according to your needs. Users are also able to change the background. A very useful feature here is setting transparent background for using the drawing over something else, for example a video. Finally, the workspace extends and reduces automatically according to the window size. In this video, I will show you how to create it step-by-step. So let’s develop it from scratch. Create a new WPF application. I will name it “RanDraw” which stands for “random drawing”. In your grid, create canvas which is a good container for drawing due to using coordinates. You can set its height and width to fix its size. Right in canvas, you can start creating drawing elements. There are a lot of them but I will use only lines. Lines are elements that start at one set of coordinates and go to the second one. Create a line. Set its starting x-coordinate to 10 and starting y-coordinate to 20. X2 and Y2 will both be 50. Set the color of the line in the Stroke property. The line’s thickness is defined by the property StrokeThickness. Let’s set it to 4. Let’s create another line. I will change only Y1. You can also change the other two coordinates. However, another way to change its position is to change the Left property of the Canvas element. We can also make lines with gradients instead of solid colors. To do that, we need to modify stroke. I will set RadialGradientBrush. Don’t forget that you cannot specify the same property twice. In your RadialGradientBrush, set its gradient stops. It will be red in the center but blue on both sides. The proportion depends on the offset. Finally, let’s create a horizontal line. To make a horizontal line, you need to specify different X-coordinates but identical Y-coordinates. For example, let’s take 60. Choose any stroke you like. Again, you can make a gradient but I will stick to a solid brush. When you launch your program, you will notice that after your resize your window, there is some white space. Don’t be confused – it is the result of using canvas with fixed height and width. You can find all the same stuff that you see here on Microsoft’s guide pages. But all this is statics. Not what I want. Not what you want. We need controls to affect the drawing. First of all, give a name to you grid which we will use soon. Secondly, define two rows in your grid. The first one should have auto height because that will be our controls panel. This way the second row will occupy all the space

Похожие видео

Показать еще