当前位置:编程学习 > VB >>

VB.net代码转换成C#代码,handles如何处理?

Private Sub Map1_SelectBoxFinal(ByVal sender As Object, ByVal e As AxMapWinGIS._DMapEvents_SelectBoxFinalEvent) Handles Map1.SelectBoxFinal

Dim sf As MapWinGIS.Shapefile

Dim myExtents As New MapWinGIS.Extents()

Dim selectedShapes() As Integer

Dim i As Integer, hndl As Integer

Dim pxMin As Double, pxMax As Double, pyMin As Double, pyMax As Double, pzMin As Double, pzMax As Double

Dim col As System.Drawing.Color

'Check if the map is in selection mode

If Map1.CursorMode = MapWinGIS.tkCursorMode.cmSelection Then


'Get the handle of the layer at position 0


hndl = Map1.get_LayerHandle(0)


'Get the shapefile in the specified layer


sf = Map1.get_GetObject(hndl)


'Convert the boundaries of the selection box from pixel units to projected map coordinates


Map1.PixelToProj(e.left, e.bottom, pxMin, pyMin)


Map1.PixelToProj(e.right, e.top, pxMax, pyMax)


'Set the extents object to be used to find shapes that have been selected in the shapefile


myExtents.SetBounds(pxMin, pyMin, 0, pxMax, pyMax, 0)


'Check if there are any shapes with in the shapefile that intersect with the selection box


If sf.SelectShapes(myExtents, 0, MapWinGIS.SelectMode.INTERSECTION, selectedShapes) Then



'Get the System.Drawing.Color which is being used as the fill color for the shapes in the layer



col = Map1.get_ShapeLayerFillColor(hndl)



'Set all shapes in the shapefile back to their original color



Map1.set_ShapeLayerFillColor(hndl, System.Convert.ToUInt32(RGB(col.R, col.G, col.B)))



'For each of the selected shapes in the shapefile, color them differently than their original fill color



For i = 0 To UBound(selectedShapes)




Map1.set_ShapeFillColor(hndl, selectedShapes(i), System.Convert.ToUInt32(RGB(100, 100, 0)))



Next


End If

End If

End Sub


我将这段代码转换为C#,Handles Map1.SelectBoxFinal这个在c#中应该怎么处理呢?
答案:1.转换:
private void Map1_SelectBoxFinal(object sender, AxMapWinGIS._DMapEvents_SelectBoxFinalEvent e)
{

MapWinGIS.Shapefile sf = default(MapWinGIS.Shapefile);

MapWinGIS.Extents myExtents = new MapWinGIS.Extents();

int[] selectedShapes = null;

int i = 0;

int hndl = 0;

double pxMin = 0;

double pxMax = 0;

double pyMin = 0;

double pyMax = 0;

double pzMin = 0;

double pzMax = 0;

System.Drawing.Color col = default(System.Drawing.Color);

//Check if the map is in selection mode

if (Map1.CursorMode == MapWinGIS.tkCursorMode.cmSelection) {

//Get the handle of the layer at position 0

hndl = Map1.get_LayerHandle(0);

//Get the shapefile in the specified layer

sf = Map1.get_GetObject(hndl);

//Convert the boundaries of the selection box from pixel units to projected map coordinates

Map1.PixelToProj(e.left, e.bottom, pxMin, pyMin);

Map1.PixelToProj(e.right, e.top, pxMax, pyMax);

//Set the extents object to be used to find shapes that have been selected in the shapefile

myExtents.SetBounds(pxMin, pyMin, 0, pxMax, pyMax, 0);

//Check if there are any shapes with in the shapefile that intersect with the selection box

if (sf.SelectShapes(myExtents, 0, MapWinGIS.SelectMode.INTERSECTION, selectedShapes)) {


//Get the System.Drawing.Color which is being used as the fill color for the shapes in the layer


col = Map1.get_ShapeLayerFillColor(hndl);


//Set all shapes in the shapefile back to their original color


Map1.set_ShapeLayerFillColor(hndl, System.Convert.ToUInt32(Information.RGB(col.R, col.G, col.B)));


//For each of the selected shapes in the shapefile, color them differently than their original fill color


for (i = 0; i <= Information.UBound(selectedShapes); i++) {



Map1.set_ShapeFillColor(hndl, selectedShapes(i), System.Convert.ToUInt32(Information.RGB(100, 100, 0)));


}

}

}
}
2.在页面窗体类中为Map1注册这个事件.
应该是这样:Map1.SelectBoxFinal += += new EventHandler(Map1_SelectBoxFinal);//此处委托事件不一定对应.因为每个函数和事件的参数可能不一致,如果写得不对,请根据控件对象点出事件(Map1.SelectBoxFinal)后,安{Tab}键自动生成.
这段事件注册的代码最好写在"Windows 窗体设计器生成的代码"中.

3.附上VB转C#的网站.如果常用参照VB的代码写C#.你会经常去逛的.当然这也可以将C#代码转成VB.
<a href=" http://www.developerfusion.com/tools/convert/vb-to-csharp/" target="_blank"> http://www.developerfusion.com/tools/convert/vb-to-csharp/</a>

上一个:请问一个VB问题,开启大写怎么实现?代码?
下一个:vb.net 中如何将图片保存到SQL数据库

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,