📄 ch9.htm
字号:
<td WIDTH="118"><tt><font FACE="Courier">Left</font></tt> </td>
<td WIDTH="172">5400</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Top</font></tt> </td>
<td WIDTH="172">1920</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Width</font></tt> </td>
<td WIDTH="172">1800</td>
</tr>
<tr>
<td WIDTH="161">Command Button</td>
<td WIDTH="118"><tt><font FACE="Courier">Name</font></tt> </td>
<td WIDTH="172">Command1</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Caption</font></tt> </td>
<td WIDTH="172">Read &Inbox</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Font</font></tt> </td>
<td WIDTH="172">8pt MS Sans Serif, Bold</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Height</font></tt> </td>
<td WIDTH="172">450</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Index</font></tt> </td>
<td WIDTH="172">4</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Left</font></tt> </td>
<td WIDTH="172">5400</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Top</font></tt> </td>
<td WIDTH="172">2520</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Width</font></tt> </td>
<td WIDTH="172">1800</td>
</tr>
<tr>
<td WIDTH="161">Command Button</td>
<td WIDTH="118"><tt><font FACE="Courier">Name</font></tt> </td>
<td WIDTH="172">Command1</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Caption</font></tt> </td>
<td WIDTH="172">Send &Mail</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Font</font></tt> </td>
<td WIDTH="172">8pt MS Sans Serif, Bold</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Height</font></tt> </td>
<td WIDTH="172">450</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Index</font></tt> </td>
<td WIDTH="172">5</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Left</font></tt> </td>
<td WIDTH="172">5400</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Top</font></tt> </td>
<td WIDTH="172">3120</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Width</font></tt> </td>
<td WIDTH="172">1800</td>
</tr>
<tr>
<td WIDTH="161">Command Button</td>
<td WIDTH="118"><tt><font FACE="Courier">Name</font></tt> </td>
<td WIDTH="172">Command1</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Caption</font></tt> </td>
<td WIDTH="172">&Read && Send</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Font</font></tt> </td>
<td WIDTH="172">8pt MS Sans Serif, Bold</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Height</font></tt> </td>
<td WIDTH="172">450</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Index</font></tt> </td>
<td WIDTH="172">6</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Left</font></tt> </td>
<td WIDTH="172">5400</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Top</font></tt> </td>
<td WIDTH="172">3720</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Width</font></tt> </td>
<td WIDTH="172">1800</td>
</tr>
<tr>
<td WIDTH="161">Command Button</td>
<td WIDTH="118"><tt><font FACE="Courier">Name</font></tt> </td>
<td WIDTH="172">Command1</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Caption</font></tt> </td>
<td WIDTH="172">E&xit</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Font</font></tt> </td>
<td WIDTH="172">8pt MS Sans Serif, Bold</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Height</font></tt> </td>
<td WIDTH="172">450</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Index</font></tt> </td>
<td WIDTH="172">7</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Left</font></tt> </td>
<td WIDTH="172">5400</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Top</font></tt> </td>
<td WIDTH="172">4320</td>
</tr>
<tr>
<td WIDTH="161"> </td>
<td WIDTH="118"><tt><font FACE="Courier">Width</font></tt> </td>
<td WIDTH="172">1800</td>
</tr>
</table>
</center></div>
<p>Note that the layout table calls for a control array of command buttons. Add a single
button to the form, set its properties (including the <tt><font FACE="Courier">Index</font></tt>
property), and then use the <tt><font FACE="Courier">Edit </font></tt>|<tt><font
FACE="Courier"> Copy</font></tt>, <tt><font FACE="Courier">Edit </font></tt>| <tt><font
FACE="Courier">Paste</font></tt> menu options to make the additional copies of the button.
You can then edit the <tt><font FACE="Courier">Caption</font></tt> properties as needed. </p>
<p>After you lay out the form, you need to add a handful of variables to the general
declaration area, a few routines to handle the standard form events, and one routine to
respond to the command-button actions. Listing 9.1 shows the code that declares the
form-level variables for this project. Add this code to the general declaration area of
the form. </p>
<hr>
<blockquote>
<b><p>Listing 9.1. Adding the form-level variables.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Option Explicit<br>
<br>
Dim objMAPISession As Object ' session object<br>
Dim cMLMFile As String '
control file<br>
Dim cCtlName() As String ' control names<br>
Dim cCtlValue() As String ' control values<br>
Dim bErr As Boolean '
error flag<br>
Dim nWidth As Integer '
form width<br>
Dim nHeight As Integer ' form
height<br>
Dim EOL As String '
end of line</font></tt> </p>
</blockquote>
<hr>
<p>Next, add the code in Listing 9.2 to the <tt><font FACE="Courier">Form_Load</font></tt>
event. This code centers the form and then stores its current width and height. This
information will be used to prevent users from resizing the form at run-time. </p>
<hr>
<blockquote>
<b><p>Listing 9.2. Adding code to the <tt><font FACE="Courier">Form_Load</font></tt>
event.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Private Sub Form_Load()<br>
'<br>
Me.Top = (Screen.Height - Me.Height) / 2<br>
Me.Left = (Screen.Width - Me.Width) / 2<br>
'<br>
nWidth = Me.Width<br>
nHeight = Me.Height<br>
EOL = (Chr(13) & Chr(10))<br>
Text1 = ""<br>
Me.Caption = "Mailing List Manager [" & cMLMFile
& "]"<br>
'<br>
' check for passed parm<br>
'<br>
If Len(Command$) <> 0 Then<br>
cMLMFile = Command$ <br>
Else<br>
cMLMFile = "mlm.txt" <br>
End If<br>
'<br>
End Sub</font></tt> </p>
</blockquote>
<hr>
<p>You'll also notice that the <tt><font FACE="Courier">Form_Load</font></tt> event checks
for a parameter passed on the command line at startup. This will be used to determine what
set of control files will be used for each run of the MLM application (you'll see more
about this later). </p>
<p>Next, add the code in Listing 9.3 to the <tt><font FACE="Courier">Form_Resize</font></tt>
event. This code uses the values established in the <tt><font FACE="Courier">Form_Load</font></tt>
event to keep forcing the form back to its original size whenever a user tries to adjust
the form size. Note, however, that this routine <i>will</i> allow users to minimize the
form. </p>
<hr>
<blockquote>
<b><p>Listing 9.3. Adding code to the <tt><font FACE="Courier">Form_Resize</font></tt>
event.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Private Sub Form_Resize()<br>
'<br>
If Me.WindowState <> vbMinimized Then<br>
Me.Width = nWidth <br>
Me.Height = nHeight <br>
End If<br>
'<br>
End Sub</font></tt> </p>
</blockquote>
<hr>
<p>You also need to add code behind the command-button control array. Listing 9.4 contains
the code that should be placed in the <tt><font FACE="Courier">Command1_Click</font></tt>
event. This routine just calls a set of custom subroutines that you'll add a bit later in
the chapter. </p>
<hr>
<blockquote>
<b><p>Listing 9.4. Adding the code in the <tt><font FACE="Courier">Command1_Click</font></tt>
event.<br>
</b></p>
</blockquote>
<blockquote>
<tt><font FACE="Courier"><p>Private Sub Command1_Click(Index As Integer) <br>
'<br>
' handle user clicks<br>
'<br>
Select Case Index<br>
Case 0 ' edit controls<br>
ControlsEdit <br>
Case 1 ' edit subs<br>
SubEdit <br>
Case 2 ' edit schedule<br>
SkedEdit <br>
Case 3 ' edit archive<br>
ArchEdit <br>
Case 4 ' read inbox<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -