473,545 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A scrolling text display that does't flash - possible in C#?

Hello,

I know I sound like a one-note Johnny on this but I'm still looking for a
solution. I need to display characters coming in from a serial port or a
socket. I also need to be able to type characters into the display myself -
but that's not the main issue at this time. I've tried a scrolling multiline
text box but once the original viewable area fills up and it starts scrolling
the flashing of the entire area drives me nuts. The vertical scroll bar can
be seen to bounce up and down as the control apparently updates the display
with every string it has including those that are not even in view. I've
limited my string array to just a few hundred strings just so it will have
less to update but that doesn't seem to matter. I've tried setting the
double-buffering property on the form, which accomplishes nothing. I've also
tried not even using a control and merely writing directly onto a form but I
haven't really accomplished much there either.

I've talked to several other C# "programmer s" here about the flashing and
they obviously know about as little as I do since they all tell me they have
the same problem and have not found a solution (they just keep a good supply
of headache pills on hand). I've seen other applications such as TeraTerm,
HyperTerm, and others that don't have this problem but I'd like to accomplish
the same thing in C# if possible. A sample application for just adding
characters to a non-flashing display would be appreciated since I'm not very
knowledgeable regarding digging down to the individual character x-y
coordinate and font size level, invalidating only over a single character,
It doesn't seem like that should be necessary anyway (but maybe it is?).

As Always, Thanks,
Ray
Aug 15 '07 #1
11 7592


"Ray Mitchell" wrote:
Hello,

I know I sound like a one-note Johnny on this but I'm still looking for a
solution. I need to display characters coming in from a serial port or a
socket. I also need to be able to type characters into the display myself -
but that's not the main issue at this time. I've tried a scrolling multiline
text box but once the original viewable area fills up and it starts scrolling
the flashing of the entire area drives me nuts. The vertical scroll bar can
be seen to bounce up and down as the control apparently updates the display
with every string it has including those that are not even in view. I've
limited my string array to just a few hundred strings just so it will have
less to update but that doesn't seem to matter. I've tried setting the
double-buffering property on the form, which accomplishes nothing. I've also
tried not even using a control and merely writing directly onto a form but I
haven't really accomplished much there either.

I've talked to several other C# "programmer s" here about the flashing and
they obviously know about as little as I do since they all tell me they have
the same problem and have not found a solution (they just keep a good supply
of headache pills on hand). I've seen other applications such as TeraTerm,
HyperTerm, and others that don't have this problem but I'd like to accomplish
the same thing in C# if possible. A sample application for just adding
characters to a non-flashing display would be appreciated since I'm not very
knowledgeable regarding digging down to the individual character x-y
coordinate and font size level, invalidating only over a single character,
It doesn't seem like that should be necessary anyway (but maybe it is?).

As Always, Thanks,
Ray

I just discovered something new. Maybe it will give someone a hint as to
what's going on. If I give some other form the focus the complete rewriting
and refreshing of everything in the display control and the bouncing of the
vertical scroll bar stops and the unbearable flashing stops. Instead, there
is just a slight flicker on some of the lines which, although it would be
better not to have, is at least readable. As soon as I give the focus back,
it starts flashing again. Any ideas?
Thanks, Ray
Aug 15 '07 #2
Ray Mitchell wrote:
[...]
I've talked to several other C# "programmer s" here about the flashing and
they obviously know about as little as I do since they all tell me they have
the same problem and have not found a solution (they just keep a good supply
of headache pills on hand).
I thought we'd covered this.

Generally:

Flashing occurs when an control is redrawn multiple times for a single
update. The most common scenario is when the control is not
double-buffered, resulting in the background being erased on-screen,
followed by the actual drawing of the new data.

It's not the only scenario though. Anything that causes the graphics
on-screen to change and then change again immediately after will cause
flashing. This can be as simple as clearing the Text property of a
control and then setting it to something else, or any number of other
things.

