Upload
warawut
View
458
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Example Code VB2008 - Form MDI
Citation preview
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 1
�������������� MDI
1. ��#$���%� &�'������ Microsoft Visual Basic 2008 ��������(� �������'�������)�*�+$ ���, Start>>> All Programs>>> Microsoft Visual Basic 2008 Express Edition % ��,�
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 2
2. ������������)�� +.�*%�)(�� �� '%� *�+$ File>>> New Project ()�#� �% Ctrl+N +$������%) % ��,�
�0�1230 �#� �(�������+$ ���#$��)��� (New Project) ��1678 �2*%� ������3)������� New Project �)��(#�� Windows Forms Application �(� �.�)�%���� Name �� mdi �(��>>> OK % ��,�
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 3
��*%� From1.vb (+$ Solution Explorer) % ��,�
���6>?0@A7BC@����D7BE�� Solution Explorer
-+.�*%� '%� �(��+$ Form1.vb ���� ���� Solution Explorer -�� ���� Properties +$���� File Name ��� Form1.vb �)���($����8� frmMain.vb % ��,�
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 4
3. ���� ���� Properties ������+$���� �� Text �%���#$� �� Form1 �)���($����8� GCH7I�7���DB���7������ MDI (VB2008) % ��,�
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 5
:(+$*%� �#�
>>>
***��������� ������� �������� ����������������� Text
�(���������� (Name) ���� ���� Properties �)�� &��#$���8� frmMain % ��,�
������������������������ ��� ������������������� ���������������� ������� �� ���
4. �����������DLE
�(��+$���#$��)��� (Add Windows FormM)
������3)������� Add New Item
������������������������ ��� ������������������� ���������������� ������� �� ���
(Add Windows FormM) % ��,�
Add New Item % ��,�
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 6
������������������������ ��� ������������������� ���������������� ������� �� ���
�)��(#�� Windows Form>>> +$���<&��� 1 =���� ><$���,����� ����
���� ���� Properties +$�������:(( ��� % ��,�
������������������������ ��� ������������������� ���������������� ������� �� ���
+$���� Name � &��#$� �� frmChild>>> �(�� Add �2��*%�=�����)�� Solution Explorer % ��,�
+$������� Text � &��#$� �� ���?8� �(� ������ (Name) � &��#$� ��
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 7
�2��*%�=�����)��
� &��#$� �� frmChild ��*%�
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 8
5. ���6?C��BOPQR��S@� �)�*��(��+$ frmMain.vb �(� �)�*�+$�1���#$���#�%��� T��A +$�#$� �� Toolbox �(���(� �(#�� Menus&Toolbars>>> % ��&(�(��+$ MenuStrip % ��,�
���2��(� ��*%� % ��,�
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 9
6. ����R�L7PQOV��SW2X�����6YZ�W
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 10
������ Type Here �)����������=����%���(���
���2��(� �)�*��.�)�%�#$����� ���� Properties % ��&
YSP������ �.�)�%������ (Name) �� mnuFrom
6>]P���?8� ���6>]PTHR� �.�)�%������ (Name) �� mnuOpenChildFrom
6>]P���?8� ���6>]P 1 ��� �.�)�%������ (Name) �� mnuOpenSingelChildFrom
>]P���?8�_SH�LP �.�)�%������ (Name) �� mnuCloseAllChildFrom
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 11
�.�)�%�#$����� ���� Properties % ��&
L7��WE�� �.�)�%������ (Name) �� mnuWindow
Tile Horizontal �.�)�%������ (Name) �� mnuTileHorizontal
Tile Vertical �.�)�%������ (Name) �� mnuTileVertical
Cascade �.�)�%������ (Name) �� mnuCascade
Arrange Icons �.�)�%������ (Name) �� mnuArrangeIcons
�.�)�%�#$����� ���� Properties % ��& ���Y��a>���� �.�)�%������ (Name) �� mnuExit
������������������������ ��� ������������������� ���������������� ������� �� ���
7. ���6X0A7aQ�PDL��S����6YZ�W
_0@ Solution Explorer �(#�� frmMain.vb ��� Code �)�=���������� ���������� ! ��������!���"
1.
��+ %+$ 1 �(� 2 �#� ��� �� �)����� -Option Explicit
-Option Strict
2.
��+ %+$ 11 ����8����������� ���� �=����MdiBackground()
������������������������ ��� ������������������� ���������������� ������� �� ���
���6X0A7aQ�PDL��S����6YZ�W
frmMain.vb �(� �%��B� F7 +$������% )�#� �(��+$ (View Code)
���������� ! ��������!���"
�� �)������.�)�%� ���+$������ Explicit On �#� �������������C� �������������Strict On �#� �)������� ������%����,(������������ %
����8����������� ���� �=���� frmMain ��� Sub New �(�����> �,+�MdiBackground() +.����
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 12
(View Code) ��#$�
�������������C� ������������� �)������� ������%����,(������������ %
����> �,+�
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 13
3.
��+ %+$ 14 1<� 22 ��8������ ��� �(����)�=����(,�
-Private Sub MdiBackground())���1<� �)� �(,���=���� frmMain ��#$�)����'+�( MdiClient -For Each c As Control In Me.Controls )���1<� 1��� �������2��� c ��8����'+�( MdiClient �(� �)�(���#&�)( �%� �� Azure
4.
��+ %+$ 24 1<� 26 ��8�����.�)�%=����')(% ���)���%�:(�����*� 5. % ��&(�(��+$ 6>]P���?8� ���6>]PTHR� ��=����)( �
��+ %+$ 28 1<� 32 ��8����� $� Open (��N%) =����(,��>&.�O -Dim f As New frmChild �#� � �������2���=���� frmChild +$�#$� �� f -f.MdiParent = Me �#� �.�)�%�#$�=������� -f.Show() �#� ��%�=����(,�
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 14
6. % ��&(�(��+$ 6>]P���?8� ���6>]P 1 �����=����)( �
��+ %+$ 34 1<� 48 ��8����� $� Open =����(,� ���N%=�����%�
-Dim currentForm As Form )���1<� � ���������� Form -For Each currentForm In Me.MdiChildren )���1<� �(,���
)�%+��=����(,� -If TypeOf currentForm Is frmChild Then )���1<� 1��=����
�P��� � ��8�=���� frmChild �(� -currentForm.MdiParent = Me )���1<� �.�)�%�#$�=�������
-currentForm.Show())���1<� ��%�=����(,��P��� �+$���,� -Exit Sub )���1<� �)��������)�����Q� -Dim f As New frmChild )���1<� � �������2���=���� frmChild +$�#$� �� f -f.MdiParent = Me )���1<� �.�)�%�#$�=������� -f.Show())���1<� ��%�=����(,�
7. % ��&(�(��+$ >]P���?8�_SH�LP��=����)( �
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 15
��+ %+$ 50 1<� 55 ����8����� $��N%=����(,�+ &�)�% -Dim f As Form )���1<� � �������2��� Form
-For Each f In Me.MdiChildren )���1<� �(,���)�%+��=����(,�+$���,� -f.Close())���1<� �N%=����(,��P��� �
8. % ��&(�(��+$ Tile Horizontal ��=����)( �
Tile Horizontal �#� ��%�=����(,���� ���
9. % ��&(�(��+$ Tile Vertical��=����)( �
Tile Vertical �#� ��%�=������� � &�
10. % ��&(�(��+$ Cascade ��=����)( �
Cascade �#� ��%�=����(,�>���O � �
11. % ��&(�(��+$ ArrangeIcons ��=����)( �
ArrangeIcons �#� ���� %����*����
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 16
12. % ��&(�(��+$ ���Y��a>���� ��=����)( �
�#� ����N%=����
�����P�g?
�)��(��+$ +$�1���, )�#� *�+$���, Debug>>> �(#�� Star debugging % ��,�
������
=����)( �
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 17
�����N%=����(,����N%>&.�
�����N%=����(,�� ��N% 1 =����
����N%=����(,�+ &�)�%
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 18
�����N%=������� ��� (Horizontal)
�����N%=������� � &� (Vertical)
�����N%=�����>���O � � (Cascade)
������������������������ ��� ������������������� ���������������� ������� �� ��� ����� � 19
���� %����*����
������=����)( �
����+.����****