A
a
I've been getting pretty annoyed with the Textbox Flicker. Any changed
to selected text causes the control to jump back to line one at the top
of the text for a second, then return to normal.
I've tried just about everything I that I can think of to prevent it,
but it looks like I'm going to use double textboxes and just keep moving
them around.
In the mean time though I wonder if someone from the OpenNetCF team
could comment on the following code. I can't seem to get OpenNetCF
sources to compile right now, but I would like to add something like
this to TextBoxEx to save lots of work in my application.
I was planning on adding the following to TextBox.cs - the TextBoxEx
class...
1. DrawControl property - bool -
TRUE - Control is painted
FALSE - Control is not painted
Default value = TRUE
2. Add OnPaint override to TextBoxEx
I just copied the OnPaint override from the #DESIGN section
of TextBox.cs. I hope it will work on the handheld at runtime
as well.
I will only draw the control if DrawControl property is true
So to prevent flicker, I would use something like this in my application...
TextBoxEx1.DrawControl = false;
TextBoxEx1.SelectedText = "HELLO";
TextBoxEx1.ScrollToCaret();
TextBoxEx1.DrawControl = true;
TextBoxEx1.Refresh():
Here is my suggested changes. Comments appreciated
--------------------------------------------------------------------------------
/// <summary>
/// Represents an enhanced TextBox.
/// </summary>
public class TextBoxEx : System.Windows.Forms.TextBox, IWin32Window
{
...
#if !DESIGN
private bool pDrawControl = true;
...
public bool DrawControl
{
get { return pDrawControl; }
set
{
pDrawControl = value;
}
}
/// <summary>
/// OnPaint override - taken from #IF Design section
/// </summary>
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs pea)
{
// This is my amazingly complex change
if (pDrawControl) {
Pen pb = new Pen(Color.Black);
SolidBrush bw = new SolidBrush(Color.White);
SolidBrush bb = new SolidBrush(Color.Black);
SolidBrush bg = new SolidBrush(Color.Gray);
if (this.ReadOnly)
pea.Graphics.FillRectangle(bg,this.ClientRectangle);
else
pea.Graphics.FillRectangle(bw,this.ClientRectangle);
pea.Graphics.DrawString(
this.Text,
this.Font,
bb,
2,
2);
pb.Dispose();
bb.Dispose();
bw.Dispose();
bg.Dispose();
// base.OnPaint(pea);
}
}
...
#Endif //!DESIGN
to selected text causes the control to jump back to line one at the top
of the text for a second, then return to normal.
I've tried just about everything I that I can think of to prevent it,
but it looks like I'm going to use double textboxes and just keep moving
them around.
In the mean time though I wonder if someone from the OpenNetCF team
could comment on the following code. I can't seem to get OpenNetCF
sources to compile right now, but I would like to add something like
this to TextBoxEx to save lots of work in my application.
I was planning on adding the following to TextBox.cs - the TextBoxEx
class...
1. DrawControl property - bool -
TRUE - Control is painted
FALSE - Control is not painted
Default value = TRUE
2. Add OnPaint override to TextBoxEx
I just copied the OnPaint override from the #DESIGN section
of TextBox.cs. I hope it will work on the handheld at runtime
as well.
I will only draw the control if DrawControl property is true
So to prevent flicker, I would use something like this in my application...
TextBoxEx1.DrawControl = false;
TextBoxEx1.SelectedText = "HELLO";
TextBoxEx1.ScrollToCaret();
TextBoxEx1.DrawControl = true;
TextBoxEx1.Refresh():
Here is my suggested changes. Comments appreciated
--------------------------------------------------------------------------------
/// <summary>
/// Represents an enhanced TextBox.
/// </summary>
public class TextBoxEx : System.Windows.Forms.TextBox, IWin32Window
{
...
#if !DESIGN
private bool pDrawControl = true;
...
public bool DrawControl
{
get { return pDrawControl; }
set
{
pDrawControl = value;
}
}
/// <summary>
/// OnPaint override - taken from #IF Design section
/// </summary>
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs pea)
{
// This is my amazingly complex change
if (pDrawControl) {
Pen pb = new Pen(Color.Black);
SolidBrush bw = new SolidBrush(Color.White);
SolidBrush bb = new SolidBrush(Color.Black);
SolidBrush bg = new SolidBrush(Color.Gray);
if (this.ReadOnly)
pea.Graphics.FillRectangle(bg,this.ClientRectangle);
else
pea.Graphics.FillRectangle(bw,this.ClientRectangle);
pea.Graphics.DrawString(
this.Text,
this.Font,
bb,
2,
2);
pb.Dispose();
bb.Dispose();
bw.Dispose();
bg.Dispose();
// base.OnPaint(pea);
}
}
...
#Endif //!DESIGN