addhandler problem

B

Benjamien De Vos

hello,

I made a usercontrol, and I add it to my form at runtime. If my mouse enters
that control, a sub has to start.
But for some reason, the trigger doesn't work. When I enter the usercontrol
with my mouse nothing happens.

Can anyone please help me? this is the code:

For Each oCard In arlCardsHand

Dim newUcSmallCard As New ucSmallCard

newUcSmallCard.showCard(oCard)

pnlHand.Controls.Add(newUcSmallCard)

newUcSmallCard.Enabled = True

newUcSmallCard.Location = New System.Drawing.Point(iPlace, 8)

newUcSmallCard.Size = New System.Drawing.Size(64, 88)

iPlace = iPlace + 91

AddHandler newUcSmallCard.MouseEnter, AddressOf smallcard_MouseEnter

Next



and then the sub that should start (but doesn't :( )



Private Sub smallcard_MouseEnter(ByVal sender As Object, ByVal e As
System.EventArgs)

Dim smmcrd As ucSmallCard = sender

MessageBox.Show("u klikte op " & smmcrd.Card.ToString)

UcCard1.showCard(sender.Card)

End Sub
 
T

Tom Leylan

Does your ucSmallCard class raise the Mouse events?

I will mention that you should turn option strict on... you will notice your
implicit cast is caught. It doesn't stop your code from working but a
DirectCast() would be nice.
Dim smmcrd As ucSmallCard = sender

Also just a suggestion but you are declaring the newUcSmallCard variable,
what looks like might be assigning the card object, then adding it to the
collection and only then changing the way it looks. Might it not be easier
to read if you declared it, made all the settings and then added it to the
collection? Something along the lines of:

Dim newUcSmallCard As New ucSmallCard

With newUcSmallCard
.showCard(oCard)
.Enabled = True
.Location = New System.Drawing.Point(iPlace, 8)
.Size = New System.Drawing.Size(64, 88)
End With

pnlHand.Controls.Add(newUcSmallCard)


Is usSmallCard inheriting from PictureBox or something similar?

Tom
 
B

Benjamien De Vos

I fount the problem, My usercontrol had a panel with docking full. Just had
to delete the panel and it worked.
thanx a lot!
 

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

Similar Threads


Top