Category / Section
How to comment out a section of code in WinForms SyntaxEditor (EditControl)?
1 min read
Hide the text
It is possible to comment out a section of code by inserting the "//" (using C# as an example) at the beginning of each line in that particular section. The interop call LockWindowUpdate can be used to pause and resume painting while the lines are being commented.
C#
// Lock Painting LockWindowUpdate(this.editControl1.Handle.ToInt64()); for (int i=1; i<=this.editControl1.PhysicalLineCount; i++) { this.editControl1.InsertText(i,1,"// "); } // Resume Painting LockWindowUpdate(0);
VB
' Lock Painting LockWindowUpdate(Me.editControl1.Handle) Dim i As Integer For i = 1 To Me.editControl1.PhysicalLineCount Me.editControl1.InsertText(i, 1, "// ") Next i ' Resume Painting LockWindowUpdate(IntPtr.Zero)