Solved

Selection box around control

Posted on 2006-11-16
11
216 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:PLavelle
ID: 17955987
Thanks newyuppie, but I already have them moving. I need to resize them at runtime.
0
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

713 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