473,738 Members | 6,332 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Flat Textbox

Hi,

I'm trying to create a textbox inheriting from the standard textbox. I
would like to:

1. repaint the textbox border;
2. define a color for that border;

Till now I made this:

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

namespace Library.Control s
{
public class TextBox : System.Windows. Forms.TextBox
{
private enum MouseState
{
Focused,
Hoover,
Normal
}

private Color borderColor = Color.FromArgb( 128, 128, 128);
//Gray
private Color highlightColor = Color.FromArgb( 10, 36, 106);
//Blue
private Color hoverColor = Color.Silver; //Silver
private MouseState m_MouseState = MouseState.Norm al;

public TextBox()
{
this.MouseEnter += new EventHandler(On MouseEnter);
this.MouseLeave += new EventHandler(On MouseLeave);
this.MouseHover += new EventHandler(On MouseHover);
this.Enter += new EventHandler(On Enter);
this.Leave += new EventHandler(On Leave);
this.BorderStyl e = BorderStyle.Fix edSingle;

SetStyle(Contro lStyles.UserPai nt, true);

}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint(e) ;
e.Graphics.Draw String(Text, Font, new
SolidBrush(Fore Color), new PointF(0, 0));

switch (m_MouseState)
{
case MouseState.Focu sed:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(highlightCo lor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Hoov er:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(highlightCo lor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Norm al:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(borderColor ), 0, 0, Width - 1, Height - 1);
break;
}
}

#region Mouse Events
private void OnMouseEnter(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
private void OnMouseLeave(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}
private void OnMouseHover(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
#endregion

private void OnEnter(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Focu sed;
Invalidate();
}
private void OnLeave(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}

}
}

The problem is related with the text drawing. Somehow, when editing,
the textbox suddenlly uses other font then the default causing
missreading.

There's any way to solve this situation.
Thanks in advance for your attention,
Filipe Marcelino

Sep 12 '06 #1
8 5092
Filipe,

Are you sure the propertie "borderstyl e" does not help you.
http://msdn.microsoft.com/library/de...styletopic.asp

Cor
"Filipe Marcelino" <fm********@gma il.comschreef in bericht
news:11******** *************@m 73g2000cwd.goog legroups.com...
Hi,

I'm trying to create a textbox inheriting from the standard textbox. I
would like to:

1. repaint the textbox border;
2. define a color for that border;

Till now I made this:

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

namespace Library.Control s
{
public class TextBox : System.Windows. Forms.TextBox
{
private enum MouseState
{
Focused,
Hoover,
Normal
}

private Color borderColor = Color.FromArgb( 128, 128, 128);
//Gray
private Color highlightColor = Color.FromArgb( 10, 36, 106);
//Blue
private Color hoverColor = Color.Silver; //Silver
private MouseState m_MouseState = MouseState.Norm al;

public TextBox()
{
this.MouseEnter += new EventHandler(On MouseEnter);
this.MouseLeave += new EventHandler(On MouseLeave);
this.MouseHover += new EventHandler(On MouseHover);
this.Enter += new EventHandler(On Enter);
this.Leave += new EventHandler(On Leave);
this.BorderStyl e = BorderStyle.Fix edSingle;

SetStyle(Contro lStyles.UserPai nt, true);

}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint(e) ;
e.Graphics.Draw String(Text, Font, new
SolidBrush(Fore Color), new PointF(0, 0));

switch (m_MouseState)
{
case MouseState.Focu sed:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(highlightCo lor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Hoov er:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(highlightCo lor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Norm al:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(borderColor ), 0, 0, Width - 1, Height - 1);
break;
}
}

#region Mouse Events
private void OnMouseEnter(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
private void OnMouseLeave(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}
private void OnMouseHover(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
#endregion

private void OnEnter(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Focu sed;
Invalidate();
}
private void OnLeave(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}

}
}

The problem is related with the text drawing. Somehow, when editing,
the textbox suddenlly uses other font then the default causing
missreading.

There's any way to solve this situation.
Thanks in advance for your attention,
Filipe Marcelino

Sep 13 '06 #2
Hi Cor,

Has you may noticed I already set my textbox borderstyle to FixedSingle
(this.BorderSty le = BorderStyle.Fix edSingle;). Now I want to paint that
border (black by default) with blue for example.

If I'm not being clear please make me know to clarify you.
Thanks in advance,
Filipe Marcelino

Cor Ligthert [MVP] wrote:
Filipe,

Are you sure the propertie "borderstyl e" does not help you.
http://msdn.microsoft.com/library/de...styletopic.asp

Cor
"Filipe Marcelino" <fm********@gma il.comschreef in bericht
news:11******** *************@m 73g2000cwd.goog legroups.com...
Hi,

I'm trying to create a textbox inheriting from the standard textbox. I
would like to:

1. repaint the textbox border;
2. define a color for that border;

Till now I made this:

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

namespace Library.Control s
{
public class TextBox : System.Windows. Forms.TextBox
{
private enum MouseState
{
Focused,
Hoover,
Normal
}

private Color borderColor = Color.FromArgb( 128, 128, 128);
//Gray
private Color highlightColor = Color.FromArgb( 10, 36, 106);
//Blue
private Color hoverColor = Color.Silver; //Silver
private MouseState m_MouseState = MouseState.Norm al;

public TextBox()
{
this.MouseEnter += new EventHandler(On MouseEnter);
this.MouseLeave += new EventHandler(On MouseLeave);
this.MouseHover += new EventHandler(On MouseHover);
this.Enter += new EventHandler(On Enter);
this.Leave += new EventHandler(On Leave);
this.BorderStyl e = BorderStyle.Fix edSingle;

SetStyle(Contro lStyles.UserPai nt, true);

}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint(e) ;
e.Graphics.Draw String(Text, Font, new
SolidBrush(Fore Color), new PointF(0, 0));

switch (m_MouseState)
{
case MouseState.Focu sed:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(highlightCo lor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Hoov er:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(highlightCo lor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Norm al:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(borderColor ), 0, 0, Width - 1, Height - 1);
break;
}
}

#region Mouse Events
private void OnMouseEnter(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
private void OnMouseLeave(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}
private void OnMouseHover(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
#endregion

private void OnEnter(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Focu sed;
Invalidate();
}
private void OnLeave(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}

}
}

The problem is related with the text drawing. Somehow, when editing,
the textbox suddenlly uses other font then the default causing
missreading.

There's any way to solve this situation.
Thanks in advance for your attention,
Filipe Marcelino
Sep 13 '06 #3
Try adding this:

protected override void OnTextChanged(E ventArgs e)
{
base.OnTextChan ged(e);
Refresh();
}

Seemed to fix the problem for me... though there is the problem of painting
the caret to deal with!

Steve
"Filipe Marcelino" <fm********@gma il.comwrote in message
news:11******** **************@ e63g2000cwd.goo glegroups.com.. .
Hi Cor,

Has you may noticed I already set my textbox borderstyle to FixedSingle
(this.BorderSty le = BorderStyle.Fix edSingle;). Now I want to paint that
border (black by default) with blue for example.

If I'm not being clear please make me know to clarify you.
Thanks in advance,
Filipe Marcelino

Cor Ligthert [MVP] wrote:
>Filipe,

Are you sure the propertie "borderstyl e" does not help you.
http://msdn.microsoft.com/library/de...styletopic.asp

Cor
"Filipe Marcelino" <fm********@gma il.comschreef in bericht
news:11******* **************@ m73g2000cwd.goo glegroups.com.. .
Hi,

I'm trying to create a textbox inheriting from the standard textbox. I
would like to:

1. repaint the textbox border;
2. define a color for that border;

Till now I made this:

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

namespace Library.Control s
{
public class TextBox : System.Windows. Forms.TextBox
{
private enum MouseState
{
Focused,
Hoover,
Normal
}

private Color borderColor = Color.FromArgb( 128, 128, 128);
//Gray
private Color highlightColor = Color.FromArgb( 10, 36, 106);
//Blue
private Color hoverColor = Color.Silver; //Silver
private MouseState m_MouseState = MouseState.Norm al;

public TextBox()
{
this.MouseEnter += new EventHandler(On MouseEnter);
this.MouseLeave += new EventHandler(On MouseLeave);
this.MouseHover += new EventHandler(On MouseHover);
this.Enter += new EventHandler(On Enter);
this.Leave += new EventHandler(On Leave);
this.BorderStyl e = BorderStyle.Fix edSingle;

SetStyle(Contro lStyles.UserPai nt, true);

}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint(e) ;
e.Graphics.Draw String(Text, Font, new
SolidBrush(Fore Color), new PointF(0, 0));

switch (m_MouseState)
{
case MouseState.Focu sed:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(highlightCo lor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Hoov er:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(highlightCo lor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Norm al:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(borderColor ), 0, 0, Width - 1, Height - 1);
break;
}
}

#region Mouse Events
private void OnMouseEnter(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
private void OnMouseLeave(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}
private void OnMouseHover(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
#endregion

private void OnEnter(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Focu sed;
Invalidate();
}
private void OnLeave(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}

}
}

The problem is related with the text drawing. Somehow, when editing,
the textbox suddenlly uses other font then the default causing
missreading.

There's any way to solve this situation.
Thanks in advance for your attention,
Filipe Marcelino

Sep 13 '06 #4
Hi Steve,

thanks for your reply but I tried and, in fact, the font doesn't "seems
to change" but it changes. Because we can see that, the caret, stays
way forward to the text. And, at some point, if we right text enough we
lose the sense of were we are writing... can you help me again?
Thanks,
Filipe Marcelino
Steve Barnett wrote:
Try adding this:

protected override void OnTextChanged(E ventArgs e)
{
base.OnTextChan ged(e);
Refresh();
}

Seemed to fix the problem for me... though there is the problem of painting
the caret to deal with!

Steve
"Filipe Marcelino" <fm********@gma il.comwrote in message
news:11******** **************@ e63g2000cwd.goo glegroups.com.. .
Hi Cor,

Has you may noticed I already set my textbox borderstyle to FixedSingle
(this.BorderSty le = BorderStyle.Fix edSingle;). Now I want to paint that
border (black by default) with blue for example.

If I'm not being clear please make me know to clarify you.
Thanks in advance,
Filipe Marcelino

Cor Ligthert [MVP] wrote:
Filipe,

Are you sure the propertie "borderstyl e" does not help you.
http://msdn.microsoft.com/library/de...styletopic.asp

Cor
"Filipe Marcelino" <fm********@gma il.comschreef in bericht
news:11******** *************@m 73g2000cwd.goog legroups.com...
Hi,

I'm trying to create a textbox inheriting from the standard textbox. I
would like to:

1. repaint the textbox border;
2. define a color for that border;

Till now I made this:

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

namespace Library.Control s
{
public class TextBox : System.Windows. Forms.TextBox
{
private enum MouseState
{
Focused,
Hoover,
Normal
}

private Color borderColor = Color.FromArgb( 128, 128, 128);
//Gray
private Color highlightColor = Color.FromArgb( 10, 36, 106);
//Blue
private Color hoverColor = Color.Silver; //Silver
private MouseState m_MouseState = MouseState.Norm al;

public TextBox()
{
this.MouseEnter += new EventHandler(On MouseEnter);
this.MouseLeave += new EventHandler(On MouseLeave);
this.MouseHover += new EventHandler(On MouseHover);
this.Enter += new EventHandler(On Enter);
this.Leave += new EventHandler(On Leave);
this.BorderStyl e = BorderStyle.Fix edSingle;

SetStyle(Contro lStyles.UserPai nt, true);

}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint(e) ;
e.Graphics.Draw String(Text, Font, new
SolidBrush(Fore Color), new PointF(0, 0));

switch (m_MouseState)
{
case MouseState.Focu sed:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(highlightCo lor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Hoov er:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(highlightCo lor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Norm al:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(borderColor ), 0, 0, Width - 1, Height - 1);
break;
}
}

#region Mouse Events
private void OnMouseEnter(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
private void OnMouseLeave(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}
private void OnMouseHover(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
#endregion

private void OnEnter(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Focu sed;
Invalidate();
}
private void OnLeave(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}

}
}

The problem is related with the text drawing. Somehow, when editing,
the textbox suddenlly uses other font then the default causing
missreading.

There's any way to solve this situation.
Thanks in advance for your attention,
Filipe Marcelino
Sep 13 '06 #5
I've tried but can't get the caret in the right place. To be honest though,
I think you're making a lot of work for yourself with this approach. If I
were to approach this problem, I'd go for creating a standard UserControl
with a text box in it:

partial class txtBox
{
private System.Componen tModel.IContain er components = null;

protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Disp ose();
}
base.Dispose(di sposing);
}

#region Component Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.txtTest = new System.Windows. Forms.TextBox() ;
this.SuspendLay out();
//
// txtTest
//
this.txtTest.Bo rderStyle =
System.Windows. Forms.BorderSty le.None;
this.txtTest.Do ck = System.Windows. Forms.DockStyle .Fill;
this.txtTest.Lo cation = new System.Drawing. Point(2, 2);
this.txtTest.Ma rgin = new System.Windows. Forms.Padding(1 );
this.txtTest.Mu ltiline = true;
this.txtTest.Na me = "txtTest";
this.txtTest.Si ze = new System.Drawing. Size(352, 23);
this.txtTest.Ta bIndex = 0;
this.txtTest.Te xt = "Test Text";
//
// txtBox
//
this.AutoScaleD imensions = new System.Drawing. SizeF(6F, 13F);
this.AutoScaleM ode = System.Windows. Forms.AutoScale Mode.Font;
this.Controls.A dd(this.txtTest );
this.Name = "txtBox";
this.Padding = new System.Windows. Forms.Padding(1 );
this.Size = new System.Drawing. Size(356, 27);
this.ResumeLayo ut(false);
this.PerformLay out();

}

#endregion

private System.Windows. Forms.TextBox txtTest;
}

Important thing to note is the padding on the user control (to give you room
to put the border) and the fact that the text box has no border and is
docked to fill the user control. This means that you don't have to handle
any of the painting of the text box, so won't have to deal with font sizes
or cope with the circumstance where your entered text is longer than the
text box (which your paint routine does not cope with now).

In the main body of the class, you'll need to provide accessors for the key
properties of the text box, but only for those that you desperately need,
such as the "Text" property and any events that you need to pass on.
(Alternatively, you can provide an accessot to get at the TextBox control).

public partial class txtBox : UserControl
{
public txtBox()
{
InitializeCompo nent();
}

public new string Text
{
get { return txtTest.Text; }
set { txtTest.Text = value; }
}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint(e) ;
// Text box takes care of itself. We just paint our border.
e.Graphics.Draw Rectangle(new System.Drawing. Pen(Color.Red), 1, 1,
Width-2, Height-2);
}

}

Obviously, you'll need to insert your logic for handling the mouse events. A
more complete set of code is:

public partial class txtBox : UserControl
{
private enum MouseState
{
Focused,
Hoover,
Normal
}

private Color borderColor = Color.FromArgb( 128, 128, 128);
//Gray
private Color highlightColor = Color.FromArgb( 10, 36, 106);
//Blue
private Color hoverColor = Color.Silver; //Silver
private MouseState m_MouseState = MouseState.Norm al;

public txtBox()
{
InitializeCompo nent();

txtTest.MouseEn ter += new EventHandler(On MouseEnter);
txtTest.MouseLe ave += new EventHandler(On MouseLeave);
txtTest.MouseHo ver += new EventHandler(On MouseHover);
txtTest.Enter += new EventHandler(On Enter);
txtTest.Leave += new EventHandler(On Leave);

}

public new string Text
{
get { return txtTest.Text; }
set { txtTest.Text = value; }
}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint(e) ;
switch (m_MouseState)
{
case MouseState.Focu sed:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(Color.Salmo n), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Hoov er:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(Color.Red), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Norm al:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(borderColor ), 0, 0, Width - 1, Height - 1);
break;
}
}

#region Mouse Events
private void OnMouseEnter(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
private void OnMouseLeave(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}
private void OnMouseHover(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
#endregion

private void OnEnter(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Focu sed;
Invalidate();
}
private void OnLeave(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}

}
That would have been my approach, anyway.It may not be the most efficient
(I'm only a beginner here) but it means I don't have to reproduce any of the
functionality of a text box and I always like it when I don't have a lot of
complicated tuff to do!

HTH
Steve
"Filipe Marcelino" <fm********@gma il.comwrote in message
news:11******** **************@ p79g2000cwp.goo glegroups.com.. .
Hi Steve,

thanks for your reply but I tried and, in fact, the font doesn't "seems
to change" but it changes. Because we can see that, the caret, stays
way forward to the text. And, at some point, if we right text enough we
lose the sense of were we are writing... can you help me again?
Thanks,
Filipe Marcelino
Steve Barnett wrote:
>Try adding this:

protected override void OnTextChanged(E ventArgs e)
{
base.OnTextChan ged(e);
Refresh();
}

Seemed to fix the problem for me... though there is the problem of
painting
the caret to deal with!

Steve
"Filipe Marcelino" <fm********@gma il.comwrote in message
news:11******* *************** @e63g2000cwd.go oglegroups.com. ..
Hi Cor,

Has you may noticed I already set my textbox borderstyle to FixedSingle
(this.BorderSty le = BorderStyle.Fix edSingle;). Now I want to paint that
border (black by default) with blue for example.

If I'm not being clear please make me know to clarify you.
Thanks in advance,
Filipe Marcelino

Cor Ligthert [MVP] wrote:
Filipe,

Are you sure the propertie "borderstyl e" does not help you.
http://msdn.microsoft.com/library/de...styletopic.asp

Cor
"Filipe Marcelino" <fm********@gma il.comschreef in bericht
news:11******* **************@ m73g2000cwd.goo glegroups.com.. .
Hi,

I'm trying to create a textbox inheriting from the standard textbox.
I
would like to:

1. repaint the textbox border;
2. define a color for that border;

Till now I made this:

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

namespace Library.Control s
{
public class TextBox : System.Windows. Forms.TextBox
{
private enum MouseState
{
Focused,
Hoover,
Normal
}

private Color borderColor = Color.FromArgb( 128, 128, 128);
//Gray
private Color highlightColor = Color.FromArgb( 10, 36, 106);
//Blue
private Color hoverColor = Color.Silver; //Silver
private MouseState m_MouseState = MouseState.Norm al;

public TextBox()
{
this.MouseEnter += new EventHandler(On MouseEnter);
this.MouseLeave += new EventHandler(On MouseLeave);
this.MouseHover += new EventHandler(On MouseHover);
this.Enter += new EventHandler(On Enter);
this.Leave += new EventHandler(On Leave);
this.BorderStyl e = BorderStyle.Fix edSingle;

SetStyle(Contro lStyles.UserPai nt, true);

}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint(e) ;
e.Graphics.Draw String(Text, Font, new
SolidBrush(Fore Color), new PointF(0, 0));

switch (m_MouseState)
{
case MouseState.Focu sed:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(highlightCo lor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Hoov er:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(highlightCo lor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Norm al:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(borderColor ), 0, 0, Width - 1, Height - 1);
break;
}
}

#region Mouse Events
private void OnMouseEnter(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
private void OnMouseLeave(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}
private void OnMouseHover(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
#endregion

private void OnEnter(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Focu sed;
Invalidate();
}
private void OnLeave(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}

}
}

The problem is related with the text drawing. Somehow, when editing,
the textbox suddenlly uses other font then the default causing
missreading.

There's any way to solve this situation.
Thanks in advance for your attention,
Filipe Marcelino


Sep 13 '06 #6
Steve,

I have a link to this, if it is to difficult, than please reply, than I will
see if I can set it to C#

http://www.vb-tips.com/dbpages.aspx?...0-58fd21b7e2ea

Cor

"Filipe Marcelino" <fm********@gma il.comschreef in bericht
news:11******** **************@ p79g2000cwp.goo glegroups.com.. .
Hi Steve,

thanks for your reply but I tried and, in fact, the font doesn't "seems
to change" but it changes. Because we can see that, the caret, stays
way forward to the text. And, at some point, if we right text enough we
lose the sense of were we are writing... can you help me again?
Thanks,
Filipe Marcelino
Steve Barnett wrote:
>Try adding this:

protected override void OnTextChanged(E ventArgs e)
{
base.OnTextChan ged(e);
Refresh();
}

Seemed to fix the problem for me... though there is the problem of
painting
the caret to deal with!

Steve
"Filipe Marcelino" <fm********@gma il.comwrote in message
news:11******* *************** @e63g2000cwd.go oglegroups.com. ..
Hi Cor,

Has you may noticed I already set my textbox borderstyle to FixedSingle
(this.BorderSty le = BorderStyle.Fix edSingle;). Now I want to paint that
border (black by default) with blue for example.

If I'm not being clear please make me know to clarify you.
Thanks in advance,
Filipe Marcelino

Cor Ligthert [MVP] wrote:
Filipe,

Are you sure the propertie "borderstyl e" does not help you.
http://msdn.microsoft.com/library/de...styletopic.asp

Cor
"Filipe Marcelino" <fm********@gma il.comschreef in bericht
news:11******* **************@ m73g2000cwd.goo glegroups.com.. .
Hi,

I'm trying to create a textbox inheriting from the standard textbox.
I
would like to:

1. repaint the textbox border;
2. define a color for that border;

Till now I made this:

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

namespace Library.Control s
{
public class TextBox : System.Windows. Forms.TextBox
{
private enum MouseState
{
Focused,
Hoover,
Normal
}

private Color borderColor = Color.FromArgb( 128, 128, 128);
//Gray
private Color highlightColor = Color.FromArgb( 10, 36, 106);
//Blue
private Color hoverColor = Color.Silver; //Silver
private MouseState m_MouseState = MouseState.Norm al;

public TextBox()
{
this.MouseEnter += new EventHandler(On MouseEnter);
this.MouseLeave += new EventHandler(On MouseLeave);
this.MouseHover += new EventHandler(On MouseHover);
this.Enter += new EventHandler(On Enter);
this.Leave += new EventHandler(On Leave);
this.BorderStyl e = BorderStyle.Fix edSingle;

SetStyle(Contro lStyles.UserPai nt, true);

}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint(e) ;
e.Graphics.Draw String(Text, Font, new
SolidBrush(Fore Color), new PointF(0, 0));

switch (m_MouseState)
{
case MouseState.Focu sed:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(highlightCo lor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Hoov er:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(highlightCo lor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Norm al:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(borderColor ), 0, 0, Width - 1, Height - 1);
break;
}
}

#region Mouse Events
private void OnMouseEnter(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
private void OnMouseLeave(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}
private void OnMouseHover(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
#endregion

private void OnEnter(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Focu sed;
Invalidate();
}
private void OnLeave(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}

}
}

The problem is related with the text drawing. Somehow, when editing,
the textbox suddenlly uses other font then the default causing
missreading.

There's any way to solve this situation.
Thanks in advance for your attention,
Filipe Marcelino


Sep 13 '06 #7
Filipe
Just had a thought, you can make this even simpler by not overriding the
OnPaint event. Since all you're doing now is drawing the border in a
specific colour, all you need to do is set the background colour of the
UserControl to the border colour you want.

Because you have the 1 pixel margin, the background of the user control is
effectively your border around the text box. So, if you set the background
of the user control, your text box gets a 1 pixel border of that colour.

You can then dump the additional burden of overriding OnPaint. You don't
need to save the mouse state and don't need to Invalidate() the control.
Just set the background in the mouse events.

Just a thought.
Steve
"Steve Barnett" <no****@nodomai n.comwrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
I've tried but can't get the caret in the right place. To be honest
though, I think you're making a lot of work for yourself with this
approach. If I were to approach this problem, I'd go for creating a
standard UserControl with a text box in it:

partial class txtBox
{
private System.Componen tModel.IContain er components = null;

protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Disp ose();
}
base.Dispose(di sposing);
}

#region Component Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.txtTest = new System.Windows. Forms.TextBox() ;
this.SuspendLay out();
//
// txtTest
//
this.txtTest.Bo rderStyle =
System.Windows. Forms.BorderSty le.None;
this.txtTest.Do ck = System.Windows. Forms.DockStyle .Fill;
this.txtTest.Lo cation = new System.Drawing. Point(2, 2);
this.txtTest.Ma rgin = new System.Windows. Forms.Padding(1 );
this.txtTest.Mu ltiline = true;
this.txtTest.Na me = "txtTest";
this.txtTest.Si ze = new System.Drawing. Size(352, 23);
this.txtTest.Ta bIndex = 0;
this.txtTest.Te xt = "Test Text";
//
// txtBox
//
this.AutoScaleD imensions = new System.Drawing. SizeF(6F, 13F);
this.AutoScaleM ode = System.Windows. Forms.AutoScale Mode.Font;
this.Controls.A dd(this.txtTest );
this.Name = "txtBox";
this.Padding = new System.Windows. Forms.Padding(1 );
this.Size = new System.Drawing. Size(356, 27);
this.ResumeLayo ut(false);
this.PerformLay out();

}

#endregion

private System.Windows. Forms.TextBox txtTest;
}

Important thing to note is the padding on the user control (to give you
room to put the border) and the fact that the text box has no border and
is docked to fill the user control. This means that you don't have to
handle any of the painting of the text box, so won't have to deal with
font sizes or cope with the circumstance where your entered text is longer
than the text box (which your paint routine does not cope with now).

In the main body of the class, you'll need to provide accessors for the
key properties of the text box, but only for those that you desperately
need, such as the "Text" property and any events that you need to pass on.
(Alternatively, you can provide an accessot to get at the TextBox
control).

public partial class txtBox : UserControl
{
public txtBox()
{
InitializeCompo nent();
}

public new string Text
{
get { return txtTest.Text; }
set { txtTest.Text = value; }
}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint(e) ;
// Text box takes care of itself. We just paint our border.
e.Graphics.Draw Rectangle(new System.Drawing. Pen(Color.Red), 1, 1,
Width-2, Height-2);
}

}

Obviously, you'll need to insert your logic for handling the mouse events.
A more complete set of code is:

public partial class txtBox : UserControl
{
private enum MouseState
{
Focused,
Hoover,
Normal
}

private Color borderColor = Color.FromArgb( 128, 128, 128);
//Gray
private Color highlightColor = Color.FromArgb( 10, 36, 106);
//Blue
private Color hoverColor = Color.Silver; //Silver
private MouseState m_MouseState = MouseState.Norm al;

public txtBox()
{
InitializeCompo nent();

txtTest.MouseEn ter += new EventHandler(On MouseEnter);
txtTest.MouseLe ave += new EventHandler(On MouseLeave);
txtTest.MouseHo ver += new EventHandler(On MouseHover);
txtTest.Enter += new EventHandler(On Enter);
txtTest.Leave += new EventHandler(On Leave);

}

public new string Text
{
get { return txtTest.Text; }
set { txtTest.Text = value; }
}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint(e) ;
switch (m_MouseState)
{
case MouseState.Focu sed:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(Color.Salmo n), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Hoov er:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(Color.Red), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Norm al:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(borderColor ), 0, 0, Width - 1, Height - 1);
break;
}
}

#region Mouse Events
private void OnMouseEnter(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
private void OnMouseLeave(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}
private void OnMouseHover(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
#endregion

private void OnEnter(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Focu sed;
Invalidate();
}
private void OnLeave(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}

}
That would have been my approach, anyway.It may not be the most efficient
(I'm only a beginner here) but it means I don't have to reproduce any of
the functionality of a text box and I always like it when I don't have a
lot of complicated tuff to do!

HTH
Steve
"Filipe Marcelino" <fm********@gma il.comwrote in message
news:11******** **************@ p79g2000cwp.goo glegroups.com.. .
>Hi Steve,

thanks for your reply but I tried and, in fact, the font doesn't "seems
to change" but it changes. Because we can see that, the caret, stays
way forward to the text. And, at some point, if we right text enough we
lose the sense of were we are writing... can you help me again?
Thanks,
Filipe Marcelino
Steve Barnett wrote:
>>Try adding this:

protected override void OnTextChanged(E ventArgs e)
{
base.OnTextChan ged(e);
Refresh();
}

Seemed to fix the problem for me... though there is the problem of
painting
the caret to deal with!

Steve
"Filipe Marcelino" <fm********@gma il.comwrote in message
news:11****** *************** *@e63g2000cwd.g ooglegroups.com ...
Hi Cor,

Has you may noticed I already set my textbox borderstyle to
FixedSingle
(this.BorderSt yle = BorderStyle.Fix edSingle;). Now I want to paint
that
border (black by default) with blue for example.

If I'm not being clear please make me know to clarify you.
Thanks in advance,
Filipe Marcelino

Cor Ligthert [MVP] wrote:
Filipe,

Are you sure the propertie "borderstyl e" does not help you.
http://msdn.microsoft.com/library/de...styletopic.asp

Cor
"Filipe Marcelino" <fm********@gma il.comschreef in bericht
news:11****** *************** @m73g2000cwd.go oglegroups.com. ..
Hi,

I'm trying to create a textbox inheriting from the standard
textbox. I
would like to:

1. repaint the textbox border;
2. define a color for that border;

Till now I made this:

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

namespace Library.Control s
{
public class TextBox : System.Windows. Forms.TextBox
{
private enum MouseState
{
Focused,
Hoover,
Normal
}

private Color borderColor = Color.FromArgb( 128, 128, 128);
//Gray
private Color highlightColor = Color.FromArgb( 10, 36, 106);
//Blue
private Color hoverColor = Color.Silver; //Silver
private MouseState m_MouseState = MouseState.Norm al;

public TextBox()
{
this.MouseEnter += new EventHandler(On MouseEnter);
this.MouseLeave += new EventHandler(On MouseLeave);
this.MouseHover += new EventHandler(On MouseHover);
this.Enter += new EventHandler(On Enter);
this.Leave += new EventHandler(On Leave);
this.BorderStyl e = BorderStyle.Fix edSingle;

SetStyle(Contro lStyles.UserPai nt, true);

}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint(e) ;
e.Graphics.Draw String(Text, Font, new
SolidBrush(For eColor), new PointF(0, 0));

switch (m_MouseState)
{
case MouseState.Focu sed:
e.Graphics.Draw Rectangle(new
System.Drawing .Pen(highlightC olor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Hoov er:
e.Graphics.Draw Rectangle(new
System.Drawing .Pen(highlightC olor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Norm al:
e.Graphics.Draw Rectangle(new
System.Drawing .Pen(borderColo r), 0, 0, Width - 1, Height - 1);
break;
}
}

#region Mouse Events
private void OnMouseEnter(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
private void OnMouseLeave(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}
private void OnMouseHover(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
#endregion

private void OnEnter(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Focu sed;
Invalidate();
}
private void OnLeave(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}

}
}

The problem is related with the text drawing. Somehow, when
editing,
the textbox suddenlly uses other font then the default causing
missreading.

There's any way to solve this situation.
Thanks in advance for your attention,
Filipe Marcelino



Sep 13 '06 #8
Man....you said "(I'm only a beginner here)"!!!
You're a GENIUS beginner NO???? ehehehehhe
Thanks for everything!!!! I'll give it a try.
Many thanks,
Filipe Marcelino

Steve Barnett wrote:
Filipe
Just had a thought, you can make this even simpler by not overriding the
OnPaint event. Since all you're doing now is drawing the border in a
specific colour, all you need to do is set the background colour of the
UserControl to the border colour you want.

Because you have the 1 pixel margin, the background of the user control is
effectively your border around the text box. So, if you set the background
of the user control, your text box gets a 1 pixel border of that colour.

You can then dump the additional burden of overriding OnPaint. You don't
need to save the mouse state and don't need to Invalidate() the control.
Just set the background in the mouse events.

Just a thought.
Steve
"Steve Barnett" <no****@nodomai n.comwrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
I've tried but can't get the caret in the right place. To be honest
though, I think you're making a lot of work for yourself with this
approach. If I were to approach this problem, I'd go for creating a
standard UserControl with a text box in it:

partial class txtBox
{
private System.Componen tModel.IContain er components = null;

protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Disp ose();
}
base.Dispose(di sposing);
}

#region Component Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.txtTest = new System.Windows. Forms.TextBox() ;
this.SuspendLay out();
//
// txtTest
//
this.txtTest.Bo rderStyle =
System.Windows. Forms.BorderSty le.None;
this.txtTest.Do ck = System.Windows. Forms.DockStyle .Fill;
this.txtTest.Lo cation = new System.Drawing. Point(2, 2);
this.txtTest.Ma rgin = new System.Windows. Forms.Padding(1 );
this.txtTest.Mu ltiline = true;
this.txtTest.Na me = "txtTest";
this.txtTest.Si ze = new System.Drawing. Size(352, 23);
this.txtTest.Ta bIndex = 0;
this.txtTest.Te xt = "Test Text";
//
// txtBox
//
this.AutoScaleD imensions = new System.Drawing. SizeF(6F, 13F);
this.AutoScaleM ode = System.Windows. Forms.AutoScale Mode.Font;
this.Controls.A dd(this.txtTest );
this.Name = "txtBox";
this.Padding = new System.Windows. Forms.Padding(1 );
this.Size = new System.Drawing. Size(356, 27);
this.ResumeLayo ut(false);
this.PerformLay out();

}

#endregion

private System.Windows. Forms.TextBox txtTest;
}

Important thing to note is the padding on the user control (to give you
room to put the border) and the fact that the text box has no border and
is docked to fill the user control. This means that you don't have to
handle any of the painting of the text box, so won't have to deal with
font sizes or cope with the circumstance where your entered text is longer
than the text box (which your paint routine does not cope with now).

In the main body of the class, you'll need to provide accessors for the
key properties of the text box, but only for those that you desperately
need, such as the "Text" property and any events that you need to pass on.
(Alternatively, you can provide an accessot to get at the TextBox
control).

public partial class txtBox : UserControl
{
public txtBox()
{
InitializeCompo nent();
}

public new string Text
{
get { return txtTest.Text; }
set { txtTest.Text = value; }
}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint(e) ;
// Text box takes care of itself. We just paint our border.
e.Graphics.Draw Rectangle(new System.Drawing. Pen(Color.Red), 1, 1,
Width-2, Height-2);
}

}

Obviously, you'll need to insert your logic for handling the mouse events.
A more complete set of code is:

public partial class txtBox : UserControl
{
private enum MouseState
{
Focused,
Hoover,
Normal
}

private Color borderColor = Color.FromArgb( 128, 128, 128);
//Gray
private Color highlightColor = Color.FromArgb( 10, 36, 106);
//Blue
private Color hoverColor = Color.Silver; //Silver
private MouseState m_MouseState = MouseState.Norm al;

public txtBox()
{
InitializeCompo nent();

txtTest.MouseEn ter += new EventHandler(On MouseEnter);
txtTest.MouseLe ave += new EventHandler(On MouseLeave);
txtTest.MouseHo ver += new EventHandler(On MouseHover);
txtTest.Enter += new EventHandler(On Enter);
txtTest.Leave += new EventHandler(On Leave);

}

public new string Text
{
get { return txtTest.Text; }
set { txtTest.Text = value; }
}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint(e) ;
switch (m_MouseState)
{
case MouseState.Focu sed:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(Color.Salmo n), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Hoov er:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(Color.Red), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Norm al:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(borderColor ), 0, 0, Width - 1, Height - 1);
break;
}
}

#region Mouse Events
private void OnMouseEnter(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
private void OnMouseLeave(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}
private void OnMouseHover(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
#endregion

private void OnEnter(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Focu sed;
Invalidate();
}
private void OnLeave(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}

}
That would have been my approach, anyway.It may not be the most efficient
(I'm only a beginner here) but it means I don't have to reproduce any of
the functionality of a text box and I always like it when I don't have a
lot of complicated tuff to do!

HTH
Steve
"Filipe Marcelino" <fm********@gma il.comwrote in message
news:11******** **************@ p79g2000cwp.goo glegroups.com.. .
Hi Steve,

thanks for your reply but I tried and, in fact, the font doesn't "seems
to change" but it changes. Because we can see that, the caret, stays
way forward to the text. And, at some point, if we right text enough we
lose the sense of were we are writing... can you help me again?
Thanks,
Filipe Marcelino
Steve Barnett wrote:
Try adding this:

protected override void OnTextChanged(E ventArgs e)
{
base.OnTextChan ged(e);
Refresh();
}

Seemed to fix the problem for me... though there is the problem of
painting
the caret to deal with!

Steve
"Filipe Marcelino" <fm********@gma il.comwrote in message
news:11******* *************** @e63g2000cwd.go oglegroups.com. ..
Hi Cor,

Has you may noticed I already set my textbox borderstyle to
FixedSingle
(this.BorderSty le = BorderStyle.Fix edSingle;). Now I want to paint
that
border (black by default) with blue for example.

If I'm not being clear please make me know to clarify you.
Thanks in advance,
Filipe Marcelino

Cor Ligthert [MVP] wrote:
Filipe,

Are you sure the propertie "borderstyl e" does not help you.
http://msdn.microsoft.com/library/de...styletopic.asp

Cor
"Filipe Marcelino" <fm********@gma il.comschreef in bericht
news:11******* **************@ m73g2000cwd.goo glegroups.com.. .
Hi,

I'm trying to create a textbox inheriting from the standard
textbox. I
would like to:

1. repaint the textbox border;
2. define a color for that border;

Till now I made this:

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

namespace Library.Control s
{
public class TextBox : System.Windows. Forms.TextBox
{
private enum MouseState
{
Focused,
Hoover,
Normal
}

private Color borderColor = Color.FromArgb( 128, 128, 128);
//Gray
private Color highlightColor = Color.FromArgb( 10, 36, 106);
//Blue
private Color hoverColor = Color.Silver; //Silver
private MouseState m_MouseState = MouseState.Norm al;

public TextBox()
{
this.MouseEnter += new EventHandler(On MouseEnter);
this.MouseLeave += new EventHandler(On MouseLeave);
this.MouseHover += new EventHandler(On MouseHover);
this.Enter += new EventHandler(On Enter);
this.Leave += new EventHandler(On Leave);
this.BorderStyl e = BorderStyle.Fix edSingle;

SetStyle(Contro lStyles.UserPai nt, true);

}

protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint(e) ;
e.Graphics.Draw String(Text, Font, new
SolidBrush(Fore Color), new PointF(0, 0));

switch (m_MouseState)
{
case MouseState.Focu sed:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(highlightCo lor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Hoov er:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(highlightCo lor), 0, 0, Width - 1, Height - 1);
break;
case MouseState.Norm al:
e.Graphics.Draw Rectangle(new
System.Drawing. Pen(borderColor ), 0, 0, Width - 1, Height - 1);
break;
}
}

#region Mouse Events
private void OnMouseEnter(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
private void OnMouseLeave(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}
private void OnMouseHover(ob ject sender, System.EventArg s e)
{
m_MouseState = MouseState.Hoov er;
Invalidate();
}
#endregion

private void OnEnter(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Focu sed;
Invalidate();
}
private void OnLeave(object sender, System.EventArg s e)
{
m_MouseState = MouseState.Norm al;
Invalidate();
}

}
}

The problem is related with the text drawing. Somehow, when
editing,
the textbox suddenlly uses other font then the default causing
missreading.

There's any way to solve this situation.
Thanks in advance for your attention,
Filipe Marcelino
Sep 13 '06 #9

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

Similar topics

11
14257
by: Nicolas Girard | last post by:
Hi, Forgive me if the answer is trivial, but could you tell me how to achieve the following: {k1:,k2:v3,...} --> ,,,...] The subtle point (at least to me) is to "flatten" values that are lists. Thanks in advance,
699
34055
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
13
3425
by: raykyoto | last post by:
Hi all, I'm sure this is a popular question that comes up every few months here. Indeed, I've looked at some of the past postings, but I would like to ask things differently. Basically, I'm using a flat file to storing data. I have to do this because mySQL is not installed on my web server, and I am not the root user. The amount of data is so small, that it isn't worth a full-blown database anyway. However, while the data is...
22
3012
by: Daniel Billingsley | last post by:
Ok, I wanted to ask this separate from nospam's ridiculous thread in hopes it could get some honest attention. VB6 had a some simple and fast mechanisms for retrieving values from basic text files, which in turn could be simply and easily maintained with notepad. I understand the benefits of XML, really, but in the case of configuration files it seems it is almost always nothing more than unnecessary complexity, both in accessing them...
1
4324
by: Morten Wennevik | last post by:
Like a Button and RadioButton has a FlatStyle and a TextBox has a BorderStyle, is it possible to set a ComboBox to appear in the same way? No 3D borders. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
3
3559
by: olivier | last post by:
I would like to know how to design a flat dropdownlist (border 1px solid) to use with asp.net (it seems no possible to modify this control's style unlike the textbox). thank's a lot
9
2190
by: FFMG | last post by:
In my site I have a config table, (MySQL), with about 30 entries; the data is loaded on every single page load. This is not the only call to the db, (we do a total of about 8 calls to the db). As with many configurations settings, once the options are set the values will not change much. So I thought it would be a good idea to move the data to a flat file. I have written a small wrapper class to first look for the file, if it exists...
2
6144
by: murthydb2 | last post by:
Hi My requirement is that i have to write a stored procedure in db2 and that will be executed in a batch file . Any system error or validation error that occurs inside the db2 sp during the execution need to be written in external flat file ( Log file to know the error ) . Is there anything similar in db2 like UTL_FILE in oracle . Please find the sample coding in oracle which will write the output to a external flat...
15
5276
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to show - text boxes, input boxes, buttons, hyperlinks ie the usual. The data is not obtained directly from a database.
0
8968
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9473
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9259
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4569
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3279
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
3
2193
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.