Gambas India Forum

Forum breadcrumbs - You are here:ForumRepository: Source CodesDrawing Area object

Drawing Area object

Do you like this program?
yes
no
Quote

Notes on the code shown below:
The idea is take a screenshot of the available desktop (i.e. the whole of my monitor's screen excluding the top panel (containing the Systray etc, whcih is used by the FSelectArea form's title and the Launch side panel) and copy it into the DrawingAreaDesktop control. This would then allow the user to select an area on the available desktop before the form is hidden and control is returned back to the Fmain form.
The FSelectArea form contains the DesktopAreaDesktop (Drawing Area object) control

Private hPicture As Picture
Public Sub Form_Open()
Print "SB"
Inc Application.Busy
hPicture = Desktop.Screenshot(Screen.AvailableX, Screen.AvailableY, Screen.AvailableWidth, Screen.AvailableHeight)
Print "SB1"
Print "Screen X=" & Screen.X & ", Screen Y = " & Screen.Y
Print "Screen AvailableX = " & Screen.AvailableX & ", AvailableY = " & Screen.AvailableY
Print "Screen Width = " & Screen.Width & ", Screen Height = " & Screen.Height
Print "Screen AvailableWidth = " & Screen.AvailableWidth & ", Screen AvailableHeight = " & Screen.AvailableHeight
Print "hPicture Width = " & hPicture.Width & ", hPicture Height = " & hPicture.Height
Last.X = Screen.AvailableX
Last.Y = Screen.AvailableY
Last.Resize(Screen.AvailableWidth, Screen.AvailableHeight)
Print "FSelectArea X = " & FSelectArea.X & ", FSelectArea Y = " & FSelectArea.Y
Print "FSelectArea Left = " & FSelectArea.Left & ", FSelectArea Top = " & FSelectArea.Top
Print "FSelectArea Width = " & FSelectArea.Width & ", FSelectArea Height = " & FSelectArea.Height
DrawingAreaDesktop.Left = Screen.AvailableX
DrawingAreaDesktop.Top = Screen.AvailableY
DrawingAreaDesktop.Width = Screen.AvailableWidth
DrawingAreaDesktop.Height = Screen.AvailableHeight
Print "DrawingAreaDesktop X = " & DrawingAreaDesktop.X & ", DrawingAreaDesktop Y = " & DrawingAreaDesktop.Y
Print "DrawingAreaDesktop Left = " & DrawingAreaDesktop.Left & ", DrawingAreaDesktop Top = " & DrawingAreaDesktop.Top
Print "DrawingAreaDesktop Width = " & DrawingAreaDesktop.Width & ", DrawingAreaDesktop Height = " & DrawingAreaDesktop.Height
Print "SB2"
Paint.Begin(DrawingAreaDesktop)
Print "SB3"
Paint.DrawPicture(hPicture, DrawingAreaDesktop.Left, DrawingAreaDesktop.Top, DrawingAreaDesktop.Width, DrawingAreaDesktop.Height)
Print "SB4"
Paint.End

When I run the app (using Debug) I get a popup stating 'Cannot Paint outside of Draw event handler'. I'm baffled as the Console output (shown below) shows that the variable hPicture (used to paint the DrawingAreaDesktop control) & that control & the FSelectArea form all have the same size. This size is actually my monitor's screen size (1920 x 1080) excluding the top panel (containing Systray and the FSelectArea's title) & the side Launcher panel: this is the Available Desktop size, namely width = 1920-67 = 1853 & height = 1080-1053 = 27/ The FSelectArea form & the DrawingAreaDesktop control both have no border specified in their properties. Any ideas concerning the popup message's cause and how to stop it?

Console output:

SB
SB1
Screen X=0, Screen Y = 0
Screen AvailableX = 67, AvailableY = 27
Screen Width = 1920, Screen Height = 1080
Screen AvailableWidth = 1853, Screen AvailableHeight = 1053
hPicture Width = 1853, hPicture Height = 1053
FSelectArea X = 67, FSelectArea Y = 27
FSelectArea Left = 67, FSelectArea Top = 27
FSelectArea Width = 1853, FSelectArea Height = 1053
DrawingAreaDesktop X = 67, DrawingAreaDesktop Y = 27
DrawingAreaDesktop Left = 67, DrawingAreaDesktop Top = 27
DrawingAreaDesktop Width = 1853, DrawingAreaDesktop Height = 1053
SB2

NB It doesn't show SB3 which is coded before the Paint.Draw command.

I've also attached the app's source just in case.

Click to Download: SelectArea.tar.gz