First of all: TextBoxes
are old legacy and rather special Controls that do not support all things normal controls let you do.
Among the things that won't work are
- Setting a BackgroundImage
- Owner-drawing them
The latter includes any drawing in its Paint/OnPaint
events.
You can code and hook-up the Paint
event, but it won't get called.
You still can draw onto a TextBox
using CreateGraphics
, if you do it right, but as always with this function the result is non-persistent and will go away as soon as the system refreshes the TextBox
itself, which is super-fast: as soon as you move your cursor over it the circle you draw may disappear..
The code to do it would have to look similar to this:
Graphics g = yourTextBox.CreateGraphics();
g.FillEllipse(Brushes.Red, yourTextBox.Width - 22, 2, 11, 11);
But as I said this will not persist, so it has little or no value.
If you want to draw onto something with a visible Text
property you can use a Label
:
private void yourLabel_Paint(object sender, PaintEventArgs e)
{
e.Graphics.FillEllipse(Brushes.Red, yourLabel.Width - 22, 2, 11, 11);
}


The result looks the same, but only the dot in the Label
will persist, e.g. a Minimize-Maximize of the form.. In fact the dot in the TextBox
didn't even survive calling my screenshot program, so I had use resort to pressing the Print-Key
!
For drawing circles upon mouseclicks onto normal controls see this post!