-
Notifications
You must be signed in to change notification settings - Fork 28
Updating Dependent Controls
A common feature most developers wish to provide with their Scintilla-based IDEs is to indicate where the caret (i.e. cursor) is at all times by perhaps displaying its location in the status bar. The UpdateUI
event is well suited to this. It is fired any time there is a change to text content or styling, the selection, or scroll positions and provides a way for identifying which of those changes caused the event to fire. This can be used to update any dependent controls or even synchronize the scrolling of one Scintilla control with another.
To display the current caret position and selection range in the status bar, try:
private void scintilla_UpdateUI(object sender, UpdateUIEventArgs e)
{
if ((e.Change & UpdateChange.Selection) > 0)
{
// The caret/selection changed
var currentPos = scintilla.CurrentPosition;
var anchorPos = scintilla.AnchorPosition;
toolStripStatusLabel.Text = "Ch: " + currentPos + " Sel: " + Math.Abs(anchorPos - currentPos);
}
}
NOTE: Not all changes will cause the UpdateUI
event to fire--only changes made by the user. Most programmatic changes will not fire the UpdateUI
event and so any changes you trigger programmatically should also trigger any programmatic changes to dependent controls.