retype code or what?

thejeraldo

Well-known member
Joined
Jun 9, 2009
Messages
70
Location
Philippines
Programming Experience
1-3
hey guys, need help around here. i have a groupbox with buttons that has codes on it. i cut the groupbox and placed it on a panel. then since i wasnt satisfied with what ive done, i cut groupbox out of the panel and deleted the panel. the code was still there for the buttons inside the panel, but its not working anymore. i tried to build,rebuild but it still doesnt work. any way i can make this work again. i couldnt use undo command since ive already close VS.

thanks in advance guys!
 
to add to this.. this is how my code looks like:

VB.NET:
Public Class frmMain

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblDescription.Text = ""
    End Sub

    Private Sub cmdE_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs)
        Label1.ForeColor = Color.RoyalBlue
        lblDescription.Text = "Manage employee information, history, performance, medical records" & vbNewLine & "and more."
    End Sub

    Private Sub cmdE_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs)
        Label1.ForeColor = Color.Black
    End Sub

    Private Sub cmdA_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs)
        Label2.ForeColor = Color.DeepPink
        lblDescription.Text = "Daily time attendance, schedules and other attendance related tasks."
    End Sub

    Private Sub cmdA_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs)
        Label2.ForeColor = Color.Black
    End Sub

    Private Sub cmdP_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs)
        Label3.ForeColor = Color.MediumSeaGreen
        lblDescription.Text = "Mini payroll."
    End Sub

    Private Sub cmdP_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs)
        Label3.ForeColor = Color.Black
    End Sub

    Private Sub frmMain_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseHover
        lblDescription.Text = ""
    End Sub

    Private Sub GroupBox1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs)
        lblDescription.Text = ""
    End Sub

    Private Sub GroupBox2_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs)
        lblDescription.Text = ""
    End Sub

End Class
 
Drag controls, don't Cut, and the handlers are preserved. When you Cut the controls are removed from the container and any link to code behind must be broken.

To resolve you can add the Handles again either by typing them in or selecting them in Designer; select the control, select Events view in Properties window, find the events, select the handler methods.
 
Wow! Thanks a lot JohnH!
i just noticed too that i can set a controls events to use the same code that are on other control's events. is this advisable? or does this have any side effects? thanks.
 
Wow! Thanks a lot JohnH!
i just noticed too that i can set a controls events to use the same code that are on other control's events. is this advisable? or does this have any side effects? thanks.
If you want to do the same thing for two different events then you certainly should use the same method to handle them. If you need to know which object raised the event you can reference it using the 'sender' parameter.
 
I'm sure I've Cut stuff before and not had the handler links disappear. Maybe that was in C# ..
 
I'm sure I've Cut stuff before and not had the handler links disappear. Maybe that was in C# ..
I just tried it in C# and the result was the same. I added a Button to a form and then created a Click event handler. I then cut the Button and examined the designer code and all traces of the Button were gone. I then pasted the Button and examined the designer code again and most had been restored but the Click event handler wasn't. My guess is that Microsoft decided that the original methods might not exist so they just wouldn't bother looking for them.
 
Indeed, you're correct!

As a further tip to JohnH's dragging suggestion, I'd recommend showing the DocumentOutline window; it shows a tree rep of the components on the form, and makes selecting things mnuch easier. You can also drag items in teh Doc Outline window to move them into different panels; just remember that they keep their location attributes, so you might find that they disappear under other controls or out of view. Manually editing the location can bring it into view
 
Back
Top