hi all,
I am developing the map tool application in vb.net where user can create maps. I gave the check boxes for show/hide the layers of map like village boundary(polygon), plot boundary(Polygon), roads(Lines), bore wells(points), dug wells(points), schools(points).
I am using the function RedrawMap for displaying various layers of maps as user checked the check boxes. If user click village boundary map shows the village boundary etc on panel control named "picMap".
The problem i am facing is when user check the village boundary layer map shows the boundary but when user check the next polygon layer i.e. plot boundary layer it gives the error message
"5:Object is currently in use elsewhere.".
Can anybody tell me what the error is and why it is happening?
My code is as follows:
Public Sub RedrawMap(ByVal index As Integer)
Dim f As Font
'Object Style
Dim Size1 As Short
Dim Size2 As Short
Dim Colour1 As Integer
Dim Colour2 As Integer
Dim i As Short
Dim j As Integer
Dim k As Short
Dim X As Integer
Dim Y As Integer
Dim FName As String
Dim FValue As String
Dim wIndex As Short
Dim NrPts As Short
Dim lRes As Integer
Dim hRgn As Integer
Dim lpRect As Rect
Dim lWidth As Integer
Dim lHeight As Integer
If zf = 0 Then Exit Sub
'If frmMain.txtScale = "1/1" Or frmMain.txtScale = "1/1000000000" Then Exit Sub
lWidth = CInt(lPicWidth) / zf
lHeight = CInt(lPicHeight) / zf
ShiftPt.X = lX
ShiftPt.Y = lY
'Display the objects of the visible layers only
Dim Cnt As Short
Dim gr As Graphics
Dim rc, gc As Short
Dim bc As Short
If zf = 0 Then Exit Sub
lWidth = CInt(lPicWidth) / zf
lHeight = CInt(lPicHeight) / zf
ShiftPt.X = lX
ShiftPt.Y = lY
'Display the objects of the visible layers only
gr = picMap.CreateGraphics()
Dim hdc As Integer
For i = 1 To UBound(LayerData)
DeleteHandle((i))
If LayerData(i).lVisibile = 1 Then
Size1 = LayerData(i).layerApp.Size1
Size2 = LayerData(i).layerApp.Size2
Colour1 = LayerData(i).layerApp.Color1
Colour2 = LayerData(i).layerApp.Color2
Select Case LayerData(i).layerKind
Case LKIND_POINT
If pointFlag = False Then
pointFlag = True
'Set Symbol style,size and colour
f = New Font(getSymbolFamilyName(Size2), Size1, FontStyle.Regular)
picMap.Font = f
Size1 = picMap.Font.SizeInPoints
For j = 1 To UBound(LayerData(i).ObjList)
If LayerData(i).ObjList(j).lObjId <> 0 Then
If LayerData(i).ObjList(j).lVisible = 1 Then
'Vector to Raster
X = ShiftPt.X - (MapRect.Left_Renamed - LayerData(i).ObjList(j).Points(1).X) * 37.8 / (zf * MapScale)
Y = ShiftPt.Y - (LayerData(i).ObjList(j).Points(1).Y - MapRect.Top - mapHeight) * 37.8 / (zf * MapScale)
'Store Object Handle
hRgn = CreateRectRgn(X - Size1 / 2, Y - Size1 / 2, X + Size1 / 2, Y + Size1 / 2)
LayerData(i).ObjList(j).lObjHandle = hRgn
If LayerData(i).ObjList(j).lSelection = 1 Then 'For selected objects
picMap.ForeColor = System.Drawing.ColorTranslator.FromOle(MapData.lSelColour)
End If
f = New Font(getSymbolFamilyName(Size2), Size1, FontStyle.Regular)
Dim br As Brush = New SolidBrush(System.Drawing.ColorTranslator.FromOle(RGB(rc, gc, bc)))
gr.DrawString(Convert.ToString(Chr(Colour2)), f, br, X, Y)
br.Dispose()
End If
End If
Next j
Case LKIND_POLY
'Display Objects
For j = 1 To UBound(LayerData(i).ObjList)
If LayerData(i).ObjList(j).lObjId <> 0 Then
If LayerData(i).ObjList(j).lVisible = 1 Then
NrPts = UBound(LayerData(i).ObjList(j).Points)
ReDim Preserve list_temppoly(NrPts)
For k = 1 To NrPts
'Vector to Raster
X = ShiftPt.X - (MapRect.Left_Renamed - LayerData(i).ObjList(j).Points(k).X) * 37.8 / (zf * MapScale)
Y = ShiftPt.Y - (LayerData(i).ObjList(j).Points(k).Y - MapRect.Top - mapHeight) * 37.8 / (zf * MapScale)
list_temppoly(k).X = X
list_temppoly(k).Y = Y
Next k
If LayerData(i).ObjList(j).lSelection = 1 Then 'For selected objects
rc = Colour1 And &HFFS
gc = ((Colour1 And &HFF00S) / &H100S) Mod &H100S
bc = ((Colour1 And &HFF0000) / &H10000) Mod &H100S
picMap.ForeColor = System.Drawing.ColorTranslator.FromOle(RGB(rc, gc, bc)) 'MapData.lSelColour
End If
'Create polygon
'Store Object Handle
hRgn = CreatePolygonRgn(list_temppoly(1), NrPts, 1)
LayerData(i).ObjList(j).lObjHandle = hRgn
hdc = gr.GetHdc()
lRes = Polygon(hdc, list_temppoly(1), NrPts)
End If
End If
Next j
End Select
End If
Next i
End Sub