Nov 8, 2009

How To Scroll A Richtextbox Control To Previous Position?

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Programming General > C# .NET

How To Scroll A Richtextbox Control To Previous Position?

turbopowerdmaxsteel
I am working on a Syntax Highlighter for the latest version of Pika Bot (built in C# .NET) wherein the responses can be saved to a human friendly format. Example:-

CODE
/*Comment gfhfghfg*/
Condition _Condition1u : BuddyComesOnline
{
    BotGroup == "_ssi";
    BuddyName == "*";
    StatusType == "Idle";
    ForSeconds == "60";
}

/*Comment asdasd*/
Effect _Effect1 : MessageBox
{
    Title = "Pika Bot";
    Message = "sdfsfsfsf";
    Icon = "Asterisk";
}

/*ghjgj*/
Integer _Variable1 = "0";

/*asdas*/
Trigger _Trigger1 : ON
{
    Conditions
    {
        _Condition1u;
    }

    Effects
    {
        _Effect1;
    }
}

Bot _Bot2
{
    ID = "asdasd";
    Password = "žŒ›žŒτΟ›žŒ›ž";
    Encrypt = "True";
}

/*asdasdas*/
Bot _Bot1
{
    ID = "sdasd";
    Password = "asdasda";
    Encrypt = "False";
}

/*asdasda*/
BotGroup _BotGroup1
{
    _Bot2
}

BotGroup _ssi
{
    _Bot1
}


The syntax highligher does some basic coloring of the keywords namely: Condition, Effect, Integer, String, Trigger, Bot and BotGroup, string constants, comments and Condition/Effect Types such as BuddyComesOnline and MessageBox. I learnt that there are two ways to go about doing this. One is to use the SelectionStart, SelectionLength, SelectionColor properties provided by the RichTextBox control and second to modify the RTF code directly. The first process is rather slow and is marred by flickers, so I chose the second option. Even though its much faster there is one problem that I can't get through. Loading the entire RTF code causes the scroll position to be modified. The control only provides the ScrollToCaret() method which I am unable to use to restore the previous scroll position.

Is there any way to make a RichTextBox control scroll to a specific position?

I have attached the sample application which does the highlighting. It requires .NET Framework 2.0 or higher.

 

 

 


Comment/Reply (w/o sign-up)

faulty.lee
Err, I've tried your app, it works fine on my machine, both with and without "Highlight Dynamically" checked. I've the latest update of .Net 2.0 including the service pack, via autoupdate. Could that have made a difference?

These are my global assemblies' file version
mscorlib.dll = 2.0.50727.832
System.Windows.Form.dll = 2.0.50727.832

I do notice a bit a glitch, but not critical one. Whenever i clicked on the Highlight button, the text tends to shift down 1/2 a line, when i scrolled in such a way the first line is shown partially. Also, if i have a lot of text, clicking on the Highlight button will halt the app for a while before it return response.

Anyway, I do have some idea for using the first method and to suppress the flicker. You can subclass the RichTextBox, and add an additional boolean as a property while overriding the OnPaint event. The boolean, when set to true, will bypass the OnPaint call to the base class, thus preventing the screen from updating. That way you can resume the screen update after you've highlighted all the text. You might need to call the Update method of your RichTextBox after you set the boolean to false.

By the way, you should have explain a bit more on using the app that you attached. We wouldn't know what you actually wanted us to do with it.

 

 

 


Comment/Reply (w/o sign-up)

turbopowerdmaxsteel
Thanx, lee.

That glitch is exactly what I was trying to solve. I found a solution to the problem which requires the usage of SendMessage API. First we create a property which is used to obtain the current position of the scrollbar just before the text is to be updated. Then I used the technique that you mentioned and subclassed the RichTextBox to prevent the paint messages from being processed. Lastly, the property was used to restore the position of the scrollbar.

The code can be found at http://www.codeguru.com/forum/showthread.php?t=281765

Comment/Reply (w/o sign-up)

faulty.lee
Actually the RichTextBox is just trying to align the first line of text to show a full line. Why not just set the height of the control in such a way that all line are visible, no partial line is shown like the current case.

Comment/Reply (w/o sign-up)

turbopowerdmaxsteel
That is not necessary as the SendMessage based method solves it. Here is what I have been trying to build. Its not complete yet but many of the features do work.

http://maxotek.net/wip/pikabot4/4.0.1268.0.rar

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Scroll Richtextbox Previous


    Looking for scroll, richtextbox, control, previous, position,

See Also,

*SIMILAR VIDEOS*
Searching Video's for scroll, richtextbox, control, previous, position,
advertisement



How To Scroll A Richtextbox Control To Previous Position?

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com