Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> How To Scroll A Richtextbox Control To Previous Position?
turbopowerdmaxst...
post Feb 21 2008, 05:32 AM
Post #1


Premium Member
Group Icon

Group: [HOSTED]
Posts: 392
Joined: 16-February 06
From: Kolkata, India
Member No.: 11,322



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.
Attached File(s)
Attached File  Syntax_Highlight.zip ( 6.35k ) Number of downloads: 3
 
Go to the top of the page
 
+Quote Post
faulty.lee
post Feb 21 2008, 06:07 PM
Post #2


Premium Member
Group Icon

Group: [HOSTED]
Posts: 495
Joined: 5-November 06
Member No.: 17,016



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.
Go to the top of the page
 
+Quote Post
turbopowerdmaxst...
post Feb 25 2008, 03:32 PM
Post #3


Premium Member
Group Icon

Group: [HOSTED]
Posts: 392
Joined: 16-February 06
From: Kolkata, India
Member No.: 11,322



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
Go to the top of the page
 
+Quote Post
faulty.lee
post Feb 25 2008, 04:04 PM
Post #4


Premium Member
Group Icon

Group: [HOSTED]
Posts: 495
Joined: 5-November 06
Member No.: 17,016



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.
Go to the top of the page
 
+Quote Post
turbopowerdmaxst...
post Feb 26 2008, 04:05 AM
Post #5


Premium Member
Group Icon

Group: [HOSTED]
Posts: 392
Joined: 16-February 06
From: Kolkata, India
Member No.: 11,322



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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Volume Control icon disappeared(6)
  2. Firefox Tab Position(3)
  3. Disable Or Limit Access To The Control Panel(8)
  4. VB.NET: Rotating Label & Angled Text Control(8)
  5. C#.NET: Web Timer Control Tutorial(3)
  6. Volume Control Icon Disappeared.(10)
  7. Seizing Control Through Capital Punishment(13)
  8. Diskmgmt.msc - Coolest Inbuilt Control ( Xp )(6)
  9. How To Control Home Computer Remotely?(12)
  10. How Parental Control Software Works(4)
  11. Awesome Remote Control Software!(18)
  12. Diy Fan Controller(4)
  13. How To Control A Text Area .(4)
  14. User Account Control!(7)
  15. Get Mouse Position(4)
  1. Getting Absolute Position Of Non-absolute Elements(5)
  2. Google Analytics Tracking Code Position(10)
  3. When A User Close The Browser Window(1)
  4. Where Is The Control Panel In A Windows Hosting Server?(3)
  5. Flood Control(3)
  6. Do You Remember Your Previous Web Hosts?(9)
  7. Mind Control And Mindsong Inc(3)
  8. Excercise Would Surly Help In Get Control On Diabetes(0)
  9. Search Engine Keyword Position(0)
  10. User Account Control(13)
  11. Free Domain Control Panel.(3)
  12. Software Kvm(4)
  13. Teamviewer(7)


 



- Lo-Fi Version Time is now: 13th October 2008 - 03:40 PM