Start off by simplifying things and try to see what exactly is happening:
Private Sub SelectedLabel_MouseDoubleClick(sender As Object, e As MouseEventArgs)
SelectedLabel = DirectCast(sender, Label)
MainContainer.Controls.Remove(SelectedLabel)
SelectedPanel.Controls.Add(SelectedLabel)
End Sub
Now, when you double click a label, it will be removed from the main panel and moved to the other.
A quick test should prove that works.
If it does, then the problem is in the rest of your code, and is almost certainly the location is not visible, or the size means you can't see the label. Without your other code, we can't tell - so put the size bit back:
Private Sub SelectedLabel_MouseDoubleClick(sender As Object, e As MouseEventArgs)
SelectedLabel = DirectCast(sender, Label)
MainContainer.Controls.Remove(SelectedLabel)
SelectedLabel.Size = New Size(30, 30)
SelectedPanel.Controls.Add(SelectedLabel)
End Sub
And see what happens now. Keep doing this, and it should become obvious where the problem is.
Hi OriginalGriff,
Thanks for the quick reply. But it is not working as i imagine. I am admitting that i need to change the font size in order to shrink the label so that user can read the label text. Now, as per your suggestion, we are not telling this program to put the label in a specific location. So some of the labels are displaying inside the panel. But some are not. And the strange thing is, the labels are appearing in the panel like the same way as they appear in the MainContainer. The same width from each other, and the same order.
That's the whole point. Because you are only moving the labels, the location and size are not changed - but it proves that the rest of the code works. So as I suggested, try adding back part of the code - change the size perhaps - and see what happens. That way, you are narrowing in on what part of your original code is causing the problem. You can then fix that, and try the rest of the code afterwards.
Hi,
Since i am a self learner, I never used BreakPoint yet. Because, i didn't see any tutorial on how to use it. Instead, i use a Debug.WriteLine command to see what happens there. In this context, i am going to do the same in the ControlAdded event of the panel. If i am doing something wrong, or is there any chance to improve my method of debugging, please correct me.
That's one reason why being a "self learner" is a very bad idea - you never know what you are missing, because you don't even know it exists! Get a book - or better go on a course - and follow it through. It should introduce everything in a well structured manner so you don't miss important stuff.
The debugger is like using Debug.WriteLine - only better, and without you having to add any statements. Start with your method on display in Visual Studio, and put the cursor on the first line. Go to the menu, and select "Debug...Toggle Breakpoint" - a red dot will appear at the left hand side of the line - that's the "breakpoint indicator" and if you click it, it will go away. Click again, and it will come back. Now you know where the dot goes, that's the quickest way to toggle a breakpoint: click that column and that line will get a breakpoint.
Now run you code in the debugger - normally, that's just a case of pressing F5, but the menu will tell you: "Debug...Start Debugging" will do it, and tell you which key is assigned to it.
When your application reaches a breakpoint it will stop, and hand control to you. You can examine to contents of variables by hovering the mouse over them, or use the "Auto", "Locals", and "Watch" panels of the Output area on the VS screen. And you can single step you code - which means you can execute it line by line to see exactly what happens and why it does what it did. Not only that, but you can change code while your app is running to see if that fixes a problem!
It's powerful, very powerful - but that is the basics and it should be enough for a very long time (I hardly use the more advanced features at all!)
Give it a try - you will soon wonder what the heck you did without it! :laugh: