<p>I am creating a Windows Forms control derived from UserControl to be embedded in a WPF app. I have generally followed the procedures given in <a href="http://www.codeproject.com/KB/WPF/WPFOpenGL.aspx?display=Print" rel="nofollow noreferrer">this link</a>.</p>

<pre><code>public ref class CTiledImgViewControl : public UserControl
{
...

virtual void OnPaint( PaintEventArgs^ e ) override;

...
};
</code></pre>

<p>And in my CPP file:</p>

<pre><code>void CTiledImgViewControl::OnPaint( PaintEventArgs^ e )
{
    UserControl::OnPaint(e);
    // do something interesting...
}
</code></pre>

<p>Everything compiles and runs, however the OnPaint method is never getting called.</p>

<p>Any ideas of things to look for? I've done a lot with C++, but am pretty new to WinForms and WPF, so it could well be something obvious...</p>

The
```
OnPaint
```
won't normally get called in a
```
UserControl
```
unless you set the appropriate style when it is constructed using the
```
SetStyle
```
method. You need to set the
```
UserPaint
```
style to true for the
```
OnPaint
```
to get called.
```
```
SetStyle(ControlStyles::UserPaint, true);
```
```
Update
I recently encountered this issue myself and went digging for an answer. I wanted to perform some calculations during a paint (to leverage the unique handling of paint messages) but I wasn't always getting a call to
```
OnPaint
```
.
After digging around with Reflector, I discovered that
```
OnPaint
```
is only called if the clipping rectangle of the corresponding
```
WM_PAINT
```
message is not empty. My
```
UserControl
```
instance had a child control that filled its entire client region and therefore, clipped it all. This meant that the clipping rectangle was empty and so no
```
OnPaint
```
call.
I worked around this by overriding
```
WndProc
```
and adding a handler for
```
WM_PAINT
```
directly as I couldn't find another way to achieve what I wanted.