You can update the control style to add the ResizeRedraw flag.
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.setstyle.aspx To have the custom UserControl take up the entire client area of its
container (parent) set the UserControl's Dock property to DockStyle.Fill.
--
Tim Wilson
..NET Compact Framework MVP
[quoted text, click to view] "Radu" <cuca_macaii2000@yahoo.com> wrote in message
news:1144275587.827445.122140@t31g2000cwb.googlegroups.com...
> Hi. I am creating a user control in vs2005 which is supposed to provide
> a fancy gradient background - in theory, you just drop it on a form,
> you set the start/end colors, the gradient type, and you're done....
> but that's in theory. It should repaint itself, it should take the size
> of the client form (the form you're dropping it on), and it should
> resize & repaint itself when the client form is resized.
>
> I have added the following proc for forcing a repaint when the user
> control is resized:
>
> ___________________________________
> Private Sub GradientBackground_Resize(ByVal sender As Object, ByVal e
> As EventArgs) Handles MyBase.Resize
> Me.Invalidate()
> End Sub
> ___________________________________
>
> I have also added this for making the user control take the full size
> of the client form:
>
> ___________________________________
> Sub Autoresize(ByVal sender As Object, ByVal e As System.EventArgs)
> Handles MyBase.HandleCreated
> Me.Size = Me.FindForm.ClientSize
> Me.Location = New Point(0, 0)
> End Sub
> ___________________________________
>
> Nice and dandy. It works until the user resizes the client.
>
> I DON'T KNOW how to make the user control resize when the client form
> gets resized. Of course, I could write code in the client form, but
> that defeats the purpose of the whole exercise, isn't it ? The user
> control should be self contained.
>
> How would one do that ? One idea I had was to somehow obtain a handle
> to the container (the client form) like so:
>
> ___________________________________
> Dim WithEvents m_ClientForm As System.Windows.Forms.Form
>
> Public Sub New()
> m_ClientForm = Me.Parent
> End Sub
>
> and then define a proc like this:
>
> Sub AutoresizeToClientForm(ByVal sender As Object, ByVal e As
> EventArgs) Handles m_ClientForm.Resize
> Autoresize(sender, e)
> End Sub
> ___________________________________
>
> but it doesn't work. I also tried with Me.Container. Both are always
> NOTHING...
>
>
> How could I solve this problem, please ?
>
> Thank you very much.
> Alex
>