The first thing to do is make sure your control is double-buffered.
Then you can look at what else might be causing the flashing, if that
doesn't fix it.
I've seen other applications such as TeraTerm,
HyperTerm, and others that don't have this problem but I'd like to accomplish
the same thing in C# if possible.
As I'm pretty sure I have mentioned before, the applications you are
talking about don't use a standard, off-the-shelf control to display
their text. They undoubtedly have a custom control so that they have
complete control over how the drawing is done. You can easily do the same.
A sample application for just adding
characters to a non-flashing display would be appreciated since I'm not very
knowledgeable regarding digging down to the individual character x-y
coordinate and font size level, invalidating only over a single character,
It doesn't seem like that should be necessary anyway (but maybe it is?).
For best control over the drawing, it may be. Perhaps if I find some
time, I'll code up a sample.

In the meantime, one thing you need to do is understand why your current
code flashes. If it's not the lack of double-buffering, it must be
something else. What else is that? How are you using the control? Are
you in fact clearing the text? If not, maybe the control does something
like that internally when you change its contents.

One thing you might try is suppressing drawing when you are changing the
value of the control. This will require subclassing the control,
enabling double-buffering, overriding the OnPaint() method, and then
setting a flag while you change the contents of the control. When
you're done updating the control, clear the flag again and invalidate
the entire control so that it redraws.

In the OnPaint() method, only call base.OnPaint() if your flag isn't set.

Finally, you will find that you get the best help if you put together a
concise-but-complete sample of code that illustrates how your code works
now, and what doesn't work for you. Absent such a sample, all we can do
is guess, and there's no guarantee that any sample code someone else
might provide will be successfully integrated by you into your existing
application. Knowing where you stand now would go a long way to helping
make sure the advice is to the point and helpful to you.

Pete
Aug 15 '07 #3


"Peter Duniho" wrote:
Ray Mitchell wrote:
[...]
I've talked to several other C# "programmer s" here about the flashing and
they obviously know about as little as I do since they all tell me they have
the same problem and have not found a solution (they just keep a good supply
of headache pills on hand).

I thought we'd covered this.

Generally:

Flashing occurs when an control is redrawn multiple times for a single
update. The most common scenario is when the control is not
double-buffered, resulting in the background being erased on-screen,
followed by the actual drawing of the new data.

It's not the only scenario though. Anything that causes the graphics
on-screen to change and then change again immediately after will cause
flashing. This can be as simple as clearing the Text property of a
control and then setting it to something else, or any number of other
things.

The first thing to do is make sure your control is double-buffered.
Then you can look at what else might be causing the flashing, if that
doesn't fix it.
I've seen other applications such as TeraTerm,
HyperTerm, and others that don't have this problem but I'd like to accomplish
the same thing in C# if possible.

As I'm pretty sure I have mentioned before, the applications you are
talking about don't use a standard, off-the-shelf control to display
their text. They undoubtedly have a custom control so that they have
complete control over how the drawing is done. You can easily do the same.
A sample application for just adding
characters to a non-flashing display would be appreciated since I'm not very
knowledgeable regarding digging down to the individual character x-y
coordinate and font size level, invalidating only over a single character,
It doesn't seem like that should be necessary anyway (but maybe it is?).

For best control over the drawing, it may be. Perhaps if I find some
time, I'll code up a sample.

In the meantime, one thing you need to do is understand why your current
code flashes. If it's not the lack of double-buffering, it must be
something else. What else is that? How are you using the control? Are
you in fact clearing the text? If not, maybe the control does something
like that internally when you change its contents.

One thing you might try is suppressing drawing when you are changing the
value of the control. This will require subclassing the control,
enabling double-buffering, overriding the OnPaint() method, and then
setting a flag while you change the contents of the control. When
you're done updating the control, clear the flag again and invalidate
the entire control so that it redraws.

In the OnPaint() method, only call base.OnPaint() if your flag isn't set.

Finally, you will find that you get the best help if you put together a
concise-but-complete sample of code that illustrates how your code works
now, and what doesn't work for you. Absent such a sample, all we can do
is guess, and there's no guarantee that any sample code someone else
might provide will be successfully integrated by you into your existing
application. Knowing where you stand now would go a long way to helping
make sure the advice is to the point and helpful to you.

Pete
Hi Pete,

