徐修云
路人甲
路人甲
  • 注册日期2005-09-26
  • 发帖数14
  • QQ
  • 铜币158枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1951回复:3

[原创]求助c#与AO开发

楼主#
更多 发布于:2007-01-31 18:03
<P>求各位高手帮帮忙,最近在学c#开发ao,在模拟vb开发ao的代码中,遇到这样一段代码:</P><PRE><CODE><FONT color=#0000ff>Public Sub</FONT></CODE> AddLayerFileToMap()
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> filePath <CODE><FONT color=#0000ff>As String</FONT></CODE>
  filePath = "D:\arcgis\arcexe83\ArcObjects Developer Kit\samples\data\USA\states.lyr"
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pGxLayer <CODE><FONT color=#0000ff>As</FONT></CODE> IGxLayer
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pGxFile <CODE><FONT color=#0000ff>As</FONT></CODE> IGxFile

  <CODE><FONT color=#0000ff>Set</FONT></CODE> pGxLayer = <CODE><FONT color=#0000ff>New</FONT></CODE> GxLayer
  <CODE><FONT color=#0000ff>Set</FONT></CODE> pGxFile = pGxLayer
  pGxFile.Path = filePath
  <CODE><FONT color=#0000ff>Dim</FONT></CODE> pMxDoc <CODE><FONT color=#0000ff>As</FONT></CODE> IMxDocument
  <CODE><FONT color=#0000ff>Set</FONT></CODE> pMxDoc = ThisDocument
  pMxDoc.FocusMap.AddLayer pGxLayer.Layer
<CODE><FONT color=#0000ff>End Sub</FONT></CODE>
其中<FONT color=#0000ff>Set</FONT> pMxDoc = ThisDocument一句因为c#中没有ThisDocument这一类,又不知道怎样把它转换成c#语句,哪位高手帮帮忙,帮我把这一句改成c#语句,不甚感激!!!</PRE>
喜欢0 评分0
徐修云
路人甲
路人甲
  • 注册日期2005-09-26
  • 发帖数14
  • QQ
  • 铜币158枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2007-02-02 08:38
谢谢楼上的以及楼上的楼上的!<img src="images/post/smile/dvbbs/em04.gif" />
举报 回复(0) 喜欢(0)     评分
sunki
路人甲
路人甲
  • 注册日期2004-04-30
  • 发帖数33
  • QQ
  • 铜币50枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2007-02-01 21:57
<P>using System;<BR>using System.Runtime.InteropServices;<BR>using System.Windows.Forms;<BR>using System.Drawing;<BR>using System.Collections.Generic;<BR>using System.Text;<BR>using ESRI.ArcGIS.SystemUI;<BR>using ESRI.ArcGIS.ArcMapUI;<BR>using ESRI.ArcGIS.Framework;<BR>using ESRI.ArcGIS.ADF.BaseClasses;<BR>using ESRI.ArcGIS.ADF.CATIDs;<BR>using MapGenerizeCS;<BR>using ESRI.ArcGIS.Carto;<BR>using ESRI.ArcGIS.Display;</P><BR>
<P>namespace MapGenerizeCS.CommandsCLS<BR>{<BR>    [Guid("90C8BF0F-A26A-4631-98BE-A23098C5D004")]<BR>    [ClassInterface(ClassInterfaceType.None)]<BR>    [ProgId("MapGenerizeCS.CommandsCLS.EleminatePo")]<BR>    public sealed class EleminatePBaseCommand<BR>    {<BR>        #region COM类注册<BR>        [ComRegisterFunction()]<BR>        [ComVisible(false)]<BR>        static void RegisterFunction(Type regType)<BR>        {<BR>            try<BR>            {<BR>                string strReg = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", regType.GUID);<BR>                MxCommands.Register(strReg);<BR>            }<BR>            catch (Exception ex)<BR>            {<BR>                ex.ToString();<BR>            }        <BR>        }<BR>        [ComUnregisterFunction]<BR>        [ComVisible(false)]<BR>        static void UnregisterFunction(Type regType)<BR>        {<BR>            try <BR>            {<BR>                string strReg = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", regType.GUID);<BR>                MxCommands.Unregister(strReg);<BR>            }<BR>            catch (Exception ex)<BR>            {<BR>                ex.ToString();<BR>            }        <BR>        }</P><BR>
<P>        #endregion<BR>        <BR>        private IApplication m_pApp;</P><BR>
<P>        private IMxDocument m_mxDoc = null;<BR>        private IMxDocument m_MxDocument = null;<BR>        private Map m_pMap = null;</P><BR>
<P>        private IDocumentEvents_OpenDocumentEventHandler hDocOpenEvents;<BR>        <BR>        public EleminatePo()<BR>        { <BR>            try<BR>            {<BR>                base.m_caption = "";<BR>                base.m_category = "";<BR>                base.m_name = "";<BR>                base.m_toolTip = "";<BR>                base.m_bitmap = CommandPics.EleminateBMP;<BR>            }<BR>            catch(Exception ex)<BR>            {<BR>                ex.ToString();<BR>            }<BR>        }</P><BR>
<P>        public override void OnCreate(object hook)<BR>        {<BR>            try<BR>            {<BR>                m_pApp = hook as IApplication;<BR>                m_MxDocument = m_pApp.Document as IMxDocument;<BR>                m_mxDoc = m_pApp.Document as IMxDocument;<BR>                m_pMap = (Map)m_mxDoc.FocusMap;<BR>                base.m_enabled = true;<BR>                StartEventHandler();<BR>            }<BR>            catch (Exception ex)<BR>            {<BR>                ex.ToString();                <BR>            }<BR>        }<BR>        public override void OnClick()<BR>        {<BR>            MessageBox.Show("", "提示");<BR>            base.OnClick();<BR>        }</P><BR>
<P><BR>        private void StartEventHandler()<BR>        {<BR>            hDocOpenEvents = new IDocumentEvents_OpenDocumentEventHandler(DocOpenE);<BR>            ((IDocumentEvents_Event)m_MxDocument).OpenDocument += hDocOpenEvents;<BR>            <BR>        }<BR>        private void DocOpenE()<BR>        {<BR>            MessageBox.Show("打开一个新的文档");<BR>        }       <BR>    }<BR>}<BR>你自己再看着改改了。</P>
我爱绿色百合!
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
3楼#
发布于:2007-02-01 15:49
<P>thisDocument只在arcgis的vba开发环境里是有效的;</P>
<P>具体你可以看看帮助的说明</P>
[此贴子已经被作者于2007-2-1 15:50:53编辑过]
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
游客

返回顶部