|
-
Mar 11th, 2012, 12:51 PM
#1
[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
-
Mar 11th, 2012, 03:00 PM
#2
Re: Cascade forms, large ones in back
Sort them first by width, then by height -- for example like this:
vb Code:
Dim sort1 = m_OpenNotes.OrderBy(Function(frm) frm.Width)
Dim sort2 = sort1.OrderBy(Function(frm) frm.Height)
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
-
Mar 11th, 2012, 03:47 PM
#3
Re: Cascade forms, large ones in back
 Originally Posted by boops boops
Sort them first by width, then by height -- for example like this:
vb Code:
Dim sort1 = m_OpenNotes.OrderBy(Function(frm) frm.Width)
Dim sort2 = sort1.OrderBy(Function(frm) frm.Height)
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?
-
Mar 11th, 2012, 04:12 PM
#4
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
-
Apr 21st, 2012, 10:52 PM
#5
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:
Private Sub CascadeNotes()
Dim LocationOffset As Integer = 15I
If m_OpenNotes.Count > 0I Then
Dim NewList As New List(Of NoteForm)
Dim frm As NoteForm
For Counter As Integer = m_OpenNotes.Count - 1I To 0I Step -1I
frm = m_OpenNotes(Counter)
If frm.Visible AndAlso Not frm.NoteLocked Then
NewList.Add(frm)
m_OpenNotes.RemoveAt(Counter)
End If
Next Counter
If NewList.Count > 0I Then
Dim ordered = From note In NewList Order By note.Height Descending, note.Width Descending
For Counter As Integer = 0I To ordered.Count - 1I
frm = ordered(Counter)
frm.LoadingNote = True
If Counter = 0I Then
'Position the first note
frm.Location = New Point(LocationOffset, LocationOffset)
Else
'Position this note in relation to the previous one
frm.Location = New Point(ordered(Counter - 1I).Location.X + LocationOffset, ordered(Counter - 1I).Location.Y + LocationOffset)
End If
frm.BringToFront()
frm.LoadingNote = False
m_OpenNotes.Add(frm)
Next Counter
Call SaveNotes()
End If
End If
End Sub
I wish I knew who posted to give me a line of code very similar to:
vb Code:
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.
-
Apr 22nd, 2012, 03:09 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|