Yes, you certainly have covered much of this before and I do appreciate your
patience. My problem is that my experience with all this GUI stuff is very
minimal. I primarily code command line C/C++ applications where I spend most
of my time on the actual algorithm rather than on the graphical user
interface. So of course I know that I need to hit the books regarding all
this but I was simply looking for an easy solution to what seemed to me would
be a pretty common application. My hope was to be able to reuse something
that had already been done and placed out there for public use rather than
make it a detailed education in the details of it all. No big deal, however.
Although I appreciate the sentiment, there's no need for you to spend
additional time coding up something that I should take the time to master
myself.

Thanks,
Ray

Aug 16 '07 #4
Ray Mitchell wrote:
Yes, you certainly have covered much of this before and I do appreciate your
patience. My problem is that my experience with all this GUI stuff is very
minimal. I primarily code command line C/C++ applications where I spend most
of my time on the actual algorithm rather than on the graphical user
interface. So of course I know that I need to hit the books regarding all
this but I was simply looking for an easy solution to what seemed to me would
be a pretty common application. My hope was to be able to reuse something
that had already been done and placed out there for public use rather than
make it a detailed education in the details of it all. No big deal, however.
Although I appreciate the sentiment, there's no need for you to spend
additional time coding up something that I should take the time to master
myself.
Okay. For what it's worth, I did put together a little test project
just so I could try to reproduce your problem. I don't know if I
reproduced your exact scenario, but I did reproduce something like it. :)

One thing I learned is that the "easy out" suggestions I provided aren't
going to help. I haven't looked into this too deeply, but it appears to
me that in addition to the TextBox control wrapping a standard Windows
edit control, that edit control itself may contain yet another control
that acts independently, or it does not use the usual "invalidate , wait
for WM_PAINT" mechanism for updating after the contents change (I'm
guessing the former, but I can't rule out the latter, even though it's
pretty much the opposite of what all Windows GUI software should be doing).

The reason I say that is that even overriding the WndProc, which would
normally allow me direct access to the underlying window, I'm unable to
disable the updating while I'm changing the control. The control
redraws immediately as things are changed, and it doesn't do so through
the handling of a WM_PAINT message (at least not directly), so there's
no direct way to simply intercept the WM_PAINT and prevent redrawing.

Anyway, to get you started on writing your own custom control...

It's really not actually all that hard. You'll want to start with a
class that inherits Control. You'll have to, at a minimum, implement
OnPaint() and provide a public API in the class so that you can do
things like add text. And of course, in the class you need to keep
track of the text. How you store the text will depend on what works
best for your implementation, as well as the API. However, you may find
that a linked list of strings, one per line, works well. That way you
can quickly add new strings to the end, as well as remove old ones from
the beginning.

In OnPaint(), the MeasureString() and DrawString() methods will be your
main workhorse methods. In the simplest case, you'll just start drawing
your text at the origin, using MeasureString() to keep track of where
the next text should go. If you want the text to wrap, .NET can help
you with that via flags passed to MeasureString() and DrawString().
Otherwise, it's as simple as updating the y coordinate for each new line
of text as you draw.

You can make things more complicated by including some sort of internal
margins for your control, and by supporting scrolling. These will
involve offsetting your drawing by various amounts representing those
properties. For scrolling, you may find it desirable for performance
reasons to only actually call DrawString() once your iteration through
the list of strings tells you that your next line of text will in fact
intersect the client area of your control. Likewise, once you've gotten
to the bottom of the control, you may want to just stop drawing, rather
than iterate through the rest of the lines that won't show on the screen
anyway.

You can cache other values as well to speed things further (like what
line of text is the first visible line, etc.), but IMHO unless you find
a demonstrable performance issue it's not really worth worrying about
that. Better to get it working first.

And of course, the most important thing will be to make sure that your
control's DoubleBuffered property is set to true. :)

Pete
Aug 16 '07 #5
On 16 Aug, 03:23, Peter Duniho <NpOeStPe...@Nn OwSlPiAnMk.comw rote:
Ray Mitchell wrote:
Yes, you certainly have covered much of this before and I do appreciate your
patience. My problem is that my experience with all this GUI stuff is very
minimal. I primarily code command line C/C++ applications where I spend most
of my time on the actual algorithm rather than on the graphical user
interface. So of course I know that I need to hit the books regarding all
this but I was simply looking for an easy solution to what seemed to me would
be a pretty common application. My hope was to be able to reuse something
that had already been done and placed out there for public use rather than
make it a detailed education in the details of it all. No big deal, however.
Although I appreciate the sentiment, there's no need for you to spend
additional time coding up something that I should take the time to master
myself.

