You can use SuspendPainting() to supsend GUI updates and SelectedView.Selection.SuspendEvents() to suspend selection changed events.
However don't forget to resume the painting/events. I've made myself some helper classes and wrap the calls with a using, so the dispose is called even if there is an exception.
Keep in mind that the selection events are only delayed, not ignored. You probably want to supsend the painting, then do your work, reset the selection and resume painting (in that order).
// Note: This class can only delay the selection changed events, not suppress them
public class SuspendSelectionEvents : IDisposable
{
private bool mIsDisposed = false;
private SyntaxEditor mEditor;
public SuspendSelectionEvents(SyntaxEditor editor)
{
mEditor = editor;
if ((null != mEditor) && (!mEditor.IsDisposed) && (null != mEditor.SelectedView))
{
mEditor.SelectedView.Selection.SuspendEvents();
}
}
~SuspendSelectionEvents()
{
Debug.Assert(mIsDisposed, "dispose object with using section");
Dispose();
}
#region IDisposable Members
public void Dispose()
{
if (!mIsDisposed)
{
mIsDisposed = true;
if ((null != mEditor) && (!mEditor.IsDisposed) && (null != mEditor.SelectedView))
{
mEditor.SelectedView.Selection.ResumeEvents();
}
}
}
#endregion IDisposable Members
}
public class SuspendPainting : IDisposable
{
private bool mIsDisposed = false;
private SyntaxEditor mEditor;
public SuspendPainting(SyntaxEditor editor)
{
mEditor = editor;
if ((null != mEditor) && (!mEditor.IsDisposed))
{
mEditor.SuspendPainting();
}
}
~SuspendPainting()
{
Debug.Assert(mIsDisposed, "dispose object with using section");
Dispose();
}
#region IDisposable Members
public void Dispose()
{
if (!mIsDisposed)
{
mIsDisposed = true;
if ((null != mEditor) && (!mEditor.IsDisposed))
{
mEditor.ResumePainting();
}
}
}
#endregion IDisposable Members
}
[Modified 12 years ago]
Best regards,
Tobias Lingemann.