Posts

Showing posts from March, 2017

Drawing a dotted circle using C#.NET windows form

Image
Dotted circle can be used for showing circular progress. Here is the code to draw a dotted/dashed circle using C# in windows form application:



usingSystem; usingSystem.Collections.Generic; usingSystem.ComponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Linq; usingSystem.Text; usingSystem.Windows.Forms; usingSystem.Drawing.Drawing2D; usingSystem.Threading; namespaceWindowsFormsApplication1 { publicpartialclassForm1 : Form { publicForm1() { InitializeComponent(); } int angle = 0; int Startangle = 0; privatevoidForm1_Load(object sender, EventArgs e) { } privatevoidpanel1_Paint(object sender, PaintEventArgs e) { //draw a dashed cricle using(Graphics g = panel1.CreateGraphics()) { System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(5, 5, 200, 200); g.SmoothingMode = Smoo…

Write text on HTML5 Canvas using fabricjs

Here is the code to add text on html5 canvas using fabricjs


<canvasid="c"width="600"height="600"></canvas><inputtype="text"class="add-text"><buttonclass="add-text-btn">Add Text</button>

Javascript code:
var canvas =window._canvas =new fabric.Canvas('c'); fabric.Image.fromURL('http://fabricjs.com/assets/printio.png', function(img){ canvas.add(img.scale(1).set({ left:0, top:0, angle:0, selectable:false})); }); canvas.renderAll(); document.querySelectorAll('.add-text-btn')[0].addEventListener('click', function(){ var textToAdd =new fabric.Text(document.querySelectorAll('.add-text')[0].value, { fontFamily:'arial' }); canvas.add(textToAdd); });
Link for jsfiddle https://jsfiddle.net/nvivekgoyal/ybogocmf/