Okay. For what it's worth, I did put together a little test project
just so I could try to reproduce your problem. I don't know if I
reproduced your exact scenario, but I did reproduce something like it. :)

One thing I learned is that the "easy out" suggestions I provided aren't
going to help. I haven't looked into this too deeply, but it appears to
me that in addition to the TextBox control wrapping a standard Windows
edit control, that edit control itself may contain yet another control
that acts independently, or it does not use the usual "invalidate , wait
for WM_PAINT" mechanism for updating after the contents change (I'm
guessing the former, but I can't rule out the latter, even though it's
pretty much the opposite of what all Windows GUI software should be doing).

The reason I say that is that even overriding the WndProc, which would
normally allow me direct access to the underlying window, I'm unable to
disable the updating while I'm changing the control. The control
redraws immediately as things are changed, and it doesn't do so through
the handling of a WM_PAINT message (at least not directly), so there's
no direct way to simply intercept the WM_PAINT and prevent redrawing.

Anyway, to get you started on writing your own custom control...

It's really not actually all that hard. You'll want to start with a
class that inherits Control. You'll have to, at a minimum, implement
OnPaint() and provide a public API in the class so that you can do
things like add text. And of course, in the class you need to keep
track of the text. How you store the text will depend on what works
best for your implementation, as well as the API. However, you may find
that a linked list of strings, one per line, works well. That way you
can quickly add new strings to the end, as well as remove old ones from
the beginning.

In OnPaint(), the MeasureString() and DrawString() methods will be your
main workhorse methods. In the simplest case, you'll just start drawing
your text at the origin, using MeasureString() to keep track of where
the next text should go. If you want the text to wrap, .NET can help
you with that via flags passed to MeasureString() and DrawString().
Otherwise, it's as simple as updating the y coordinate for each new line
of text as you draw.

You can make things more complicated by including some sort of internal
margins for your control, and by supporting scrolling. These will
involve offsetting your drawing by various amounts representing those
properties. For scrolling, you may find it desirable for performance
reasons to only actually call DrawString() once your iteration through
the list of strings tells you that your next line of text will in fact
intersect the client area of your control. Likewise, once you've gotten
to the bottom of the control, you may want to just stop drawing, rather
than iterate through the rest of the lines that won't show on the screen
anyway.

You can cache other values as well to speed things further (like what
line of text is the first visible line, etc.), but IMHO unless you find
a demonstrable performance issue it's not really worth worrying about
that. Better to get it working first.

And of course, the most important thing will be to make sure that your
control's DoubleBuffered property is set to true. :)

Pete
If you do fancy giving it a go, here's a tiny example. There's one
class : control and one form that shows it working. Create a new forms
app add a class and paste the control into it then paste the form code
over the form in the forms app. Everything is written under the 1.1
framework so it should work everywhere.
Watch for line wrap.

Control first
---------------------------------------------------------------------

using System;
using System.Drawing;
using System.Componen tModel;
using System.Windows. Forms;

namespace WindowsApplicat ion23
{
[System.Componen tModel.Designer Category("Code" )]
public class UC : Control
{
protected override void OnPaint(PaintEv entArgs e)
{
e.Graphics.Fill Rectangle(Brush es.AliceBlue,ne w Rectangle(Left, Top,
Width, Height));
Font f = new Font("Arial",8. 25F);
SizeF s = e.Graphics.Meas ureString("this is a test", f,
new SizeF(Width - Left, Height - Top ));
RectangleF r = new RectangleF(Left , Top, s.Width, s.Height);
e.Graphics.Fill Rectangle(Syste m.Drawing.Brush es.Cyan, r);
e.Graphics.Draw String("this is a test", f, Brushes.Black, r);
r = new RectangleF(Left , Top + r.Height, s.Width, s.Height);
e.Graphics.Fill Rectangle(Syste m.Drawing.Brush es.CornflowerBl ue, r);
e.Graphics.Draw String("this is a test", f, Brushes.Black, r);
}
protected override void OnResize(EventA rgs e)
{
this.Invalidate ();
base.OnResize (e);
}
}
}

