?
Solved

Re-Draw form

Posted on 2006-04-21
2
Medium Priority
?
183 Views
Last Modified: 2010-04-23
Hi Guys,

I have a form with a number of Pictureboxes, that can be moved around. What I'd like to have is a button that with "Re-draw" the form to bring it back to it's initial state, ie. all controls where they originally were.

I could just set the top and left properties of each control to what they originally were, but I was hoping there was an easier way?

Cheers,

Wayne
0
Comment
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 16513316
That's about how to do it....

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private startX, startY As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each ctl As Control In Me.Controls
            If TypeOf ctl Is PictureBox Then
                AddHandler ctl.MouseDown, AddressOf Me.pb_MouseDown
                AddHandler ctl.MouseMove, AddressOf Me.pb_MouseMove
                ctl.Tag = ctl.Location
            End If
        Next
    End Sub

    Private Sub pb_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        If e.Button = MouseButtons.Left Then
            startX = e.X
            startY = e.Y
        End If
    End Sub

    Private Sub pb_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        If e.Button = MouseButtons.Left Then
            Dim pb As PictureBox = CType(sender, PictureBox)
            pb.Left = pb.Left + (e.X - startX)
            pb.Top = pb.Top + (e.Y - startY)
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For Each ctl As Control In Me.Controls
            If TypeOf ctl Is PictureBox AndAlso Not IsNothing(ctl.Tag) Then
                ctl.Location = ctl.Tag
            End If
        Next
    End Sub

End Class
0
 
LVL 48

Author Comment

by:Wayne Taylor (webtubbs)
ID: 16513457
Yeah, thought as much.

Cheers Mike!
0

Featured Post

Industry Leaders: 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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month16 days, 4 hours left to enroll

850 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