DisappearingLineIndicator

SyntaxEditor for Windows Forms Forum

Posted 14 years ago by byperman - Sint-Niklaas, Belgium
Avatar
Hi,

I'm trying to implement a DisappearingLineIndicator, similar to the DisappearingIndicator that highlights a line (changing the backcolor) instead of making the text bold.

I'm not really sure how to do this, however. Could anyone tell me how to do this?

Thanks,
Brecht
/// <summary>
    /// Summary description for DisappearingLineIndicator.
    /// </summary>
    public class DisappearingLineIndicator : SpanIndicator
    {
        private Timer f_timer;

        private Color f_color;

        private HighlightingStyle f_style;

        public DisappearingLineIndicator(int milliSeconds, Color color) : base("DissapearingLineIndicator", 10, false, IndicatorMarks.StyleAssignment)
        {
            f_color = color;
            f_style = new HighlightingStyle("DisappearingLineIndicator", "DisappearingLineIndicator", Color.White, f_color, false, false, false);
            f_timer = new Timer(milliSeconds);
            f_timer.Elapsed += new ElapsedEventHandler(f_timer_Elapsed);
        }

        protected override void DrawMarks(Graphics g, Rectangle bounds)
        {
        }


        protected override HighlightingStyle GetHighlightingStyle()
        {
            return f_style;
        }

        protected override void OnAdded(IndicatorEventArgs e)
        {
            base.OnAdded (e);
            f_timer.Start();
        }

        private void f_timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            f_timer.Stop();
            // Something should happen here...
        }
    }

Comments (4)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Looks like you almost have it... in ours, we have this code related to the timer:
/// <summary>
/// Occurs when the timer expires.
/// </summary>
/// <param name="sender">Sender of the event.</param>
/// <param name="e">An <c>IndicatorEventArgs</c> that contains the event data.</param>
private void timer_Tick(object sender, EventArgs e) {
    // Disable the timer
    timer.Enabled = false;

    // Unbind the indicator if bound
    if (this.IsBound)
        this.Document.Indicators.Remove(this);
}

/// <summary>
/// Creates a timer.
/// </summary>
private void CreateTimer() {
    // Kill any existing timer
    if (timer != null) {
        try {
            timer.Enabled = false;
            timer.Tick -= new EventHandler(timer_Tick);
            timer.Dispose();
            timer = null;
        }
        catch {}
    }

    // Create the timer
    timer = new Timer();
    timer.Enabled    = false;
    timer.Interval    = milliseconds;
    timer.Tick += new EventHandler(timer_Tick);
}

/// <summary>
/// Occurs when the indicator is added to a <see cref="Document"/>.
/// </summary>
/// <param name="e">An <c>IndicatorEventArgs</c> that contains the event data.</param>
protected override void OnAdded(IndicatorEventArgs e) {
    // Call the base method
    base.OnAdded(e);

    // Enable the timer
    this.CreateTimer();
    timer.Enabled = true;
}


Actipro Software Support

Posted 14 years ago by byperman - Sint-Niklaas, Belgium
Avatar
Ok, thanks.

Where did you get the Document reference in the timer_Tick-method? That seems to be the key...
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Oh shoot... it's an internal property. Didn't notice that. I'll make it public for the next maint release for you.


Actipro Software Support

Posted 14 years ago by byperman - Sint-Niklaas, Belgium
Avatar
Great, thanks!

[Modified at 08/16/2005 07:34 AM]
The latest build of this product (v2020.1 build 0400) was released 24 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.