Form
----------------------------------------------------------------------------------------

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;

namespace WindowsApplicat ion23
{
public class Form2 : System.Windows. Forms.Form
{
private System.Componen tModel.Containe r components = null;
private System.Windows. Forms.Button button1;
private UC _uc;

public Form2()
{
InitializeCompo nent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
private void InitializeCompo nent()
{
this.button1 = new System.Windows. Forms.Button();
this._uc = new WindowsApplicat ion23.UC();
this.SuspendLay out();
//
// button1
//
this.button1.Lo cation = new System.Drawing. Point(88, 128);
this.button1.Na me = "button1";
this.button1.Si ze = new System.Drawing. Size(48, 24);
this.button1.Ta bIndex = 0;
this.button1.Te xt = "button1";
this.button1.Cl ick += new System.EventHan dler(this.butto n1_Click);
//
// _uc
//
this._uc.Locati on = new System.Drawing. Point(10, 10);
this._uc.Name = "_uc";
this._uc.Size = new System.Drawing. Size(46, 102);
this._uc.TabInd ex = 0;
//
// Form2
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 266);
this.Controls.A dd(this.button1 );
this.Controls.A dd(this._uc);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayo ut(false);

}
#endregion
private void button1_Click(o bject sender, System.EventArg s e)
{
_uc.Width +=10;
}
[STAThread]
static void Main()
{
Application.Run (new Form2());
}
}
}

Aug 16 '07 #6

I should probably add:

public UC()
{
this.SetStyle(C ontrolStyles.Do ubleBuffer,true );
}

I've just modified it to scroll the string and the above removes any
flicker.
Aug 16 '07 #7


"Peter Duniho" wrote:
Ray Mitchell wrote:
Yes, you certainly have covered much of this before and I do appreciate your
patience. My problem is that my experience with all this GUI stuff is very
minimal. I primarily code command line C/C++ applications where I spend most
of my time on the actual algorithm rather than on the graphical user
interface. So of course I know that I need to hit the books regarding all
this but I was simply looking for an easy solution to what seemed to me would
be a pretty common application. My hope was to be able to reuse something
that had already been done and placed out there for public use rather than
make it a detailed education in the details of it all. No big deal, however.
Although I appreciate the sentiment, there's no need for you to spend
additional time coding up something that I should take the time to master
myself.

Okay. For what it's worth, I did put together a little test project
just so I could try to reproduce your problem. I don't know if I
reproduced your exact scenario, but I did reproduce something like it. :)

One thing I learned is that the "easy out" suggestions I provided aren't
going to help. I haven't looked into this too deeply, but it appears to
me that in addition to the TextBox control wrapping a standard Windows
edit control, that edit control itself may contain yet another control
that acts independently, or it does not use the usual "invalidate , wait
for WM_PAINT" mechanism for updating after the contents change (I'm
guessing the former, but I can't rule out the latter, even though it's
pretty much the opposite of what all Windows GUI software should be doing).

The reason I say that is that even overriding the WndProc, which would
normally allow me direct access to the underlying window, I'm unable to
disable the updating while I'm changing the control. The control
redraws immediately as things are changed, and it doesn't do so through
the handling of a WM_PAINT message (at least not directly), so there's
no direct way to simply intercept the WM_PAINT and prevent redrawing.

Anyway, to get you started on writing your own custom control...

It's really not actually all that hard. You'll want to start with a
class that inherits Control. You'll have to, at a minimum, implement
OnPaint() and provide a public API in the class so that you can do
things like add text. And of course, in the class you need to keep
track of the text. How you store the text will depend on what works
best for your implementation, as well as the API. However, you may find
that a linked list of strings, one per line, works well. That way you
can quickly add new strings to the end, as well as remove old ones from
the beginning.

In OnPaint(), the MeasureString() and DrawString() methods will be your
main workhorse methods. In the simplest case, you'll just start drawing
your text at the origin, using MeasureString() to keep track of where
the next text should go. If you want the text to wrap, .NET can help
you with that via flags passed to MeasureString() and DrawString().
Otherwise, it's as simple as updating the y coordinate for each new line
of text as you draw.

