Results 1 to 6 of 6

Thread: [RESOLVED] Shapes

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Posts
    19

    Resolved [RESOLVED] Shapes

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Shapes

    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.
    vb.net Code:
    1. For Each sc In Me.Controls.OfType(Of ShapeContainer)()
    2.     For Each rs In sc.Shapes.OfType(Of RectangleShape)()
    3.         MessageBox.Show(rs.Bounds.ToString(), rs.Name)
    4.     Next
    5. Next
    Note that you can view that hierarchy in the Document Outline window (Ctrl+Alt+T).
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Posts
    19

    Re: Shapes

    Thank you very much for so quick respond. Works as charm!

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Posts
    19

    Re: [RESOLVED] Shapes

    One more question. Is it possible to add tooltip for shape as for button?
    Code:
    ToolTip1.SetToolTip(Button1, "Some text")

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] Shapes

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Posts
    19

    Re: [RESOLVED] Shapes

    Thanks again, i will try that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width