Custom control creation problem, please....

R

Radu

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top