DrawString text sometimes not visible

  • Thread starter Thread starter Mazen
  • Start date Start date
M

Mazen

I have a problem with the e.Graphics.DrawString.

I am using the code below to display text strings on a
panel embedded in a tab control. The text i specify in
DrawString is displayed on the screen, however, if the
tab control's selected page is different from the string
output page, the text doesnt appear. It seems that
DrawString displays the test only when the tab page i am
writing to is visible, if the tab control is shifted to
another page, the string doesnt seem to appear when i
select the correct tab again.

Let me know in case there is a solution for this in order
to make the text visible even if the output tabpage is
not the visble one at the time that the DrawString
command is executed.

Thanks


Inside OnPaint(PaintEventArgs e):

for (int i = 0; i <currentsXx.Count; i++)//
{
e.Graphics.DrawString((string)PrintedX
,font1,new SolidBrush(Color.Black), (int)(currentsXx
)-6,dimY+2*marginY-20);
}
 
Let me know in case there is a solution for this in order
to make the text visible even if the output tabpage is
not the visble one at the time that the DrawString
command is executed.

I am not sure of exactly whay you are trying to achieve but:
The OnPaint routine is used to paint visible areas of the screen; thre is no point in painting something that is not visible (and its more efficient to repaint only what has been invalidated than everything).
The OnPaint routine is associated with a Control, or Control derived class. So each tab page will have its own OnPaint routine; within that routine you need to paint that page. So if on page A you set a value that affects how page B is displayed, you need to set the data used by page B, not try to paint it in page A's paint routine, so that when page B is brought to the fore its OnPaint routine knows what to draw.
HTH,
Ian Cooper
wwww.dnug.org.uk
 
Back
Top