8 Replies - 7154 Views - Last Post: 15 April 2013 - 11:24 PM Rate Topic: -----

#1 Imdsm  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 103
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Updating a rich text box without it flickering

Posted 15 November 2010 - 06:20 AM

I'm trying to update a rich text box up to 10 times per second, without it flickering.

Lets say the text is a grid of 40 by 5 of the period character, which would give it a look like this:

........................................
........................................
........................................
........................................
........................................

And I then had an @ symbol in the middle like so:

........................................
........................................
..................@.....................
........................................
........................................

And when you press the up/down/left/right keys, the symbol moved without the confines of the grid.

This all works fine, but sometimes even when it's just a single key press, resetting the text in the box makes it flicker.

The way I do it at the moment is I render the grid into a string, and check every 100ms if the text is different to that rendered, and if it is, set the text to the new text.

But even when this is a single update, the textbox may flicker.

The code is:
private string RenderOutput()
{
    string output = "";
    for (int y = 0; y < mapSize.Height; y++)
    {
        for (int x = 0; x < mapSize.Width; x++)
        {
            if (x == point.X && y == point.Y) output += "@";
            else output += ".";
        }
        output += "\n";
    }
    return output;
}

private void DrawOutput()
{
    string output = RenderOutput();            
    if (rtf1.Text.ToString() != output)
    {
        rtf1.Text = output;
    }
}



Application.DoEvents() has no effect, and I can't really think of anything else that would have, other than scrapping the text box idea all together, if I could find a rich text label..

Any ideas?

Is This A Good Question/Topic? 0
  • +

Replies To: Updating a rich text box without it flickering

#2 batesy3k  Icon User is offline

  • D.I.C Regular

Reputation: 41
  • View blog
  • Posts: 299
  • Joined: 10-September 09

Re: Updating a rich text box without it flickering

Posted 15 November 2010 - 06:26 AM

refer to gabehabe's suggestion from this tutorial... may be what you need, however if not I'll dig out something I've used before for such things:

http://www.dreaminco...hlight-in-c%23/

Regards :
Was This Post Helpful? 1
  • +
  • -

#3 Janitor  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 56
  • Joined: 30-July 10

Re: Updating a rich text box without it flickering

Posted 15 November 2010 - 06:33 AM

Should have a look at double buffer...

this.SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer,true);


http://www.bobpowell...oublebuffer.htm
Was This Post Helpful? 1
  • +
  • -

#4 Imdsm  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 103
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: Updating a rich text box without it flickering

Posted 15 November 2010 - 06:34 AM

Thanks for the link but not quite the solution for me, though it will be useful later on when I colour things..

No, the problem I have is when the text is changed, it actually resets all the text and puts the new text in, even though most characters are the same they are still changed, and so the box kinda flickers but only sometimes..

The textbox is actually readonly, and there isn't any text input into it, just the form keydown event catching keys.

If there was a way to change only certain characters in the textbox, that may help, but I've yet to find a way to do that.

Thanks anyway
Was This Post Helpful? 0
  • +
  • -

#5 Janitor  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 56
  • Joined: 30-July 10

Re: Updating a rich text box without it flickering

Posted 15 November 2010 - 06:40 AM

View PostImdsm, on 15 November 2010 - 12:34 PM, said:

Thanks for the link but not quite the solution for me, though it will be useful later on when I colour things..

No, the problem I have is when the text is changed, it actually resets all the text and puts the new text in, even though most characters are the same they are still changed, and so the box kinda flickers but only sometimes..

The textbox is actually readonly, and there isn't any text input into it, just the form keydown event catching keys.

If there was a way to change only certain characters in the textbox, that may help, but I've yet to find a way to do that.

Thanks anyway


My apologies, have a look at validating text in a text box...and using the

theText = theText.Replace(Letter, String.Empty)


http://msdn.microsof...s.forms.textbox
Was This Post Helpful? 0
  • +
  • -

#6 Imdsm  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 103
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: Updating a rich text box without it flickering

Posted 15 November 2010 - 06:44 AM

Thanks Janitor, I thought of doing something like that but it didn't seem to work, neither did trying:
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);

I really can't think of a way to make it smoother :(

I will try removing the @ and a ., and inserting the other characters and see if that helps

Thanks
Was This Post Helpful? 0
  • +
  • -

#7 Imdsm  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 103
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: Updating a rich text box without it flickering

Posted 15 November 2010 - 07:20 AM

View PostJanitor, on 15 November 2010 - 05:40 AM, said:

theText = theText.Replace(Letter, String.Empty)


http://msdn.microsof...s.forms.textbox


Afraid this doesn't work as the way it works is instead of actually replacing the text and updating the control, it just replaces a letter and returns the string.

Thanks anyway
Was This Post Helpful? 0
  • +
  • -

#8 Imdsm  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 103
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: Updating a rich text box without it flickering

Posted 17 November 2010 - 03:43 AM

For anyone interested, instead of using a RTB, I decided to use Malison: http://bitbucket.org...lison/wiki/Home
Was This Post Helpful? 0
  • +
  • -

#9 frostyraver  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 195
  • Joined: 21-April 09

Re: Updating a rich text box without it flickering

Posted 15 April 2013 - 11:24 PM

View PostImdsm, on 17 November 2010 - 03:43 AM, said:

For anyone interested, instead of using a RTB, I decided to use Malison: http://bitbucket.org...lison/wiki/Home


What I did was create a normal text box, then I just put this somewhere

rtBox.Text = txtBox.Text;



For some stupid reason this works, something with how the RTB imports any type of information.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1