On Feb 28, 2008, at 9:44 PM, Samuel DeVore wrote:
> On Feb 28, 2008, at 4:41 PM, Stephen Dodd wrote:
>
>> Anyone have/know of a good cross-platform class to keep a window on
>> screen that works well across multiple monitors?
>
> Joe was tossing around some sample code for something like this about
> a year ago I think. Joe you remember it?
Well, it wasn't exactly this; it was for resizing the window to fit
whatever monitor it's on.
You need to first determine what monitor your window is on:
Protected Function ScreenNumber() As Integer
// Return the number of the screen (from 0 to ScreenCount-1)
// which this window is mostly on.
Dim bestScreen As Integer = -1
Dim bestArea As Integer
for i As Integer = 0 to ScreenCount-1
Dim w As Integer = _
Min( Screen(i).Left + Screen(i).Width, Left + Width ) _
- Max( Screen(i).Left, Left )
Dim h As Integer = _
Max( Screen(i).Top + Screen(i).Height, Top + Height ) _
- Max( Screen(i).Top, Top )
if w < 0 or h < 0 then continue for
Dim area As Integer = w * h
if area > bestArea then
bestScreen = i
bestArea = area
end if
next
if bestScreen < 0 then return 0 // if not on any screen, report
the main monitor
return bestScreen
End Function
Then, shrink the window to fit:
Protected Sub FitToScreen()
// Fit this window onto its screen, by shortening it as needed.
Dim scrn As Integer = ScreenNumber
Dim sBottom As Integer = Screen( scrn ).AvailableTop + Screen
( scrn ).AvailableHeight
Dim sRight As Integer = Screen( scrn ).AvailableLeft + Screen
( scrn ).AvailableWidth
if Top + Height > sBottom then
Height = Max( MinHeight, sBottom - Top )
end if
if Left + Width > sRight then
Width = Max( MinWidth, sRight - Left )
end if
End Sub
HTH,
- Joe
--
Joe Strout
Inspiring Applications, Inc.
http://www.InspiringApps.com
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|