Solved

Selection box around control

Posted on 2006-11-16
11
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

615 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