Solved

Selection box around control

Posted on 2006-11-16
11
210 Views
Last Modified: 2010-04-23
Hello,

I am trying to build a designer where you can add controls, move them around, resize them, etc. I am trying to emulate the one that appears on a multiline textbox on a .NET form. Such as this:

http://www.petelavelle.com/SelectionBox.jpg

Is anything build in to handle this, or do I need to draw this myself?
0
Comment
Question by:PLavelle
  • 3
  • 2
  • 2
  • +2
11 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 17955800
Like the panel control?
Or am I not following you?
0
 

Author Comment

by:PLavelle
ID: 17955818
I am trying to do it at runtime, so I want that border to show up around the selected controls on my designer.
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17955823
im also not sure i follow your question. what i understand is that you are trying to create a user control that can move, resize, etc, right?
if so, i can provide this link:
http://www.codeproject.com/vb/net/RuntimeMovableControls.asp

teaches how to build a movable user control. you would need to add the resizing part but its a good start.
0
 

Author Comment

by:PLavelle
ID: 17955987
Thanks newyuppie, but I already have them moving. I need to resize them at runtime.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 10

Expert Comment

by:gangwisch
ID: 17956045
use a panel and panel1.borderstyle=fixedsingle onmousehover
0
 

Author Comment

by:PLavelle
ID: 17956072
That won't bring up those 8 little white boxes to resize the control though.
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17956348
0
 
LVL 10

Accepted Solution

by:
Kinger247 earned 500 total points
ID: 17956588
Heres a quick way, needs a bit of work on the resizing of the control but you get the idea  ...

Public Class Form1
    Private WithEvents Button As New Button
    Private WithEvents GrabHandles1 As New Panel
    Private WithEvents GrabHandles2 As New Panel
    Private WithEvents GrabHandles3 As New Panel
    Private WithEvents GrabHandles4 As New Panel
    Private MouseX As Single
    Private MouseY As Single
    Private Dragging As Boolean = False
    Private GrabHandle_Dragging As Boolean = False
    Private GRABHANDLEWIDTH As Integer = 6
    Private SelectedFloorObject As Control

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Button.Text = "Button1"
        Button.Parent = Me
        Button.Bounds = New Rectangle(60, 40, 75, 23)

        With GrabHandles1
            .Name = "TOPLEFT"
            .Size = New Size(GRABHANDLEWIDTH, GRABHANDLEWIDTH)
            .BackColor = Color.White
            .BorderStyle = BorderStyle.FixedSingle
            .Parent = Me
            .BringToFront()
        End With

        With GrabHandles2
            .Name = "TOPRIGHT"
            .Size = New Size(GRABHANDLEWIDTH, GRABHANDLEWIDTH)
            .BackColor = Color.White
            .BorderStyle = BorderStyle.FixedSingle
            .Parent = Me
            .BringToFront()
        End With

        With GrabHandles3
            .Name = "BOTTOMRIGHT"
            .Size = New Size(GRABHANDLEWIDTH, GRABHANDLEWIDTH)
            .BackColor = Color.White
            .BorderStyle = BorderStyle.FixedSingle
            .Parent = Me
            .BringToFront()
        End With

        With GrabHandles4
            .Name = "BOTTOMLEFT"
            .Size = New Size(GRABHANDLEWIDTH, GRABHANDLEWIDTH)
            .BackColor = Color.White
            .BorderStyle = BorderStyle.FixedSingle
            .Parent = Me
            .BringToFront()
        End With

        MoveGrabHandles()

        SelectedFloorObject = Button
        Invalidate()
    End Sub

    Private Sub xMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button.MouseDown
        MouseX = -e.X : MouseY = -e.Y
        Dragging = True
        SelectedFloorObject = sender
        Cursor = Cursors.SizeAll
    End Sub

    Private Sub xMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button.MouseMove
        If Dragging Then
            Me.Invalidate()
            Dim MPosition As New Point
            MPosition = Me.PointToClient(MousePosition)
            MPosition.Offset(MouseX, MouseY)
            sender.Location = MPosition
            MoveGrabHandles()
        End If
    End Sub

    Private Sub xMouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button.MouseUp
        Dragging = False
        Cursor = Cursors.Default
    End Sub

    Private Sub MoveGrabHandles()
        GrabHandles1.Location = New Point(Button.Left - (GRABHANDLEWIDTH / 2), Button.Top - (GRABHANDLEWIDTH / 2))
        GrabHandles2.Location = New Point(Button.Right - (GRABHANDLEWIDTH / 2), Button.Top - (GRABHANDLEWIDTH / 2))
        GrabHandles3.Location = New Point(Button.Right - (GRABHANDLEWIDTH / 2), Button.Bottom - (GRABHANDLEWIDTH / 2))
        GrabHandles4.Location = New Point(Button.Left - (GRABHANDLEWIDTH / 2), Button.Bottom - (GRABHANDLEWIDTH / 2))
    End Sub

    Private Sub GrabHandles_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles GrabHandles1.MouseDown, GrabHandles2.MouseDown, GrabHandles3.MouseDown, GrabHandles4.MouseDown
        MouseX = -e.X : MouseY = -e.Y

        If e.Button = Windows.Forms.MouseButtons.Left Then
            GrabHandle_Dragging = True
        End If
    End Sub

    Private Sub GrabHandles1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles GrabHandles1.MouseEnter, GrabHandles2.MouseEnter, GrabHandles3.MouseEnter, GrabHandles4.MouseEnter
        Select Case sender.name
            Case "TOPLEFT" : Cursor = Cursors.SizeNWSE
            Case "TOPRIGHT" : Cursor = Cursors.SizeNESW
            Case "BOTTOMRIGHT" : Cursor = Cursors.SizeNWSE
            Case "BOTTOMLEFT" : Cursor = Cursors.SizeNESW
        End Select
    End Sub

    Private Sub GrabHandles1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles GrabHandles1.MouseLeave, GrabHandles2.MouseLeave, GrabHandles3.MouseLeave, GrabHandles4.MouseLeave
        Cursor = Cursors.Default
    End Sub

    Private Sub GrabHandles_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles GrabHandles1.MouseMove, GrabHandles2.MouseMove, GrabHandles3.MouseMove, GrabHandles4.MouseMove
        Me.Refresh()

        If GrabHandle_Dragging Then

            Dim MPosition As New Point
            MPosition = Me.PointToClient(MousePosition)

            '//-- Put resizing code here.
            Select Case sender.name
                Case "TOPLEFT"
                Case "TOPRIGHT"
                Case "BOTTOMRIGHT"
                Case "BOTTOMLEFT"
            End Select

        End If
    End Sub

    Private Sub GrabHandle1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles GrabHandles1.MouseUp, GrabHandles2.MouseUp, GrabHandles3.MouseUp, GrabHandles4.MouseUp
        GrabHandle_Dragging = False
    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim gr As Graphics = e.Graphics

        If SelectedFloorObject IsNot Nothing Then
            Dim RECTMP As Rectangle = New Rectangle(SelectedFloorObject.Left - 1, SelectedFloorObject.Top - 1, _
                SelectedFloorObject.Width + 1, SelectedFloorObject.Height + 1)

            Dim pen As New Pen(Color.Black, 1)
            pen.DashStyle = Drawing2D.DashStyle.Dot
            gr.DrawRectangle(pen, RECTMP)
        End If
    End Sub
End Class
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 18015937
Hi PLavelle,

Have any of these solutions worked for you ?
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now