Repaint Event

  • Thread starter Thread starter Tamir Khason
  • Start date Start date
T

Tamir Khason

Is there something RePaint event?
I have a couple of controls where I draw using control.CreateGraphics, BUT
when I lost focus or do something inside the contorl (click ,etc) all
graphics are disappears
What the name of the event to handle in order to be able to repaint the
graphics on lost?
 
Hi Tamir,

Thank you for posting in the community! My name is Jeffrey, and I will be
assisting you on this issue.

Based on my understanding, you want to show graphics that was created out
using Control.CreateGraphics well in WinForm.
==============================================
Based on my experience, when your control loses focus or being clicked, the
Paint event will fires. So I think if you invoke your
Control.CreateGraphics code in the control's Paint event, your graphics
will not disappear.

Also, if in some event, your control does not paint well, you can
explicitly call the Control.Invalidate method to force the control to
repaint.

If it still does not work, please paste some sample code, I will work with
you.
==============================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
I tried the both
In onPaint event (on mainForm and every one of controls) is does not seemed
to help. Invocation of Invalidate function CLEARS all graphics drawn
Follow the code of drawing I do

private void drawCant(TSComponents.TSTabButton button)

{

//this.Invalidate();

//this.Refresh();

Graphics gr_Middle = this.pnlMiddle.CreateGraphics();

Graphics gr_Down = this.pnlDown.CreateGraphics();

gr_Middle.Clear(this.pnlMiddle.BackColor);

gr_Down.Clear(this.pnlDown.BackColor);

Pen p = new Pen(button.ForeColorClick,2);

Point[] pts_Middle =

{

new Point(button.Location.X+2,0),

new Point(2,2),

new Point(2,pnlMiddle.Height),

new Point(pnlMiddle.Width-2,pnlMiddle.Height),

new Point(pnlMiddle.Width-2,2),

new Point(button.Location.X+button.Width-2,2),

new Point(button.Location.X+button.Width-2,0)

};

Point[] pts_Down =

{

new Point(button.Location.X+2,0),

new Point(button.Location.X+2,2),

new Point(2,2),

new Point(2,pnlDown.Height-2),

new Point(pnlDown.Width-2,pnlDown.Height-2),

new Point(pnlDown.Width-2,2),

new Point(button.Location.X+button.Width-2,2),

new Point(button.Location.X+button.Width-2,0)

};

Point[] pts_Down_Alone =

{

//new Point(button.Location.X+2,0),

//new Point(button.Location.X+2,2),

new Point(2,0),

new Point(2,pnlDown.Height-2),

new Point(pnlDown.Width-2,pnlDown.Height-2),

new Point(pnlDown.Width-2,0),

//new Point(button.Location.X+button.Width-2,2),

//new Point(button.Location.X+button.Width-2,0)

};


if (pnlMiddle.Visible)

gr_Middle.DrawLines(p,pts_Middle);


if(pnlMiddle.Visible)

gr_Down.DrawLines(p,pts_Down_Alone);

else

gr_Down.DrawLines(p,pts_Down);

gr_Middle.Dispose();

gr_Down.Dispose();

//this.pnlMiddle.Invalidate();

//this.pnlDown.Invalidate();


}



"Jeffrey Tan[MSFT]" said:
Hi Tamir,

Thank you for posting in the community! My name is Jeffrey, and I will be
assisting you on this issue.

Based on my understanding, you want to show graphics that was created out
using Control.CreateGraphics well in WinForm.
==============================================
Based on my experience, when your control loses focus or being clicked, the
Paint event will fires. So I think if you invoke your
Control.CreateGraphics code in the control's Paint event, your graphics
will not disappear.

Also, if in some event, your control does not paint well, you can
explicitly call the Control.Invalidate method to force the control to
repaint.

If it still does not work, please paste some sample code, I will work with
you.
==============================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Tamir,

Thanks for your feedback.

=============================================
I have tried your code, it really does not work.

To make the graphics stay permanently, you should hook in the Paint event
and use System's Graphics object to draw your graphic.

If you create and use your own Graphics object, you will draw
asynchronously on the graphics of another control, the control may refresh
its surface at any time, destroying your work in the process.

For more information, please refer to:
http://www.bobpowell.net/pictureboxhowto.htm

You should do like this:
private void button2_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Graphics g =e.Graphics;
Pen blackPen = new Pen(Color.Red, 3);

float x = 0.0F;
float y = 0.0F;
float width = 10.0F;
float height = 10.0F;
// Draw rectangle to screen.
g.DrawRectangle(blackPen, x, y, width, height);
//g.Dispose(); You can not Dispose the system's Graphics object
}

===============================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I will work with you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Tamir,

Does my reply resolve your issue?
If you still have anything unclear, please feel free to tell me. I will
work with you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thank you for your response,
however It impossible in current project to use paint event in order to
initialize custom draw due the custom draw occured and requested by external
procedure.
Is there other way to do it?
 
Hi Tamir,

Thanks for your feedback.

On Windows Form, the system will take charge of the paint of the control.
If you only custom draw your graphics once on the form, then it will be
refreshed immediately and it will disappear.

The only way you are notified is paint event, so I think you must place
your drawing code in this event.

For your issue, I did not see the TRUE obstacle of placing drawing code in
the paint event. Can you show me the KEY difficulty?

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Tamir,

Is your problem resolved?
If you still have anything unclear, please feel free to tell me, I will
work with you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top