Skip to main content

Posts

Showing posts from January, 2015

Flicker free Drawing with WinForm in C#

Just create a C# WinForm Project, Name the form "FormMain" and add a button "buttonRun". Use the code below then you can test it. Main idea is: Draw some image on a bitmap first, then "paste" the bitmap on the graphics of the form. This will reduce the "flicking" of the window. Code: ================================== public partial class FormMain : Form { bool isDrawing = false; Bitmap gBmp = null; Graphics gGraphImg = null; // this variables are just for the Curve int gX = 350, gY = 200; int offX = 180, offY = 100; public FormMain() { InitializeComponent(); CreateBitmapAndGraphic(); } // gBmp & gGraph will be created, when the form is initialized or resized. private void CreateBitmapAndGraphic() { if (gBmp != null) { gBmp.Dispose(); // Dispose it to prevent memory usage too high, when redraw too many times. } gBmp =...