gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
阅读:1091回复:1

[分享]如何用VBA在ARCMAP中加入自己的窗体

楼主#
更多 发布于:2004-08-18 09:46
<P><FONT color=#007f00 size=5>Adding Custom Controls referenced to VBA Forms to the ArcGIS Interface</FONT></P></B><!--mstheme-->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0></FONT></FONT><!--mstheme--></FONT>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0></FONT><B><FONT face=Arial color=#ff0000 size=4>
<P align=justify>NOTE</FONT><FONT face=Verdana size=2>: This document shows how to load a form called <I>frmLayerInfo</I>. Wherever you see <I>frmLayerInfo</I> you need to substitute the </FONT></B><FONT face=Verdana size=2><FONT color=#ff0000>name</FONT><B> of the form you are loading.0</B></FONT><FONT face="宋体, MS Song" size=3> </FONT>


<P><FONT face="宋体, MS Song" size=3></FONT></P>
<FONT face="宋体, MS Song"></FONT></P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica"><FONT face=Verdana size=2>
<P>Many programs written in Visual Basic for Applications will come in the form of VB Forms (the form you interact with by clicking or entering information). These forms can be associated with buttons on the the ArcGIS GUI (Graphical User Interface). By associating a VB Form containing some custom program with a new button, you will have access to its custom functionality in any ArcGIS session. Everytime you open ArcGIS you are opening the "<I>Normal.mxt</I>" document. This document is called a <I><B>'template'</B></I> and contains the information necessary for ArcGIS to reconstruct the standard user environment (all the buttons and menu items you see evertime you start the program). </P></FONT><FONT face=Verdana size=1>
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image2.gif"></P></FONT><FONT face=Verdana size=2>
<P>It is in this "Normal" template that you will import a custom VB Form and associate that form with a custom button on the GUI. Once saved, it will be available to you each time you start ArcGIS.</P></FONT><FONT face=Verdana color=#007f00 size=5><I><B>
<P>Step 1: Finding the Normal.mxt</P></B></I></FONT>
<P>The <I>Normal.mxt</I> is found within the Visual Basic for Applications (VBA) Editor:</P>
<!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>Click on Tools->Macros->Visual Basic Editor in the menubar:
<p>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center>
<IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image3.gif"></P>
<P align=center></P>
<!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>Next you will see the visual basic editor
<p>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image4.gif"></P>
<P>        On the left side is the Project Explorer and in here you will see the <I>Normal.mxt</I> template as the first item.</P>
<!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>Click on the "+" sign to expand it, and then expand the folder called "ArcMap Objects".
<p>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image5.gif"></P>
<!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>We will come back to this later. The item under "ArcMap Objects" called "ThisDocument" will eventually contain two lines of code that will load our custom user form by clicking on a button within the ArcGIS GUI.
<p>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica"><FONT face=Verdana color=#007f00 size=5><I><B>
<P>Step 2: Importing the custom form into the Normal.mxt document template</P></B></I></FONT>
<P>We now need to load the custom userform called <I><B>frmLayerInfo</B></I> into the "<I>Normal.mxt</I>" document:</P>
<!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>Click on File->Import File in the VB Editor menubar:
<p>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image6.gif"></P>

