I have a question for all of my fellow Daniwebbers.

If I place a panel within another panel, can I "click" the panel later?

In other words, if I am able to click the panel, can I reference that panel in code for manipulation? Such as flipping or rotating the panel orientation.


Here is what I have so far, but it requires the user to type the "index".

If CInt(TextBox1.Text) <> 0 Or TextBox1.Text <> "" Then
                'Allows the user to rotate the image using the text box and rotate button
                ImagePanel.Controls(CInt(TextBox1.Text) - 1).BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipNone)
                ImagePanel.Controls(CInt(TextBox1.Text) - 1).Refresh()
End If

I should also add that the panels that are added into the parent panel are created on runtime.


Edited 4 Years Ago by Begginnerdev: n/a

Here's how you create your panel at run time

Dim newPanel As Panel

newPanel = New Panel()
' Set "child" panel's properties
' Set a unique name for each panel
newPanel.Name = "ChildPanel1"
' Set Click event handler
AddHandler newPanel.Click, AddressOf childPanelClick
' Add panel to main panel's controls

Main point is to give each control (panel) a unique name which is also the key to Controls collection of ImagePanel.

The Click event handler can be implemented in two ways

Public Sub childPanelClick(sender As Object, e As EventArgs)
    ' Rotate and refresh _this_ panel
    CType(sender, Panel).BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipNone)
    CType(sender, Panel).Refresh()

    ' If ImagePanel is global variable you can also access panel with its unique name
    ' ImagePanel.Controls(CType(sender, Panel).Name).BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipNone)
    ' ImagePanel.Controls(CType(sender, Panel).Name).Refresh()

End Sub

Since the sender object is a "child" panel you don't have to care about its name, just rotate it. That's the uncommented code (depends also what else you want to do with the panel).
The second way in the commented lines assumes that ImagePanel is a global variable and thus can be accessed from the event handler. Instead of using any indices, control collection's item is accessed with key which is the same as control's name.
I suggest putting ImagePanel.Controls(CType(sender, Panel).Name) inside Try...Catch block to trap possible references to null objects...


I will try this, thank you.

What I will be doing is viewing multiple images and cascading them as "pages" to create one multipage tiff.

This question has already been answered. Start a new discussion instead.