You can make things more complicated by including some sort of internal
margins for your control, and by supporting scrolling. These will
involve offsetting your drawing by various amounts representing those
properties. For scrolling, you may find it desirable for performance
reasons to only actually call DrawString() once your iteration through
the list of strings tells you that your next line of text will in fact
intersect the client area of your control. Likewise, once you've gotten
to the bottom of the control, you may want to just stop drawing, rather
than iterate through the rest of the lines that won't show on the screen
anyway.

You can cache other values as well to speed things further (like what
line of text is the first visible line, etc.), but IMHO unless you find
a demonstrable performance issue it's not really worth worrying about
that. Better to get it working first.

And of course, the most important thing will be to make sure that your
control's DoubleBuffered property is set to true. :)

Pete
Pete,

Thanks for taking so much time to try this out then write such a detailed
explanation. I will take the time to look into your observations and
suggestions. Doesn't it seem a little strange to you that there is not
already a control that just works properly for this purpose? Maybe I'm in
the minority, doing embedded communications monitoring and such low level
work but it still seems like there would be some demand for some sort of
interactive real-time data display that doesn't bounce all over the place.
I've actually looked at the source code for TeraTerm (freely, legally,
available) but it's fairly complex and for me it's difficult to pick out the
portion I'm actually looking for. I figure that if I could, however, I could
get some more ideas. I think it's written with either just Win32 APIs or
maybe MFC, so it might be necessary to invoke some of it as unmanaged code if
there were no managed C# equivalent. Anyway, I want to stick with standard
..NET stuff if possible so I'll take a closer look at using the methods you
suggest for measuring and drawing strings, etc. Thanks again for all your
help and suggestions over the past few weeks/months.

Ray
Aug 17 '07 #8


"DeveloperX " wrote:
>
I should probably add:

public UC()
{
this.SetStyle(C ontrolStyles.Do ubleBuffer,true );
}

I've just modified it to scroll the string and the above removes any
flicker.
Hey DeveloperX,

Thanks for the code. I'll take a look and see what I do with it.

Ray
Aug 17 '07 #9
Peter Duniho wrote:
[...]
Finally, in the realm of serious hacking, I had a couple of other ideas
I haven't had a chance to try out yet, but which I think I will at some
point. One is to do a sort of double-buffering technique, except using
two complete copies of the control in a double-buffered form. The other
is to somehow use the DrawBitmap method to more completely control how
the textbox control gets drawn on the form.

Both of these hacks have serious problems when it comes to user
interaction, I suspect, but if all you want to do is get the text on the
screen, they might just do the trick. They definitely qualify as ugly
hacks though. :)

I'll post back here if anything comes of them.
Okay, the double-copy technique didn't pan out. Even with the main form
double-buffered, drawing for the child controls doesn't actually get
double-buffered and so there's still flicker as each textbox is swapped
to the front.

However, using DrawBitmap worked a lot better. The basic idea is to
have a custom control exactly covering the real control, and when the
real control gets updated, copy the results to a bitmap and then use
that to draw the custom control. With the custom control on top of the
real control, drawing by the real control is completely obscured, and so
redrawing of the visible graphics is controlled completely by the custom
control. Of course, by setting DoubleBuffered to true in the custom
control, flicker can be prevented.

Warning: I got a bit of an icky feeling just writing this code. It
seems kind of evil to me. :) But it does completely stop the flickering.

I've copied the code here. To use it, you'll need to add a new Custom
Control to your project, and then completely replace the non-Designer
part of the implementation with this code. Once you've gotten it
compiled, then you can drag-and-drop a new NoFlashMirror instance from
the Designer toolbox onto your form with the actual textbox control. In
the Designer, set the MirroredControl property of the NoFlashMirror
control instance to the textbox control you want it to cover.

Finally, anywhere in your code that you do something that would change
the visual aspect of the actual textbox control, call
NoFlashMirror.U pdateMirror();

That _should_ be all there is to it.

