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

PrivateSubMap1_SelectBoxFinal(ByValsenderAsObject,ByValeAsAxMapWinGIS._DMapEvents_Sel... 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#中应该怎么处理呢?
展开
 我来答
hacker8848
2010-05-19 · TA获得超过169个赞
知道答主
回答量:316
采纳率:100%
帮助的人:173万
展开全部
这句的意思就是此过程Map1_SelectBoxFinal绑定到Map1.SelectBoxFinal事件,在C#中可以不用处理
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
aino77
2010-05-19 · TA获得超过920个赞
知道小有建树答主
回答量:378
采纳率:0%
帮助的人:282万
展开全部
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.
http://www.developerfusion.com/tools/convert/vb-to-csharp/

参考资料: http://www.developerfusion.com/tools/convert/vb-to-csharp/

本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
激活痛
2010-05-19
知道答主
回答量:12
采纳率:0%
帮助的人:0
展开全部
//得到数据视图,参数为要排序的列
private DataView GetDv(string strSort)
{
//定义数据库连接
DataView dv;
SqlConnection CN = new SqlConnection();
try
{
//初始化连接字符串
CN.ConnectionString = "data source=pmserver;initial catalog=Northwind;persist security info=False;user id=sa;Password=sa;";
CN.Open();
//从NorthWind得到orders表的数据
SqlDataAdapter adp = new SqlDataAdapter("select * from orders", CN);
DataSet ds = new DataSet();
adp.Fill(ds);
//得到数据视图
dv = ds.Tables[0].DefaultView;
}
catch (Exception ex)
{
#if DEBUG
Session["Error"] = ex.ToString();
Response.Redirect("../error.aspx"); //跳转程序的公共错误处理页面
#endif
}
finally
{
//关闭连接
CN.Close();
}
//排序
dv.Sort = strSort;
return dv;
}

private void Page_Load(System.Object sender, System.EventArgs e)
{
if (! IsPostBack)
{
ViewState["strSort"] = "orderid";
dgOrder.DataSource = GetDv[ViewState["strSort"].ToString()];
dgOrder.DataBind();
}
}
//排序
private void dgOrder_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
dgOrder.CurrentPageIndex = 0;
//得到排序的列
ViewState["strSort"] = e.SortExpression.ToString();
dgOrder.DataSource = GetDv[ViewState["strSort"].ToString()];
dgOrder.DataBind();
}

//分页
private void dgOrder_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
//得到分页的页号
dgOrder.CurrentPageIndex = e.NewPageIndex;
dgOrder.DataSource = GetDv[ViewState["strSort"].ToString()];
dgOrder.DataBind();
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式