<!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>Navigate to where you have saved the files <I><B>frmLayerInfo</B></I>.frm and <I><B>frmLayerInfo</B></I>.frx:
<p>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image7.gif"></P>
<P align=center></P>
<!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>If you look now at your Project Explorer you will see a new folder called "Forms" underneath the folder called "ArcMap Objects". Click on the "+" sign and you will see the <I><B>frmLayerInfo</B></I> form item within the folder:
<p>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image8.gif"></P>
<BLOCKQUOTE>
<P>You have now loaded the custom userform called <I><B>frmLayerInfo</B></I> into the <I>Normal.mxt</I> document template. </P></BLOCKQUOTE><!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>Now save the normal template by clicking on File->Save <I>Normal.mxt</I> in the menubar.
<p>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image9.gif"></P>
<FONT face=Verdana color=#007f00 size=5><I><B>
<P>Step 3: Creating a custom UIControlButton in ArcGIS GUI</P></B></I></FONT>
<P>Now that we have the custom form called <I><B>frmLayerInfo</B></I> within the ArcGIS <I>Normal.mxt</I> document template we next need to put a button on the button bar in ArcGIS that will load the form when we want to use its functionality within the GIS program.</P>
<!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>Return to the ArcGIS program
<p>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image10.gif"></P>
<!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>Right-click on any grey area of the Menubar and you will see the Customize Menu Appear. Choose the <U>C</U>ustomize… item at the bottom.
<p>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image11.gif"></P>
<P align=center></P>
<!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>Now the Customize Dialog box is showing. Click on the Commands Tab at the top of the Customize dialog box and scroll down until you find the item called "UIControls":
<p>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image12.gif"></P>
<!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>Click on the button called NewUIControl…
<p>
<P>Now the New UIControl dialogbox comes up and you want to create a new UIButtonControl (a button that eventually you can press and when you press it will load the user form called <I><B>frmLayerInfo</B></I>)</P>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image13.gif"></P>
<!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>The Customize dialog box will now show a new <FONT face=Verdana color=#ff0000 size=2>Normal.UIButtonControl1</FONT><FONT face=Verdana size=2> in the Commands: window pane on the left hand side:
<p>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image14.gif"></P>
<BLOCKQUOTE>
<P>This <FONT face=Verdana color=#ff0000 size=2>Normal.UIButtonControl1</FONT><FONT face=Verdana size=2> references the "<I>Normal.mxt</I>" document, hence the prefix "Normal" in front of the UIButtonControl. This button will now be associated with the user form so that when it is clicked it will load the userform and provide us with the necessary functionality to run the custom program.</P></BLOCKQUOTE></FONT><FONT face="BankGothic Md BT"><I><B>
<P>Step 4: Associating the new UIButtonControl with the frmLayerInfo within the Normal.mxt template</P></B></I></FONT>
<P>This is the semi-final step to giving a custom macro universal functionality within ArcGIS.</P>
<!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>Double click on the item </FONT><FONT face=Verdana color=#ff0000 size=2>Normal.UIButtonControl1
<p></FONT><FONT face=Verdana size=2>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image14.gif"></P>
<P align=center></P>
<!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>This will "Jump" you over to the Visual Basic Editor and the ThisDocument item under the ArcMap Objects folder within the <I>Normal.mxt</I> template. Now type in the following:
<p>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image15.gif"></P>
<!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>Now click the File->Save <I>Normal.mxt</I> in the menubar and you are almost finished.
<p>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image16.gif"></P>
<FONT face=Verdana color=#007f00 size=5><I><B>
<P>Step 5: Placing the new UIButtonControl onto the ArcGIS Interface</P></B></I></FONT>
<P>This is an easy step. It involves dragging the new button onto one of the button bars of ArcGIS.</P><!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>Right-click on any grey area of the Menubar and you will see the Customize Menu Appear. Choose the <U>C</U>ustomize… item at the bottom.
<p>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image11.gif"></P>
<P align=center></P>
<!--mstheme--></FONT>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<P>Goback to the Commands Tab and scroll down to the UIControls and you will see your </FONT><FONT face=Verdana color=#ff0000 size=2>Normal.UIButtonControl11
<p></FONT>
<p>
</P></TABLE><!--mstheme--><FONT face="Arial, Arial, Helvetica">
<P align=center><IMG src="http://www.uottawa.ca/academic/arts/geographie/lpcweb/web2320/arcGIS/custforms/Image17.gif"></P>
<P>    Click and drag this button onto one of the button bars within ArcGIS.</P><!--mstheme--></FONT>
喜欢0 评分0
GIS麦田守望者,期待与您交流。
destnity
路人甲
路人甲
  • 注册日期2004-03-25
  • 发帖数341
  • QQ
  • 铜币272枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2004-08-18 11:23
<img src="images/post/smile/dvbbs/em08.gif" /><img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em01.gif" />
签 名: 不能超过 250 个字符 文字将出现在您发表的文章的结尾处。
举报 回复(0) 喜欢(0)     评分
游客

返回顶部