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#中应该怎么处理呢? 展开
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#中应该怎么处理呢? 展开
3个回答
展开全部
这句的意思就是此过程Map1_SelectBoxFinal绑定到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.
http://www.developerfusion.com/tools/convert/vb-to-csharp/
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/
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
//得到数据视图,参数为要排序的列
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();
}
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();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询