Results 1 to 6 of 6

Thread: [RESOLVED] Cascade forms, large ones in back

  1. #1

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Resolved [RESOLVED] Cascade forms, large ones in back

    I've got a collection of a type of form and multiple of these can be displayed on the screen independently at the same time and now I'm wanting to add the ability to cascade these forms, but these forms can all be re-sized so it'll be very rare when they are of the same or similar size. I would like to be able to cascade them based on their present size, so the largest for is in the back and the smallest is in front. I also realize that a form could be wider than than another form but that other form is taller than the current one, in which case I would like the taller form to be considered the larger one (an arbitrary decision, I know). Here's the code I currently have that cascades them in the order they are in the collection, I just need to know how to re-order them based on their size.
    Code:
    Private m_OpenNotes As New List (Of NoteForm)
    
    Private Sub CascadeNotes()
        If m_OpenNotes.Count > 0I Then
            Dim LocationOffset As Integer = 15I
            For Counter As Integer = 0I To m_OpenNotes.Count - 1I
                With m_OpenNotes(Counter)
                    If Counter = 0I Then
                        'Position the first note
                        .Location = New Point(LocationOffset, LocationOffset)
                    Else
                        'Position this note in relation to the previous one
                        .Location = New Point( _
                            m_OpenNotes(Counter - 1I).Location.X + LocationOffset, _
                            m_OpenNotes(Counter - 1I).Location.Y + LocationOffset)
                    End If
                End With
            Next Counter
        End If
    End Sub
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Cascade forms, large ones in back

    Sort them first by width, then by height -- for example like this:

    vb Code:
    1. Dim sort1 = m_OpenNotes.OrderBy(Function(frm) frm.Width)
    2.     Dim sort2 = sort1.OrderBy(Function(frm) frm.Height)
    3.     m_OpenNotes = New List(Of Form)(sort2.Reverse)
    That way, forms will be sorted by height, with forms of equal height sorted by width, in descending order.

    BB

  3. #3

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Cascade forms, large ones in back

    Quote Originally Posted by boops boops View Post
    Sort them first by width, then by height -- for example like this:

    vb Code:
    1. Dim sort1 = m_OpenNotes.OrderBy(Function(frm) frm.Width)
    2.     Dim sort2 = sort1.OrderBy(Function(frm) frm.Height)
    3.     m_OpenNotes = New List(Of Form)(sort2.Reverse)
    That way, forms will be sorted by height, with forms of equal height sorted by width, in descending order.

    BB
    Error 1 'OrderBy' is not a member of 'System.Collections.Generic.List()'.

    I am targeting the 4.0 FW too, what assembly(ies) do I need to have imported?
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Cascade forms, large ones in back

    I think it's in System.Core.dll. Isn't that referenced by default? You could instead try adding Imports System.Linq, since that seems to work when I dereference Core.

    BB

  5. #5

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Cascade forms, large ones in back

    I don't see the post in here that I ended up using to get it to work, but here's my full code for it:
    vb Code:
    1. Private Sub CascadeNotes()
    2.         Dim LocationOffset As Integer = 15I
    3.         If m_OpenNotes.Count > 0I Then
    4.             Dim NewList As New List(Of NoteForm)
    5.             Dim frm As NoteForm
    6.             For Counter As Integer = m_OpenNotes.Count - 1I To 0I Step -1I
    7.                 frm = m_OpenNotes(Counter)
    8.                 If frm.Visible AndAlso Not frm.NoteLocked Then
    9.                     NewList.Add(frm)
    10.                     m_OpenNotes.RemoveAt(Counter)
    11.                 End If
    12.             Next Counter
    13.             If NewList.Count > 0I Then
    14.                 Dim ordered = From note In NewList Order By note.Height Descending, note.Width Descending
    15.                 For Counter As Integer = 0I To ordered.Count - 1I
    16.                     frm = ordered(Counter)
    17.                     frm.LoadingNote = True
    18.                     If Counter = 0I Then
    19.                         'Position the first note
    20.                         frm.Location = New Point(LocationOffset, LocationOffset)
    21.                     Else
    22.                         'Position this note in relation to the previous one
    23.                         frm.Location = New Point(ordered(Counter - 1I).Location.X + LocationOffset, ordered(Counter - 1I).Location.Y + LocationOffset)
    24.                     End If
    25.                     frm.BringToFront()
    26.                     frm.LoadingNote = False
    27.                     m_OpenNotes.Add(frm)
    28.                 Next Counter
    29.                 Call SaveNotes()
    30.             End If
    31.         End If
    32.     End Sub
    I wish I knew who posted to give me a line of code very similar to:
    vb Code:
    1. Dim ordered = From note In NewList Order By note.Height Descending, note.Width Descending
    So I could give them credit.

    Boops, I toyed with your idea too, but I need to get into using Linq more often and I'm sure there's a way I can use it more with that sub too, I just don't know how.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  6. #6
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: [RESOLVED] Cascade forms, large ones in back

    Neat. Your new line of Linq code is far more compact. I too rarely use Linq and I didn't know you could use two OrderBy clauses like that. I wouldn't be surprised if one or both the For loops could be condensed in a similar way. Any Linq Lions out there?

    BB

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