Of course, this method completely prevents any user interaction with the
underlying control. You can't click with the mouse, select text, use
the arrow keys to move around in the textbox, type into the textbox,
etc. (Well, technically the last two are possible, but because the
NoFlashMirror control relies on the controlling application to notify it
of changes, redrawing to deal with blinking and movement of the caret
isn't handled).

It is _possible_ that there might be some way hook into the underlying
edit control class so that these sorts of things are handled, but I
don't know off the top of my head how that would be done. If the
textbox control were all managed, I think it would be simply a matter of
forwarding various input events (mouse, key, etc.) and subscribing to
the Paint event. But it's not, and so you'd have to do all that stuff
at a lower level, which is trickier from managed code.

Anyway, without further ado...

public partial class NoFlashMirror : Control
{
Control _ctl;
Bitmap _bmp;

public Control MirroredControl
{
get { return _ctl; }
set
{
if (_ctl != value)
{
if (_ctl != null)
{
_ctl.SizeChange d -= _SizeChangedHan dler;
_ctl.LocationCh anged -= _LocationChange dHandler;
}

_ctl = value;

if (_ctl != null)
{
_ctl.SizeChange d += _SizeChangedHan dler;
_ctl.LocationCh anged += _LocationChange dHandler;

_SizeChangedHan dler(this, new EventArgs());
_LocationChange dHandler(this, new EventArgs());

}

UpdateMirror();
}
}
}

private void _SizeChangedHan dler(object sender, EventArgs e)
{
Size = _ctl.Size;
}

private void _LocationChange dHandler(object sender, EventArgs e)
{
Location = _ctl.Location;
}

public void UpdateMirror()
{
if (_ctl != null)
{
if (_bmp == null ||
_bmp.Width != _ctl.Width ||
_bmp.Height != _ctl.Height)
{
_bmp = new Bitmap(_ctl.Wid th, _ctl.Height);
}

_ctl.DrawToBitm ap(_bmp,
new Rectangle(new Point(), _bmp.Size));
}
else
{
_bmp = null;
}

Invalidate();
}

public NoFlashMirror()
{
InitializeCompo nent();

DoubleBuffered = true;
}

protected override void OnPaint(PaintEv entArgs pe)
{
// Calling the base class OnPaint
base.OnPaint(pe );

if (_bmp != null)
{
pe.Graphics.Dra wImage(_bmp, new Point());
}
}
}
Aug 17 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
2335
by: Christopher Subich | last post by:
As a hobby project, I'm writing a MUD client -- this scratches an itch, and is also a good excuse to become familiar with the Python language. I have a conceptual handle on most of the implementation, but the biggest unknown for me is the seemingly trivial matter of text display. My first requirement is raw speed; none of what I'm doing is...
26
2611
by: Bernie Yaeger | last post by:
I'd like to develop scrolling text in an 'about' box, similar to the kind of thing you see in lots of apps (eg photoshop). I could use flash to do this, and I know how to, but I would like to know if I can do this in vb .net only. Thanks for any help. Bernie Yaeger
6
3271
by: Bosnewi | last post by:
hi, What's the easiest way to make a text to fly inside of any control such as textbox. Any ideas???
17
4691
by: pigeonrandle | last post by:
Hi, I have seen loads of different ways to do this, but the all seem to yield the same result - text that doesn't flicker when it's moving too slowly! Does anyone know 'the best way' to make text scroll... eg Override OnPain and OnPaintBackground Override WndProc
5
4234
by: PythonistL | last post by:
I am a newbie with Javascript. I have this simple script for scrolling text <HTML> <HEAD> <TITLE>Scrolling Message Script</TITLE> <SCRIPT language="JavaScript"><!-- var msg = 'My scrolling text.. ' function scrollMsg(){
1
7321
by: Bishman | last post by:
Hi, I have been trying to get text to scroll smoothly accross a windows form using GDI+ and a timer. Changing the position of the text by a configurable amount and calling invalidate to force a redraw at various intervals ( based on the timer ). The text is not moving that smoothly, it seems very jerky, no matter what combination of timings...
1
1647
by: coldbuttmoneky | last post by:
Now i know that clearing a text field in normal macromedia flash is a simple: textfield.text=""; but when this is place into a button on selteco flash, it doesnt seem to clear anything. The name of my text field is search so i thought putting: search.text=""; but it displays an error message. someone help? bad action cript person here...
0
7478
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7410
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7668
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7773
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5984
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3466
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1025
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
722
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.