阅读:1950回复:3
[原创]求助c#与AO开发
<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> |
|
1楼#
发布于:2007-02-01 15:49
<P>thisDocument只在arcgis的vba开发环境里是有效的;</P>
<P>具体你可以看看帮助的说明</P> [此贴子已经被作者于2007-2-1 15:50:53编辑过]
|
|
|
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> |
|
|
3楼#
发布于:2007-02-02 08:38
谢谢楼上的以及楼上的楼上的!<img src="images/post/smile/dvbbs/em04.gif" />
|
|