problem with CreateGraphics.

  • Thread starter Thread starter RickDee
  • Start date Start date
R

RickDee

I really can't understand on how to use CreateGraphics. Even though I have
follow what is shown in many sites, I can't get it working at all.

For example.

I have textbox name textbox1. I create a method as shown below :

public void DrawTextBox()
{
Graphics g = textBox1.CreateGraphics();
g.DrawString("Hello", new Fonr("Verdana", 8), new SolidBrush(Color.Red),
0, 0);
}

Then in the Window application, I call this method. But the text box just do
not want to display anything.

What is going on ?? What is the thing that I don't understand actually ?

Thanks
Regards
 
Textboxes can be tricky

You can do the same with

public void DrawTextBox()
{
textBox1.Text = "Hello";
textBox1.Font = new Font("Verdana", 8);
textBox1.ForeColor = Color.Red;
}

but I guess it wouldn't be the same.

To create fully customized textboxes I think you need to create your own
textbox class and override some function. I could be wrong.
 
I have textbox name textbox1. I create a method as shown below :
public void DrawTextBox()
{
Graphics g = textBox1.CreateGraphics();
g.DrawString("Hello", new Fonr("Verdana", 8), new SolidBrush(Color.Red),
0, 0);
}

Then in the Window application, I call this method. But the text box just do
not want to display anything.

What is going on ?? What is the thing that I don't understand actually ?


you should override OnPaint if you want to draw something. if you draw
outside OnPaint, your paintings will be overdrawn by the window.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu
[noncommercial and no ****ing ads]
 
Thanks for the input so far.

Actually my aim is to build a list box where I can add text with different
color in it. I have checked out the website and found that the OnPaint
method was been mentioned, but the problem is that I could not find the
OnPaint method for ListBox in the Object Browser.

Does anybody has some simple sample code to lead me or a good site where I
can refer to ?

Thanks
Regards


****************************************************************************
*****
cody said:
I have textbox name textbox1. I create a method as shown below :

public void DrawTextBox()
{
Graphics g = textBox1.CreateGraphics();
g.DrawString("Hello", new Fonr("Verdana", 8), new SolidBrush(Color.Red),
0, 0);
}

Then in the Window application, I call this method. But the text box
just
do
not want to display anything.

What is going on ?? What is the thing that I don't understand actually ?


you should override OnPaint if you want to draw something. if you draw
outside OnPaint, your paintings will be overdrawn by the window.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu
[noncommercial and no ****ing ads]
 
Back
Top