Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

This one is really baffling me..

 

My project adds controls in a For Next loop at startup, each control when added has AddHandlers specified to link the mouse events to that control. I then pass the event that is called to a function which sets the properties of that control.. so now I can change the image or text properties for each event.

 

Here's the problem. I call the Setproperties function when the control is originally created, and then each time an event is called.

 

The first control that is added works fine, it responds to all events, and sets the properties for each.

 

Every control after that, when it is originally added it sets the properties, but does not set them when the events occur. The events are however firing, it's just not setting the properties for the event. Any ideas as to why this might be happening?

 

I am sure this might be confusing, and I can add the code when I get home, but it's been bothering me all day! :)

 

Thanks in advance,

 

liquid8

Posted

ItemCollection is a collection of strings with names for a new control, newPage is a Form, and SkinnedItem is a Class which inherits a panel, and has a few extra properties

 

Here is the initial adding of the controls

 

      Dim strInfo As String
       'Add each Item to the page
       For Each strInfo In itemCollection
           Dim newItem As New SkinnedItem()
           'Set Item Properties
           newItem.Name = strInfo
           newItem.SetItemProps(newItem, strInfo)
           newItem.Initialize
           'Add the Button
           newPage.Controls.Add(newItem)
       Next

 

This is the code in the initialize method for a SkinnedItem which attaches the events

 

Public Sub Initialize()
           AddHandler Me.MouseEnter, AddressOf Mouse_Enter
           AddHandler Me.MouseLeave, AddressOf Mouse_Leave
           AddHandler Me.MouseUp, AddressOf Mouse_Up
           AddHandler Me.MouseDown, AddressOf Mouse_Down
End Sub

 

Here is the SetItemProps method

 

Public Sub SetItemProps(ByVal Item As Object, ByVal ItemName As String, optional EventName as string)
         Select Case EventName
            Case "onmouseenter"
               Item.BackgroundImage = Image.FromFile("C:\temp\image1.jpg")
         End Select
End Sub

 

And here is the Event Code

 

Public Sub Mouse_Enter(ByVal sender As Object, ByVal e As System.EventArgs)
       If sender.GetType.Name.ToString = "SkinnedItem" Then
           SetItemProps(sender, sender.name, "onmouseenter")
       End If
End Sub

 

I had to simplify some of the code, to make it understandable as I am reading all the properties for each event from an xml file, but if you don't see anything in this... I could attach the project.

 

Thanks a bunch,

 

liquid8

  • *Experts*
Posted

Have you set some breakpoints to see if you're: getting in the Mouse_Enter event, if you are getting in that sender's type is "SkinnedItem", and if so then SetItemProps is getting called and falling into the .BackgroundImage code?

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

Ive run all the way through many times and it seems to be getting the correct values for the 2nd control that is added, I see no difference between that and the 1st one.

 

I think it has something to do with the sender but i just can't figure it out....

 

an important bit of info i left out, the SkinnedItem class adds a Label to itself (i needed to use a panel for certain reasons, but I also needed to change the offset of the label from the panels BG image... best way i could figure to do it) anyways.. so maybe the sender is confusing the two... still, I had that problem before, and all it did was just change the properties of the Label to the SkinnedItems properties..

 

that being said, when i break on the mouse event, it is showing that the sender is SkinnedItem, so I dunno...

 

thanks guys,

 

liquid8

Posted (edited)

Well, I did a seperate test adding the controls dynamically, then attaching the events, and it works fine, so I will just have to bang my head against the wall till i figure out what in my code is causing the prob ;)

 

I will post when I figure out what I'm doing wrong.. Just a note, I am not using a seperate class for the handlers on the test, so somethings going on in there..

 

liquid8

 

 

********** Found It **********

 

It was getting incorrect values from the XML. Anyways, my coding was incorrect for searching the XML, and it was basically retrieving the same information for every event.. thereby it was doing everything, just not changing..

 

Thanks guys,

 

liquid8

Edited by liquid8

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...