您的位置:首页 > 编程语言 > C#

C#在做AE自定义工具时的一个错误——自定义放大工具

2009-08-30 23:51 344 查看
需要动态加载一张图片,程序如下:
base.m_bitmap = new System.Drawing.Bitmap
(GetType().Assembly.GetManifestResourceStream(GetType(), "zoomout.bmp"));
但是调试时总会抛出异常“未处理的“System.ArgumentException”类型的异常出现在 system.drawing.dll 中。其他信息: “null”不是“stream”的有效值。”,显然GetTyp().Assembly.GetManifestResourceStream()方法 并没有找到需要加载的图片。难道是命名空间的问题,
实在让人不得其解,寻思半天。
查了一下资料,发现有人提到Build Action" property should be set to " Embedded Resourse",我突然想到Assembly.GetManifestResourceStream 是从当前程序集加载指定的清单资源,呵呵,我要加载的图片仅仅是放在项目文件夹中并包含在项目中,这个不能算是程序集中的资源阿。赶紧从项目文件列表中找到相应图片,点击图片,修改其操作属性为嵌入的资源,那可。
以下是自定义放大工具

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geometry;
using System.Drawing;

namespace 自定义工具程序
{
public sealed class ZoomOut : BaseTool
{
IMapControl3 mapControl;
private IHookHelper m_HookHelper = new HookHelperClass();
public ZoomOut()
{
//Set command properties
base.m_caption = "Zoom Out";
base.m_toolTip = "Zoom Out";
base.m_message = "Zoom Out on the Display";
base.m_name = "Generic_ZoomOut";
base.m_bitmap = new System.Drawing.Bitmap
(GetType().Assembly.GetManifestResourceStream(GetType(), "zoomout.bmp"));

}
public override void OnCreate(object hook)
{
m_HookHelper.Hook = hook;
if (hook is IToolbarControl)
{
IToolbarControl toolbarControl = (IToolbarControl)hook;
mapControl = (IMapControl3)toolbarControl.Buddy;
}
}

public override bool Enabled
{
get
{
if (m_HookHelper.FocusMap == null) return false;
return true;
}
}
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
//Track a rectangle on the active view
IEnvelope trackExtent = mapControl.TrackRectangle();
if (trackExtent == null) return;
//Get the current extent of the active view
IEnvelope currentExtent = mapControl.Extent;
IEnvelope newExtent = null;
//If the tracked envelope is empty
if (trackExtent.IsEmpty)
{
//Expand the current extent
newExtent = currentExtent;
newExtent.Expand(2.0, 2.0, true);
newExtent.CenterAt(mapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y));
}
else
{
//Create coordinates for the new extent
double dWidth = currentExtent.Width * (currentExtent.Width /
trackExtent.Width);
double dHeight = currentExtent.Height * (currentExtent.Height /
trackExtent.Height);
double dXmin = currentExtent.XMin - ((trackExtent.XMin -
currentExtent.XMin) * (currentExtent.Width / trackExtent.Width));
double dYmin = currentExtent.YMin - ((trackExtent.YMin -
currentExtent.YMin) * (currentExtent.Height / trackExtent.Height));
double dXmax = (currentExtent.XMin - ((trackExtent.XMin -
currentExtent.XMin) * (currentExtent.Width / trackExtent.Width))) + dWidth;
double dYmax = (currentExtent.YMin - ((trackExtent.YMin -
currentExtent.YMin) * (currentExtent.Height / trackExtent.Height))) + dHeight;
//Set the extent coordinates
newExtent = new EnvelopeClass();
newExtent.PutCoords(dXmin, dYmin, dXmax, dYmax);
}
//Set the new extent
mapControl.Extent = newExtent;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: