@Robert Vanleeuwen OK. So, I assume I'm not closing the container. But can someone explain why that matters here?
You're using MouseDown, so since the control still exists underneath it's MouseDown event is still firing. You need to close the containers when they're not in view, you're wasting the memory for each container opened and then not closed.
@Robert Vanleeuwen So, I've been learning about how to dynamically draw and embed things into a canvas. It's allowed me to really make things flexible and less cluttered.
Nope. Stop right there. You need to embed the container into the
Window, not a
@Robert Vanleeuwen how do I programatically close the previous container when its not a global variable?
Maintain a reference to the
ContainerControl you're instancing and embedding. When the user navigates away from the detail view, close the container.
@Robert Vanleeuwen I'm guessing that it does overwrite it, but the canvas had it embedded before
@Robert Vanleeuwen so that means It's still embedded even though a new instance of the same name is embedded.
Not so close. The instance that's embedded stays in scope, embedded into the window. The variable you'd used to do so is your last accessible reference to it. You should store that reference before replacing it. If you destroy the reference but not the embedded container you have to reacquire a reference to the container which isn't as easy as just keeping the reference in the first place.
@Robert Vanleeuwen ALL my containers are embedded by the name "cc"
You need better variable names if you want to understand the code in six months.
@Robert Vanleeuwen Yet that makes no sense to me. If I dim something as new with the same name and embed it - why wouldn't it just overwrite whatever was there to begin with?
When you embed the control into a window, you're adding the control to a window. What you're doing is not removing that control from the window. You're just missing a step.
@Robert Vanleeuwen OK so maybe I don't need to "close" the cc... since it overwrites in program.
Yes. You do. It does not get "overwritten" since you're embedding it.
@Robert Vanleeuwen Its the canvas I have to worry about right?
You need to remove the canvas, and embed properly into the window.
@Robert Vanleeuwen how do I refresh the canvas as a clean slate?
Canvas.Invalidate will cause another
Paint event, but it's likely not what you actually want.