Results 1 to 32 of 32

Thread: move / resize runtime controls

  1. #1

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    move / resize runtime controls

    here's a dll that handles vb IDE style runtime move + resize for your controls


    edit: this is written in vb2010. for vb2005 + vb2008 versions see post #4
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by .paul.; Jan 28th, 2010 at 12:20 PM.

  2. #2
    Addicted Member
    Join Date
    Jun 2008
    Location
    Macedonia
    Posts
    188

    Re: move / resize runtime controls

    ???????????????
    MACEDONIA 4EVER

  3. #3

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: move / resize runtime controls

    are you using vb2010???

  4. #4

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Thumbs up Re: move / resize runtime controls

    ok. i converted it for vb2005 + vb2008
    Attached Files Attached Files

  5. #5
    Addicted Member
    Join Date
    Feb 2010
    Posts
    197

    Re: move / resize runtime controls

    Hi .paul., im having a problem, could you help, im using the visual studio 2008 version, i can import the class etc into a new blank project and it all works great, how ever everytime i try to import it into my current project i get this error:



    Steps i take to import it:
    1, Import the .jpg resource
    2, Reference the MoveResizeControl
    3, Add controlHandler.vb tot he solution
    4, add in the code from form1.


    Thanks.

  6. #6

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: move / resize runtime controls

    try comparing the references + imports in the project where it works + the project where it doesn't

  7. #7
    Addicted Member
    Join Date
    Feb 2010
    Posts
    197

    Re: move / resize runtime controls

    Hey, ok seems in a pre made project all the references were not been auto imported, so ive done them and it now builds with no error, but it messes the BG up, take a look (BG is normally black)


  8. #8

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: move / resize runtime controls

    are you using a backgroundimage?
    if yes, try using the backcolor instead

  9. #9
    Addicted Member
    Join Date
    Feb 2010
    Posts
    197

    Re: move / resize runtime controls

    Hey, no im only using BG color, no image, on the form i have a combo box which changes bg color themes and out of the 6 other color themes, but there not triggered, so they shouldn't be affecting this, right? (O_o).

    When it loads with the red X its partially functional, the 2 picture boxes can be clicked dona nd moved/resized, the movement when moving them tho feels very sluggish and choppy compared tot he demo project or when there added to a new project.

  10. #10

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: move / resize runtime controls

    can you post the code from that form?

  11. #11
    Addicted Member
    Join Date
    Feb 2010
    Posts
    197

    Re: move / resize runtime controls

    Theres bucket loads of code on the page, theres 2 main parts which may be conflictign with your code so ill paste those, this one,

    Users can select a BG color/theme:
    Code:
        Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
            If (ComboBox2.SelectedItem = "Custom") Then
                OpenFileDialog2.ShowDialog()
    
                Dim sBackgroundImage As String
                sBackgroundImage = OpenFileDialog2.FileName
                Me.BackgroundImage = New System.Drawing.Bitmap(sBackgroundImage)
                Me.BackgroundImageLayout = ImageLayout.Stretch
                'OR:
                Me.BackgroundImage = New System.Drawing.Bitmap(OpenFileDialog2.FileName)
                Me.BackgroundImageLayout = ImageLayout.Stretch
    
            ElseIf (ComboBox2.SelectedItem = "Midnight v2") Then
                Me.BackColor = Color.Black
                Me.BackgroundImage = Nothing
                ''folders
                ListBox1.BackColor = Color.Black
                ListBox1.ForeColor = Color.Gray
                ListBox1.BorderStyle = BorderStyle.None
    
                ''files
                ListBox2.BackColor = Color.Black
                ListBox2.ForeColor = Color.Gray
                ListBox2.BorderStyle = BorderStyle.None
    
                ''serial:
                serial.BackColor = Color.Black
                serial.ForeColor = Color.Gray
                serial.BorderStyle = BorderStyle.None
    
                ''name:
                namefull.BackColor = Color.Black
                namefull.ForeColor = Color.Gray
                namefull.BorderStyle = BorderStyle.None
    
                ''version:
                version.BackColor = Color.Black
                version.ForeColor = Color.Gray
                version.BorderStyle = BorderStyle.None
    
                ''genre:
                genre.BackColor = Color.Black
                genre.ForeColor = Color.Gray
                genre.BorderStyle = BorderStyle.None
    
                ''Date:
                date1.BackColor = Color.Black
                date1.ForeColor = Color.Gray
                date1.BorderStyle = BorderStyle.None
    
            ElseIf (ComboBox2.SelectedItem = "Midnight") Then
                Me.BackgroundImage = New System.Drawing.Bitmap(Application.StartupPath() & "\BG\" & "themmoon.jpg")
    
                ''folders
                ListBox1.BackColor = Color.Black
                ListBox1.ForeColor = Color.Gray
                ListBox1.BorderStyle = BorderStyle.Fixed3D
    
                ''files
                ListBox2.BackColor = Color.Black
                ListBox2.ForeColor = Color.Gray
                ListBox2.BorderStyle = BorderStyle.Fixed3D
    
                ''serial:
                serial.BackColor = Color.Black
                serial.ForeColor = Color.Gray
                serial.BorderStyle = BorderStyle.Fixed3D
    
                ''name:
                namefull.BackColor = Color.Black
                namefull.ForeColor = Color.Gray
                namefull.BorderStyle = BorderStyle.Fixed3D
    
                ''version:
                version.BackColor = Color.Black
                version.ForeColor = Color.Gray
                version.BorderStyle = BorderStyle.Fixed3D
    
                ''genre:
                genre.BackColor = Color.Black
                genre.ForeColor = Color.Gray
                genre.BorderStyle = BorderStyle.Fixed3D
    
                ''Date:
                date1.BackColor = Color.Black
                date1.ForeColor = Color.Gray
                date1.BorderStyle = BorderStyle.Fixed3D
    end if
    That part, on page load the form is set to just be on default settings which is the BG color of the page set to black, i had thought this code would conflict, but as none of the themes are selected just the default one i thought it'd be ok.

    Theres also a similar combobox used to change between some preset layouts, heres that code:
    Code:
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
            If (ComboBox1.SelectedItem = "Standard") Then
                ''folders
                ListBox1.Location = New Point(8, 72)
                ListBox1.Size = New Size(419, 394)
    
                ''files
                ListBox2.Location = New Point(8, 484)
                ListBox2.Size = New Size(419, 225)
    
                ''serial:
                serial.Location = New Point(451, 501)
    
                ''name:
                namefull.Location = New Point(451, 469)
                namefull.Size = New Size(534, 26)
    
                ''region:
                flagu.Location = New Point(451, 533)
                flagj.Location = New Point(451, 533)
                flage.Location = New Point(451, 533)
    
                ''version:
                version.Location = New Point(940, 501)
    
                ''genre:
                genre.Location = New Point(637, 501)
    
                ''Date:
                date1.Location = New Point(808, 501)
    
                ''front:
                pboxGameCover.Size = New Size(261, 370)
                pboxGameCover.Location = New Point(455, 82)
    
                ''back:
                pboxGameCoverA.Show()
                pboxGameCoverA.Size = New Size(261, 370)
                pboxGameCoverA.Location = New Point(722, 82)
    
    
            ElseIf (ComboBox1.SelectedItem = "Large Front") Then
                ''folders
                ListBox1.Location = New Point(8, 72)
                ListBox1.Size = New Size(419, 290)
    
                ''files
                ListBox2.Location = New Point(8, 368)
                ListBox2.Size = New Size(419, 147)
    
                ''serial:
                serial.Location = New Point(8, 553)
    
                ''name:
                namefull.Location = New Point(8, 521)
                namefull.Size = New Size(419, 26)
    
                ''region:
                flagu.Location = New Point(315, 585)
                flagj.Location = New Point(315, 585)
                flage.Location = New Point(315, 585)
    
                ''version:
                version.Location = New Point(365, 553)
    
                ''genre:
                genre.Location = New Point(194, 553)
    
                ''Date:
                date1.Location = New Point(8, 585)
    
                ''front:
                pboxGameCover.Size = New Size(452, 627)
                pboxGameCover.Location = New Point(482, 82)
    
                ''back:
                pboxGameCoverA.Hide()
    
            ElseIf (ComboBox1.SelectedItem = "Minimal") Then
                ''folders
                ListBox1.Location = New Point(8, 72)
                ListBox1.Size = New Size(284, 394)
    
                ''files
                ListBox2.Location = New Point(8, 484)
                ListBox2.Size = New Size(284, 134)
    
                ''serial:
                serial.Location = New Point(451, 114)
    
                ''name:
                namefull.Location = New Point(451, 82)
                namefull.Size = New Size(534, 26)
    
                ''region:
                flagu.Location = New Point(350, 82)
                flagj.Location = New Point(350, 82)
                flage.Location = New Point(350, 82)
    
                ''version:
                version.Location = New Point(940, 114)
    
                ''genre:
                genre.Location = New Point(637, 114)
    
                ''Date:
                date1.Location = New Point(808, 114)
    
                ''front:
                pboxGameCover.Size = New Size(261, 370)
                pboxGameCover.Location = New Point(300, 157)
    
                ''back:
                pboxGameCoverA.Hide()
    
            End If
    There the only bits of code which affect the forms look or layout in my project.

  12. #12

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: move / resize runtime controls

    try commenting out ComboBox2_SelectedIndexChanged. i suspect it's the backgoundimages

  13. #13
    Addicted Member
    Join Date
    Feb 2010
    Posts
    197

    Re: move / resize runtime controls

    OK i removed the all code to do with themes, tested, same issue, so then i removed all code to do with layouts, tested again same issue.

    One thing i have noticed tho, whilst testing and the red X is there etc, the pictureboxs as i said are very sluggish feeling when moving them and as there moved the re X int he BG flickers, how ever if i try to move a listbox it moves perfectly, nice smooth and fast and no flicker, so the issue seems to be around the picture boxes, my pic boxes have no code related to them currently tho,.

  14. #14

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: move / resize runtime controls

    the red x is there because an error occurred drawing the background in the paint event

  15. #15
    Addicted Member
    Join Date
    Feb 2010
    Posts
    197

    Re: move / resize runtime controls

    Just done a test to check other code, i removed all code from my project except the code for this, and the error is still there, so then i one by one deleted all controls on the form so the form is now blank except 1 pic box and a list box for testing, no code except whats there for this, and the error is still present.

  16. #16

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: move / resize runtime controls

    are you using 3.5 framework in your project?

  17. #17
    Addicted Member
    Join Date
    Feb 2010
    Posts
    197

    Re: move / resize runtime controls

    yeah, it wasn't at first tho, but i set it to use 3.5 inthe advanced compile options, before importing any of this controls code.

  18. #18

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: move / resize runtime controls

    i can't see where the problem is. try adding your components + code bit by bit to a project where move / resize is working + checking it's still working at each stage.
    if you can isolate the problem that way, hopefully i can help more then...

  19. #19
    Addicted Member
    Join Date
    Feb 2010
    Posts
    197

    Re: move / resize runtime controls

    Hey, sorry for the late reply, my current project is a little to far gone to rebuild but i have another part of the same project to build which ill try this in along with the same components i used in my current project and report back if one of them is causing the issue.

  20. #20
    Fanatic Member
    Join Date
    Apr 2008
    Posts
    778

    Re: move / resize runtime controls

    Hello paul

    I am trying to use your move resize label in my project at run time but I got one small problem.
    After I call add a label using this code:
    Code:
    Dim label() As MoveResizeLabel
        Dim nlabel As Integer
        Private Sub LabelToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LabelToolStripMenuItem.Click
            ReDim Preserve label(nlabel)
            label(nlabel) = New MoveResizeLabel
            Me.Controls.Add(label(nlabel))
            label(nlabel).Location = New Point(100, 100)
            label(nlabel).Text = "Label"
        End Sub
    The label doesn't function as good as the ones you have on your project already sitting on the form. I am able to move it but not resize it, I think it draws the square but it fails at drawing the dots. I am not very familiar with drawings in coding but if you know what should I change in code of the moveresizelabel.vb I would appreciate.

    Thank you

  21. #21

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: move / resize runtime controls

    that's not my code you're using.
    i think that's NickThissen's MoveResizeLabel you're referring to

  22. #22
    Fanatic Member
    Join Date
    Apr 2008
    Posts
    778

    Re: move / resize runtime controls

    Quote Originally Posted by .paul. View Post
    ok. i converted it for vb2005 + vb2008
    I am using the code you have posted here, the 2008 version. I am using your move resize label for my application.

    This little bit is my code (I am putting one of those labels on my form at run time)

    Code:
    Dim label() As MoveResizeLabel
        Dim nlabel As Integer
        Private Sub LabelToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LabelToolStripMenuItem.Click
            ReDim Preserve label(nlabel)
            label(nlabel) = New MoveResizeLabel
            Me.Controls.Add(label(nlabel))
            label(nlabel).Location = New Point(100, 100)
            label(nlabel).Text = "Label"
        End Sub
    I think the problem might be somewhere in these subs:

    Code:
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            'MsgBox = 513
            MyBase.WndProc(m)
            Dim g As Graphics = Me.CreateGraphics
            'on paint with customcolor borderstyle
    
            If m.Msg = 15 And Me.BorderStyle = CustomBorderStyles.None Then
                g.DrawRectangle(New Pen(bdrColor, 1), New Rectangle(0, 0, Me.Width - 1, Me.Height - 1))
            End If
    
            'on paint if selected
            If m.Msg = 15 And Me.Selected = True Then
                DrawDashedRectangle()
                DrawSquareResizeHandles()
            End If
    
            g.Dispose()
        End Sub
    
    Private Sub DrawSquareResizeHandles()
            Dim g As Graphics = Me.CreateGraphics
    
            g.FillRectangle(Brushes.Black, rTopLeft)
            g.FillRectangle(Brushes.Black, rTopRight)
            g.FillRectangle(Brushes.Black, rBotRight)
            g.FillRectangle(Brushes.Black, rBotLeft)
    
            g.FillRectangle(Brushes.Black, rTopMid)
            g.FillRectangle(Brushes.Black, rBotMid)
    
            g.FillRectangle(Brushes.Black, rMidLeft)
            g.FillRectangle(Brushes.Black, rMidRight)
    
        End Sub
    
    Private Sub DrawDashedRectangle()
            Dim g As Graphics = Me.CreateGraphics
            Dim points() As Point = GetPointsForSelectedLines()
            Dim count As Integer
    
            g.DrawRectangle(Pens.White, New Rectangle(0, 0, Me.Width - 1, Me.Height - 1))
            For count = 0 To points.Length - 1 Step 2
                If count + 1 = points.Length Then
                    Exit Sub
                End If
                g.DrawLine(Pens.Black, points(count), points(count + 1))
    
            Next
    
        End Sub
    Last edited by MrtforCode; Jun 8th, 2010 at 10:51 AM.

  23. #23
    Fanatic Member
    Join Date
    Apr 2008
    Posts
    778

    Re: move / resize runtime controls

    oh I am sorry, the bit with the move resize label was not your code. But I still want to ask you a question about the code you have done.

    You actually made mostly any control (textbox, groupbox, richtextbox, listbox...) movable and sizable except the label, or could it easily move resize a label as well? Where do I need to improve to get it working on a label as well?
    Last edited by MrtforCode; Jun 8th, 2010 at 10:59 AM.

  24. #24

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: move / resize runtime controls

    there seems to be a problem using my code with the label control + i'm not 100% sure but i think the API functions don't work with the label control

  25. #25
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: move / resize runtime controls

    I saw the strange label behavior as well, it does not seem to work. If all you need is a simple line of text (no auto-ellipsis, auto-size, stuff like that) then you can use a PictureBox instead and draw the text manually using Graphics.DrawString.

  26. #26
    Fanatic Member
    Join Date
    Apr 2008
    Posts
    778

    Re: move / resize runtime controls

    Well, I will try to adjust the code to work for me but first I will need to study it out.

    One question .paul., what makes the mouse cursor turn into 'move' cursor on mouseover the 'move' tag, can you show me the sub that does that? I could not find it, I want to apply something like this to NickThissen's label

  27. #27

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: move / resize runtime controls

    Quote Originally Posted by MrtforCode View Post
    what makes the mouse cursor turn into 'move' cursor on mouseover the 'move' tag?
    the move box + the resize boxes are pictureboxes. i set their cursor property when they are added, so whenever the mouse is over them the cursor automatically changes

  28. #28
    Hyperactive Member
    Join Date
    Mar 2009
    Posts
    462

    Re: move / resize runtime controls

    Wow this is truly amazing! Good job on this , I will be using this in the future thanks so much. Your the best

  29. #29
    Hyperactive Member
    Join Date
    May 2007
    Posts
    300

    Re: move / resize runtime controls

    Great job on this, thanks Paul!

    A couple of questions...

    I would like to add an "edit" mode and "normal" mode so that the resize/move handles only show when in edit mode. How would you suggest going about that?

    I would like to be able to save the controls' new sizes and layout. Does vb have an easy "save all" method to save all the page's control location and sizes?

  30. #30

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: move / resize runtime controls

    1/ add a property, canSelect:

    vb Code:
    1. Private _canSelect As Boolean = True
    2. Public Property canSelect As Boolean
    3.     Get
    4.         Return _canSelect
    5.     End Get
    6.     Set(ByVal value As Boolean)
    7.         _canSelect = value
    8.     End Set
    9. End Property

    then, in mControl_mousedown:

    vb Code:
    1. Private Sub mControl_mousedown(ByVal sender As Object, ByVal e As System.EventArgs)
    2.      If Not canSelect Then Return

    to toggle selectability, change the property.

    2/ yes. (ApplicationSettings)
    here's an example. it saves (+ loads) the text property, but you'll use the location + size properties:

    http://www.vbforums.com/showpost.php...48&postcount=2

    unfortunately that doesn't work for dynamically added controls. you'll need to work something out using my.settings if your controls were added at runtime...

  31. #31
    Hyperactive Member
    Join Date
    May 2007
    Posts
    300

    Re: move / resize runtime controls

    Thanks very much!

  32. #32
    New Member
    Join Date
    Jun 2012
    Posts
    1

    Re: move / resize runtime controls

    Hi Paul,

    This class is very impressive and so simple to use, just a FYI to anybody having trouble getting this to work with labels (I know I did!) just set the AutoSizeMode to None and it works fine. The API won't work with controls that have any kind of autosizing and this includes anchor.

    I have a database program that allows the user to design their own data entry screens, with an IDE very simular to VS but after a while I ran into problems with labels not moving & anchor properties on any control.

    If you need to use anchors (i.e Top, Left works fine, but Top, Left, Right will not) just store the control anchors in a variable when it is selected (i.e in mControl_mousedown), then set the control anchor to Top,Left and then restore the original anchor properties in move_mousemove within the If GetCapture=0 statement.

    Many Thanks paul

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