Hello all,
Is it possible to loop all rectangle shapes that are on form? I did something like that with textboxes.
Code:Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctlr Is TextBox
Some code here
End If
Next
Printable View
Hello all,
Is it possible to loop all rectangle shapes that are on form? I did something like that with textboxes.
Code:Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctlr Is TextBox
Some code here
End If
Next
Strictly speaking, those rectangles aren't actually controls. It's a little more complex than that. Each shape is actually a component. As far as I'm aware, there's only ever one control, i.e. a ShapeContainer, added to the form, no matter how many shapes you add.Note that you can view that hierarchy in the Document Outline window (Ctrl+Alt+T).vb.net Code:
For Each sc In Me.Controls.OfType(Of ShapeContainer)() For Each rs In sc.Shapes.OfType(Of RectangleShape)() MessageBox.Show(rs.Bounds.ToString(), rs.Name) Next Next
Thank you very much for so quick respond. Works as charm!
One more question. Is it possible to add tooltip for shape as for button?
Code:ToolTip1.SetToolTip(Button1, "Some text")
As I said, a shape is not a control. You can only display ToolTips on controls, so no.
That said, you could display a ToolTip manually on the ShapeContainer, which is a control. You could handle the MouseHover event of the ShapeContainer, determine if the cursor is over a shape and, if it is, call Show on a ToolTip and specify the ShapeContainer as the control and the appropriate offset for the shape.
Thanks again, i will try that.