       .  4:   Visual Basic  
  


                   (). XVIII       Visual Basic    .      .  I.   Visual Basic.  II.         .  III.       .  IV.            .  V.        ,    .  VI.               .  VII.        -       .





 

       .  4:   Visual Basic  


      

  (  )








                                  ,      ,        Visual Basic         Microsoft ().

  ()     ,    ,   ,         .     , ,      ,    ,      -    .  ,         .           .      , ,     ,   ,      ,        .            .

  (, , ) Visual Studio (  VS)   -               ,             .  ,    VS      ,       ,       (    )            Visual C#, Visual Basic  Visual C++.      (   )    ,     ,              .

       ,      .           Visual Basic        VB.     ,        (          ZharkovPress.ru     )    ,         .           ,            VB,      ;       ,           Visual Basic     .    ,        ,    ,   (   ,     ,       ),      ,     .         ,           .     .           (        ,    )      ( : ,  )           VS.               (      )        .                       ZharkovPress.ru (    Help  Visual Studio,  ,      ),       , ,     (   )   , , , , ,      (  )     .                 VS  (  ),            ,        .

    XVIII         Visual Basic.



 I.   Visual Basic

 1.   

 2.         

 3.              

 II.         

 4.      

 5.   ,       

 6.    

 7.   ,      

 8.       

 9.         

 10.       ,         

 11.      

 III.       

 12.            

 IV.            

 13.               

 V.        ,    

 14.        ,           ,    

 15.        ,           ,    

 VI.               

 16.               12 

 17.               7      ,     

 VII.        -       

 18.        -

 VIII.              

 19.               

 IX.               

 20.           

 21.           5     

 X.        

 22.                

 XI.               

 23.                

 XII.       

 24.                  

 XIII.        

 25.              

 XIV.         ,   

 26.          ,          

 XV.       

 27.         

 XVI.                

 28.         

 29.    

 30.  

 XVII.          

 31.    

 XVIII. ,          

 32.     



 

   VII        Visual Basic.



 I.   Visual Basic

 1.   

 2.         

 3.              

 II.         

 4.      

 5.   ,       

 6.    

 7.   ,      

 8.       

 9.         

 10.       ,         

 11.      

 III.       

 12.            

 IV.            

 13.               

 V.        ,    

 14.        ,           ,    

 15.        ,           ,    

 VI.               

 16.               12 

 17.               7      ,     

 VII.        -       

 18.        -



 

        ,    Microsoft,      Microsof.                   ,        .     ,        (              ZharkovPress.ru)  ,                ,                 ,            .

                      ,    (  )    Visual Basic     ,   ,                           .      ,   ,      , , , ,    .

            .

,           email:

valery-zharkov@mtu-net.ru

:       ( )




 I.   Visual Basic





 1.   





1.1.   


  (computer game)            ,   .

   ,       (game program),           ,      .

       ,            ,        .  ,  ,  ,     .

                    .

          Microsoft Windows.

             Microsoft Visual Basic    Microsoft Visual Studio  .

      (  )  .                DirectX,     DirectX  XNA  ,   Microsoft.

,    ,    .

  ,       (   ,    puzzle  )   ,        (, ,   ..).      ,   ,          .           ,     .

 (arcade game)      ,  ,  ,  ,     ,   ,      ,  ,     .     ,   ,        .           ,   .        ,  (shooter)   (action).

   .              ,         .       , ,    ,      ,       .      ,     ,   .

   (adventure game)  ,          , ,    .

   (extensive game)  ,     , ,     .

-    , , ,     .

         (,   ..).

         ,   , ,       ,     .

 (interactive game)  ,           .

 (network game)  ,      ,            LAN  Local Area Network.

 (training game)  ,     .

          .   (RPG Role Playing Game)   ,         (     ) .

  ,    (no-solution game),   .

     ,    ,    ,   ,    ,      ,      .

                   .    ,     ,     (,  ),    .

         ,        .




1.2.   


     -     ,      Visual Studio,     (  )      .

1.   (   , ,   ..) Visual Studio   VS  Microsoft.         . ,     VS, , Express-  -,      Microsoft.        VS        ZharkovPress.ru.

VS    CLR (Common Languege Runtime),      .       (   ) ,     (  CLR). ,         ,      MSIL (Microsoft Intermediate Language)       .             .

             (  )  Visual Basic,       ,       (Visual Basic, C#, ++, J#)    (   []). ,     Visual Studio        Visual Studio.

     Windows,        Visual Studio,  ,   Visual Basic       GDI+ (Graphics Device Interface)   GDI+            .

  ,     ZharkovPress.ru         DirectX     .

2.    DirectX / XNA,     Microsof       DirectX     DirectX Software Development Kit (SDK)  XNA.         DX  XNA.    DX  XNA     Microsoft. ,     Microsoft   DirectX        Windows     Technologies. , DirectX (  DX)   ,      (  ).

,                  DirectX  XNA,        ,     DirectX  XNA.




 2.         





2.1.  - 


             .            ,        ,    ,     .

        :

     ;

    ;

    ;

      ().

    (   )  :

1)  ,     (,   ,        ),    ,       ,           (,     )  -  ()     Visual Basic;

2)  ,             ( ,      )    ,    ,      (   , , Windows)      .




2.2.  


    -   (  )      .    ,   ,         ,               (  ).

    ( ) Visual Basic   Visual Studio (   )    .

1.   ( :  , , ,   ..) Visual Studio    New Project ( File, New, Project).

2.   New Project (. 2.1)   Project Types    Visual Basic, Windows, Windows  ,    Templates   ( ,  )  Windows Forms Application;  Name   , , Calculator.     Location    ( Projects      ),      .        Location (  Browse)            ,     .

3.     (Solution)     ,            (   ),    (  )  Create Directory for Solution (. 2.1)     .








. 2.1.   Project Types   Visual Basic, Windows.

4.   New Projects (. 2.1)  OK. Visual Basic         Form1    (,   )   Form1.vb[Design],         .

5.   ,          ,        Visual Studio.      Visual Studio   :

    (Solution)   ,    Build  Build Solution        ,    Ctrl+Shift+B; ,         Tools, Customize,      Alt,     (    Microsoft Word);

    (Selection)    (   ),    Build, Build Selection        ;  Build    Build Selection   Selection    ,    Calculator.

      Output   Output (. 2.2)   VB       :



Build complete  0 errors, 0 warnings

=== Build: 1succeeded, 0 failed, 0 up-to-date, 0 skipped ===

6.   ,     :  Debug  Start Without Debugging (   Ctrl+F5)  Start ( F5),        .

  Form1       Form1   ,          .      x (Close  )          .

   Visual Studio ,        (   ).




2.3.   


  (        Toolbox, . 2.2)          .

1.  Properties ()    Form1 (. 2.3)    (    )    View, Properties Window          ,         .    Properties   Form1,     ,            Properties.   Properties        Properties (   , ,   Events).   (  )              ;           Enter.     () Form1   ,       Form1.vb[Design]    Solution Explorer (- ),   . 2.3,      Form1.vb.

2.   Properties   Form1 (. 2.3)  ()  Font      .    Font (. 2.4).

3.   Font () , ,  Times New Roman   (Size) 14          ,         Toolbox.   Font  OK.

4.    ,   Properties   Text   Form1  (    :  , Paste), , Calculator;    Text (   Enter), . 2.3.

5.    BackColor (. 2.3)    (     Control)       Form1.      . ,             .

6.    BackgroundImage (), . 2.3,           ( (.bmp), (.jpg), (.gif)  .)    ,              ;          (, TextBox  Button)   (, Timer),    .

7. ,     Toolbox (. 2.2)    Windows Forms   .

                 GroupBox,        .      Toolbox (. 2.2)   GroupBox ( ).    .    GroupBox   ,   Properties   Text      (    :  , Paste), ,   (Addition of numbers);     Text (   Enter).

   Properties    .








. 2.2.   Toolbox.








. 2.3.  Properties.

8.      TextBox (   );  Properties      .

9.     TextBox        .

10.    ,    ,          Label. ,   Label          ,    Properties        Text      (    :  , Paste), ,  (number).

11.        ,          +.

12.           =,        :   Toolbox  Button;   ;           ,    Properties   Text      (    :  , Paste), ,   =;     Text (   Enter).   Form1   Form1.Designer.vb (. 2.5)    .     (. 2.6).

       Visual Studio      ,        [].  ,   ,     ,      Visual Studio.








. 2.4.   Font  .








. 2.5.  Form1.Designer.vb.








. 2.6.    () .




2.4.  


   Form1.vb            .          ,                Events (    )   Properties (. 2.3). ,       = (. 2.6)        Click   Events  Properties.         ,                   .

 .   Form1.vb               :

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click

End Sub

           (Imports System),   System (   )        .             .      (   , , TextBox) ,        .       :

 2.1.      .

Dim a, b, c As Double

a = Convert.ToDouble(TextBox1.Text)

b = Convert.ToDouble(TextBox2.Text)

c = a + b

TextBox3.Text = c.ToString

     :

Dim a, b As Double

a = Convert.ToDouble(TextBox1.Text)

b = Convert.ToDouble(TextBox2.Text)

TextBox3.Text = a + b.ToString

     :

Dim a As Double

a = Convert.ToDouble(TextBox1.Text)

TextBox3.Text = (a + _

Convert.ToDouble(TextBox2.Text)).ToString

     :

TextBox3.Text = (Convert.ToDouble(TextBox1.Text) + _

Convert.ToDouble(TextBox2.Text)).ToString

          .     (  , ,     )     [].

   ( Build, Build Selection       )      Output   VB    ,    (         )          .   ,   ,     ,         .

  ,    Debug  Start Without Debugging (       ).         (. 2.6)      (. 2.7),            .




2.5.  


  : 1,1 + 2,2 = 3,3     . 2.7.








. 2.7.    .

 . 2.7 ,            ,         . ,      2.1   ( ) ,      .          .

    :   ,   .  ,                     Visual Basic (  ).




2.6.   


          .        , , ,   ( 2). ,        (   ,       ),          .     .      , ,   ( 3).    =    . 2.8.      (, ), , 5,555555555555557E+19 (. 2.8)    E  ,   E  . ,       ,    ,  (   6  . 2.8     ).      =          ,  ,    ( )          . ,        31.








. 2.8.     .

           :

1.          .

2.        (15).

3.       (31).

4.    x   |x|

1*10E-031 <= |x| <= 9.99999999999999*10E+031.

5.    ():

 

1 <= |x| <= 999999999999999

;

 

1*10E-031 <= |x| < 1

 999999999999999 < |x| <= 9.99999999999999*10E+031

.

     ,     -     Windows-,   - .      ,        ,     ,  (    )          -          ,         ( )        .   .




2.7.    


             , ,   ,             (  ).          .

       Timer   :    Toolbox   Timer (. 2.3);   .  Form1     Timer1 (. 2.9),         . ,                   .   Properties   timer1   Enabled  False  True (. 2.10),    Interval     100  , ,  500  (,  1000   1 ). ,         Properties,    , ,    .

 2.2.        .

Private Sub InitializeTimer()

'  Timer:

Timer1.Enabled = True

'  Tick    Interval:

Timer1.Interval = 500

End Sub

         500  ( 0,5 )      Tick      Timer1_Tick (.   2.3),  ,       .








. 2.9.    Timer.








. 2.10.  Properties.

,      ,      .        Timer (. 2.9).   Form1.vb     ,         2.3.

 2.3.     .

Private Sub Timer1_Tick(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Timer1.Tick

'  ,

'   False:

Static myText As Boolean

'    :

If myText Then

Me.Text = " (Calculator)"

Else

Me.Text = "   " & _

"(Calculator with animation)"

End If

'  myText  :

myText = Not myText

End Sub

    ,           [].

       : Build, Build Selection; Debug, Start Without Debugging.   Visual Basic        .         500  ( 0,5 )   (Calculator)      (Calculator with animation) (. 2.11),      .

   2.3   " (Calculator)"   "" (..   " (Calculator)"),          "   (Calculator with animation)",       (  )   .          (. 2.11).








. 2.11.

     ,     [].

,           .

,        ,      2.3    Me    Name  -   (Label1, Button1  ..),         .

 ,          Timer (),              .




2.8.       


           (    - ), ,    ,     ,       , ,   ..           .       ,      -         True  Enabled     False, ,       (      ).

 2.4.  ,  .

Timer1.Enabled = False

         ,          .   ,         :

 2.5.  ,  .

Timer1.Enabled = True

                  , , .      Form1  (  )   ,   Text  &Stop/Start Animation      .   Form1.vb     ,     ,     ,     .

 2.6.      .  1.

'   OffOn     False:

Dim OffOn As Boolean '= False  .

Private Sub Button2_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button2.Click

'     

'    Button:

If (OffOn = False) Then

' :

Timer1.Enabled = False

'  OffOn  :

OffOn = True

Else

' :

Timer1.Enabled = True

'  OffOn  :

OffOn = False

End If

End Sub

    :

 2.7.      .  2.

'   OffOn     True:

Dim OffOn As Boolean = True

Private Sub Button2_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button2.Click

OffOn = Not OffOn

Timer1.Enabled = OffOn

End Sub

     , , : Ctrl+F5.   Visual Basic        .

        500  ( 0,5 )   (Calculator)      (Calculator with animation) (. 2.11),      .

         (. 2.12).     Text   &Stop/Start Animation   &,    S , , ,       ,     Alt+s.

           Timer ()   ,          ,    .








. 2.12.




2.9.    


,           ,         .      ,      -         Beep().

     Beep()      Tick ,          Tick      Interval.         N,       (, , , 10)   N:

Dim N As Integer = 10

         i:

Static i As Integer

i = i + 1

If i <= N Then

Beep()

End If

            , ,          (   ).

    (     [] )         ,              .

    ,    ()                (  )   Visual Basic   ,    (  )   ( ) ,            .

         -   ,    ( )               .




 3.              





3.1.      


   . ,                     ,      (      )         ,       .                        .     (,  )      ,      , ,   .

    :   () :     ;      ;      ;     (   )   OK,         .  ()            (          ,   );   ,      .

,    (      []),      -.  VS   New Project (  File, New, Project).   New Projects   Project Types    Visual Basic, Windows,   Templates ,   ( ) Windows Forms Application,   Name   , , Calculator2_2 (  2    ,    2    ). ٸ OK.   Visual Basic           Form1(    ).         (. 3.1)     (  GroupBox,  TextBox,  Button,  Label)    (  Timer: Enabled  True;  Interval, ,   ,  100).








. 3.1. Form1   .




3.2.   


     ,   Project  Add Windows Form,   Add New Item   Add ( Open).   Visual Basic       Form2     Solution Explorer   Form2.vb. ,  ,    (. 3.2).         ,      .








. 3.2. Form2   .




3.3.  


   =   Form1   .   (   )    .

 3.1.  Button1_Click      .

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click

Dim A, B As Double

A = Convert.ToDouble(TextBox1.Text)

B = Convert.ToDouble(TextBox2.Text)

Dim myForm2 As New Form2

myForm2.C = A

myForm2.D = B

myForm2.Show()

End Sub

   OK  Form2.         C  D,       ,       .

 3.2.    Button1_Click     Form2.

Public C, D As Double

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click

Dim F, G As Double

F = C : G = D

TextBox1.Text = F.ToString

TextBox2.Text = G.ToString

TextBox3.Text = (F * G).ToString

End Sub

  ,  A  B, , ,   C  D,   ,    ,       TextBox,         .  F, G    (    )     C, D. ,              ,         ( 3.1  3.2),   .           [].




3.4.       


                     ,    ,    -  .         ,  :       ;       .          :    ,     (  )      Properties   Interval;       ,    ()   .           Timer      .   Form1.vb    Timer1_Tick    Tick,  (  )   () Timer.        .       ,      .

 3.3.       .

'  :

Dim myString As String = "2_2 (Calculator2_2) "

'  ,    :

Static i As Integer

'     :

Me.Text = myString.Substring(0, i)

i = i + 1

'   :

If i = myString.Length Then i = 1

          ( ):    ;    ,     (  )      Properties   Interval;              ()   .      Timer     .   Form1.vb  ,    :

 3.4.       .

'  :

Dim myString As String = _

"2_2 (Calculator2_2). 2 (Form2) "

' ,    :

Static i As Integer = myString.Length()

'     :

Me.Text = myString.Substring(0, i)

i = i  1

'    :

If i = -1 Then i = myString.Length()

      -   (   ),    3.3  3.4   (Me.Text = myString.Substring(0, i)   (Me.)       ( Name), , (Button1.)  .




3.5.  


      ()   -, ,     :

1.  : Build, Build Selection; Debug, Start Without Debugging.

  Visual Basic               .         .

2.       (. 3.1).

3. ٸ   ,       =.

   (. 3.2)   .         .

4.      OK.

  Visual Basic     (. 3.2):

      ;

      ;

       .

     x (Close).   Visual Basic   ,     .                .

                .

1. ٸ     ( ),   ( )   (,   )    =.

       .

2. ٸ OK          .

          .      (     )  .

      x (Close)   ,     ( ) .

 ,           .

     ( )      -        ,     ,     ,       .

      ,            Windows,   -   :          (    ,    );       ,     ;      ,        ,     ;    (       ) ,      .  ,     ,              .

    (  )      (, )                 ,     .

   ,   ,        ,            Visual Studio   ,      DirectX,   .




 II.         





 4.      





4.1.     


         ,         ,     microsoft.com: Rob Miles. Games Programming with Cheese: Part One.          Visual C#   ,   ,     Visual Studio,             ,   ,  Visual Basic     Visual Studio.           .        (  )             (arcade).   ,   , , , -  , ,    (cheese).          ,        , , 25 x 32 .       ,    -  , , Paint,       Windows.

   , ,       ,    ,      .

      : VS   New Project   Project types    Visual Basic, Windows,   Templates   Windows Forms Application,   Name  (   )  , , Cheese1   OK.  , ,  ,      ,          ,    Name    .  ,   Form1 (. 4.1)   .  (   ) ,        . ,          ,    Properties ( Form1)   BackColor   Window.

   (      )    cheese.jpg   ,  :  Project  Add Existing Item,      Files of type  All Files,            Add (     ).

  Solution Explorer     (. 4.2).

    cheese.jpg          ,  :  Solution Explorer     ,    Properties (  )   Build Action (  )      Content ()  None   Embedded Resource ( ).   ,     Form1.vb    System.Reflection    Assembly:

Imports System.Reflection '  Assembly.

  Properties ( Form1)   Events      Paint.    Form1_Paint       .

   , ,    PictureBox     -       .








. 4.1. .















. 4.2.    SE  Properties.

 4.1.    .

'   System.Drawing.Image  :

Dim cheeseImage As Image

'         :

'  myAssembly  Assembly   

'     :

Dim myAssembly As Assembly = Assembly.GetExecutingAssembly()

'  myAssemblyName

' System.Reflection.AssemblyName   

' ,     ,

'Version, Culture, PublicKeyToken:

Dim myAssemblyName As AssemblyName = myAssembly.GetName()

'      Name

'    string:

Dim myName_of_project As String = myAssemblyName.Name

Private Sub Form1_Paint(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.PaintEventArgs) _

Handles MyBase.Paint

'    System.Drawing.Image

'      

'     (ResourceStream):

cheeseImage = _

New Bitmap(myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "cheese.JPG"))

'    Form1:

e.Graphics.DrawImage(cheeseImage, 10, 20)

End Sub

       :

Build, Build Selection;

Debug, Start Without Debugging.

  VS   Deploy (  ),     (Device)  Windows Mobile 6 Classic ( Professional) Emulator    Deploy.

  Form1        cheese.jpg (. 4.1).

           (   )           (e.Graphics.DrawImage(myBitmap, 10, 20)).




4.2.   


      .     ,         .      ,    ().

     updatePositions,   .            (   x  y).  ,    ( )   .

 4.2.   .

'  :

Dim cx As Integer = 50

'  :

Dim cy As Integer = 100

Private Sub updatePositions()

cx = cx + 1

cy = cy + 1

End Sub

,     cx  cy,    .         ,    ,       .

  ,    updatePositions    ,   .    Toolbox     Timer ().   Properties (   Timer)   Enabled    False,   Interval   40 (,   25       ; 1000   1 ).

 ,      Timer () ,      ,      ,      .     Properties (   Timer)   Enabled     False.

 ,     ,     .      Form1_Paint     :

' :

Timer1.Enabled = True

,     Form1_Paint    .

 4.3.    .

Private Sub Form1_Paint(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.PaintEventArgs) _

Handles MyBase.Paint

'    System.Drawing.Image

'      

'     (ResourceStream):

cheeseImage = _

New Bitmap(myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "cheese.JPG"))

'    Form1:

e.Graphics.DrawImage(cheeseImage, cx, cy)

' :

Timer1.Enabled = True

End Sub

  ,    Form1_Paint,         cx  cy.

      Timer (    ).    timer1_Tick,      updatePositions    Invalidate ( Refresh)        .

 4.4.         .

Private Sub Timer1_Tick(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Timer1.Tick

' :

updatePositions()

' :

Invalidate()

End Sub

       : Build, Build Selection; Debug, Start Without Debugging.   VS   Deploy (  ),     (Device)  Windows Mobile 6 Classic ( Professional) Emulator    Deploy.     ,   Form1        cheese.jpg          (   )   (. 4.3).

  ,        .

 ,    ,         .








. 4.3.      .








. 4.4.  .




4.3.      


            , ,   .        , :

 ,    ,        - ;        ,     ;

,    , ,  ,            ,     .

              .

     ,     :

  , ..         x, y;       cheese.jpg,       ;

   x, y         ;        ;

     x, y     (),                   ,        ;

  ,        ()   ;

    ,      , ,               ;             45 ;

      ,       Timer ();

      Interval  Timer;            Interval;

   (    )  ;         .

         (  ) ,  ,               ,        .

 ,       updatePositions   .

 4.5.    .

'   "x"  (Right):

Dim goingRight As Boolean = True

'   "y"  (Down):

Dim goingDown As Boolean = True

Private Sub updatePositions()

If (goingRight) Then

cx = cx + 1

Else

cx = cx  1

End If

If ((cx + cheeseImage.Width) >= _

Me.ClientSize.Width) Then

goingRight = False

End If

If (cx <= 0) Then

goingRight = True

End If

If (goingDown) Then

cy = cy + 1

Else

cy = cy  1

End If

If ((cy + cheeseImage.Height) >= _

Me.ClientSize.Height) Then

goingDown = False

End If

If (cy <= 0) Then

goingDown = True

End If

End Sub

   ,    x, y    +1,        x, y (  ),     -1,        x, y (  ).

       (cheeseImage.Width  cheeseImage.Height)   Me.ClientSize.Width  Me.ClientSize.Height).              .

   (Build, Build Selection; Debug, Start Without Debugging)  ,    Form1       cheese.jpg      ,     (. 4.4).

        .




4.4.         


       .   , , 100 ,    25             4 .        ,      1    Interval   ,     xSpeed,       Interval   ,     :

If (goingRight) Then

cx += xSpeed

Else

cx -= xSpeed

End If

  xSpeed,       (  x)  .

     y      :

If (goingDown) Then

cy += ySpeed

Else

cy -= ySpeed

End If

          change   :

Private Sub changeSpeed(ByVal change As Integer)

xSpeed += change

ySpeed += change

End Sub

     change      changeSpeed.    change      Interval    ,  ,  ,   .

         , ,        (   ),    .            Visual C#  ()    ,         , ,  Visual Basic.     Project   Add Reference,   Add Reference   (.NET)   Microsoft.VisualBasic    OK.    , , updatePositions  :

Microsoft.VisualBasic.Interaction.Beep();

  ,     .

         Visual Basic,       Microsoft.VisualBasic,      ( ):

Beep()

  ,     .

 ,       updatePositions   .

 4.6.    .

'     "x":

Dim xSpeed As Integer = 1

'     "y":

Dim ySpeed As Integer = 1

'    :

Private Sub changeSpeed(ByVal change As Integer)

xSpeed += change

ySpeed += change

End Sub

'    :

Private Sub updatePositions()

If (goingRight) Then

cx += xSpeed

Else

cx -= xSpeed

End If

If ((cx + cheeseImage.Width) >= _

Me.ClientSize.Width) Then

goingRight = False

'      Beep:

Beep()

End If

If (cx <= 0) Then

goingRight = True

'      Beep:

Beep()

End If

If (goingDown) Then

cy += ySpeed

Else

cy -= ySpeed

End If

If ((cy + cheeseImage.Height) >= _

Me.ClientSize.Height) Then

goingDown = False

'      Beep:

Beep()

End If

If (cy <= 0) Then

goingDown = True

'      Beep:

Beep()

End If

End Sub

      -    , ,    Button ().    Toolbox      Button    Properties   Text     ,      . ,       Button (   )         .

        .

       (changeSpeed(1))   .

 4.7.     .

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click

changeSpeed(1)

End Sub

      .        (changeSpeed(-1))   .

 4.8.     .

Private Sub Button2_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button2.Click

changeSpeed(-1)

End Sub

   (Build, Build Selection; Debug, Start Without Debugging)  ,    Form1       cheese.jpg     (. 4.5  4.6),    ,              .

,            Beep.








. 4.5.  .








. 4.6.  .




4.5.      


,       cheese.jpg  ,    , ,      ,     .            (    ).

   (      )     bread.jpg   ,  :  Project  Add Existing Item,      Files of type  All Files,            Add (     ).   Solution Explorer    .

    bread.jpg          ,  :  Solution Explorer     ,    Properties (  )   Build Action (  )      Content ()  None   Embedded Resource ( ).

    breadImage ( Image)           bx  by    ,   ,          .        Form1_Paint   ,     .

 4.9.    .

'   System.Drawing.Image  :

Dim breadImage As Image ' =Nothing  .

'  :

Dim bx As Integer = 0

'  :

Dim by As Integer = 0

Private Sub Form1_Paint(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.PaintEventArgs) _

Handles MyBase.Paint

'    System.Drawing.Image

'      

'     (ResourceStream):

cheeseImage = _

New Bitmap(myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "cheese.JPG"))

breadImage = _

New Bitmap(myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "bread.JPG"))

'    Form1:

e.Graphics.DrawImage(cheeseImage, cx, cy)

e.Graphics.DrawImage(breadImage, bx, by)

' :

Timer1.Enabled = True

End Sub

   (Build, Build Selection; Debug, Start Without Debugging)  ,    Form1     cheese.jpg    bread.jpg (    ), . 4.7.    ,   ,       (  ).




4.6.        


         ,       ,     ,       ,        ,     .            ,           ,    .

       ,       Form1_Paint   ,      (  ).








. 4.7.     .








. 4.8.   .

 4.10.    .

'     Bitmap:

Dim backBuffer As Bitmap = Nothing

Private Sub Form1_Paint(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.PaintEventArgs) _

Handles MyBase.Paint

'    System.Drawing.Image

'      

'     (ResourceStream):

cheeseImage = _

New Bitmap(myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "cheese.JPG"))

breadImage = _

New Bitmap(myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "bread.JPG"))

' ,   :

If (backBuffer Is Nothing) Then

backBuffer = New Bitmap(Me.ClientSize.Width, _

Me.ClientSize.Height)

End If

Using g As Graphics = Graphics.FromImage(backBuffer)

' :

g.Clear(Color.White)

'    backBuffer:

g.DrawImage(breadImage, bx, by)

g.DrawImage(cheeseImage, cx, cy)

End Using

'    Form1:

e.Graphics.DrawImage(backBuffer, 0, 0)

' :

Timer1.Enabled = True

End Sub

      ,  ,   ,    .   ,     Form1_Paint   Windows      (background color),      (white),           .    ,    Windows   .          ,       OnPaintBackground,        ,     .

 4.11.  OnPaintBackground.

Protected Overrides Sub OnPaintBackground( _

ByVal e As System.Windows.Forms.PaintEventArgs)

'   (Background).

End Sub '  OnPaintBackground.

  OnPaintBackground      Form1_Paint, ,    Form1.

    (Build, Build Selection; Debug, Start Without Debugging)        ,     .

        (. 4.8),         ,     ,               .         .




4.7.           


       ,      ,      .     (Up),  (Down),  (Left)   (Right)            Toolbox, , ,    .  ,      Button      Text    , ,    (. 4.9).   ,   Form1   Properties    Size, ,  384; 473.

  ,     ,   ,   ,           .         ,    Properties   Events      MouseMove.              .








. 4.9.      .








. 4.10.   .

 4.12.    .

Private Sub Button3_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button3.Click

'  :

by -= ySpeed

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button4.Click

'  :

by += ySpeed

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button5.Click

'  :

bx -= xSpeed

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button6.Click

'  :

bx += xSpeed

End Sub



Private Sub Form1_MouseMove(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.MouseEventArgs) _

Handles MyBase.MouseMove

'     :

Dim mouseX As Integer = e.X

Dim mouseY As Integer = e.Y

'  ,   :

bx = mouseX

by = mouseY

End Sub

 ,       (,

Dim bx As Integer = 150 : Dim by As Integer = 200)

   .

   (Build, Build Selection; Debug, Start Without Debugging)   (  )   ,      .

      , ,                (. 4.9).

 . 4.9 ,         Button (     (Focus) ),          ,    Enter,         .   ,      , ,   Button,   - , ,   Form1_Paint     (button2.Focus();).       , ,     Tab     ,        Enter.

  ,      ,   ,   ,            .

,       (   )    , ,  Button  .

,    MouseMove,      -   ,     Properties   Events   Form1 (. 4.11).








. 4.11.    .

,       Button (   )           .

        (. 4.10),    , ,     ,     ,               .          (  ).

 ,        :

   ;

 ;

      , , ;

   ;

       , ,      ;

     (      );

      ;

      .

        .




 5.   ,       





5.1.  ,   


        ,         ,      microsoft.com: Rob Miles. Games Programming with Cheese: Part Two.          Visual C# ,  ,    Visual Studio,           Visual Basic ,  ,    Visual Studio.           .

              .

         ,    . ,    , ..     ,   .       ,         .

,      bread.jpg,   . 5.1.








. 5.1. ,   .

             ,              .      x, y       ,      (bx, by)     (bx + batWidth, by + batHeight)      .

   .NET Framework (  )   Rectangle (   System.Drawing),   - Rectangle Constructor   .    - Rectangle Constructor (      )   (Int32, Int32, Int32, Int32)  Rectangle   (  )    . 5.1.

 5.1.

- Rectangle Constructor (Int32, Int32, Int32, Int32)  Rectangle.

Visual Basic (Declaration)

Public Sub New ( _

x As Integer, _

y As Integer, _

width As Integer, _

height As Integer _

)

Visual Basic (Usage)

Dim x As Integer

Dim y As Integer

Dim width As Integer

Dim height As Integer

Dim instance As New Rectangle(x, y, width, height)

C#

public Rectangle (

int x,

int y,

int width,

int height

)

C++

public:

Rectangle (

int x,

int y,

int width,

int height

)

J#

public Rectangle (

int x,

int y,

int width,

int height

)

JScript

public function Rectangle (

x : int,

y : int,

width : int,

height : int

)

   - Rectangle Constructor   :

x   x    ;

y   y    ;

width   (  x) ;

height   (  y) .

       ,   ,   , , :

',    :

Dim cheeseRectangle As Rectangle

',    :

Dim breadRectangle As Rectangle

   -   (    new)    -, , :

cheeseRectangle = New Rectangle(cx, cy, _

cheeseImage.Width, cheeseImage.Height)

breadRectangle = New Rectangle(bx, by, _

breadImage.Width, breadImage.Height)




5.2.   ,    




   Rectangle (   System.Drawing)  ,       .   ,        ,   ,           ,     ,    .

       - .  -   Rectangle,        Intersect  IntersectsWith (. 5.2)     .






. 5.2.    Intersect  IntersectsWith.

     IntersectsWith (      )   (Rectangle rect)  Rectangle   (  )    . 5.2.

 5.2.

  Rectangle.IntersectsWith  Rectangle.

Visual Basic (Declaration)

Public Function IntersectsWith ( _

rect As Rectangle _

) As Boolean

Visual Basic (Usage)

Dim instance As Rectangle

Dim rect As Rectangle

Dim returnValue As Boolean

returnValue = instance.IntersectsWith(rect)

C#

public bool IntersectsWith (

Rectangle rect

)

C++

public:

bool IntersectsWith (

Rectangle rect

)

J#

public boolean IntersectsWith (

Rectangle rect

)

JScript

public function IntersectsWith (

rect : Rectangle

) : Boolean

  IntersectsWith         ,     rect.

  ,           ,      False.

   ,           ,   IntersectsWith    True,         -    (    ), ,   :

'  :

If (cheeseRectangle.IntersectsWith(breadRectangle)) Then

'    :

goingDown = Not goingDown

'      Beep:

Beep()

End If




5.3.    




  ,        (    )   ,        Form1_Paint   ,      (  ).

 5.1.    .

',    :

Dim cheeseRectangle As Rectangle

',    :

Dim breadRectangle As Rectangle

Private Sub Form1_Paint(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.PaintEventArgs) _

Handles MyBase.Paint

'    System.Drawing.Image

'      

'     (ResourceStream):

cheeseImage = _

New Bitmap(myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "cheese.JPG"))

breadImage = _

New Bitmap(myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "bread.JPG"))

' ,   :

cheeseRectangle = New Rectangle(cx, cy, _

cheeseImage.Width, cheeseImage.Height)

breadRectangle = New Rectangle(bx, by, _

breadImage.Width, breadImage.Height)

' ,   :

If (backBuffer Is Nothing) Then

backBuffer = New Bitmap(Me.ClientSize.Width, _

Me.ClientSize.Height)

End If

'   Graphics  :

Using g As Graphics = Graphics.FromImage(backBuffer)

' :

g.Clear(Color.White)

'    backBuffer:

g.DrawImage(cheeseImage, cx, cy)

g.DrawImage(breadImage, bx, by)

End Using

'    Form1:

e.Graphics.DrawImage(backBuffer, 0, 0)

' :

Timer1.Enabled = True

End Sub

     updatePositions      ,      .

 5.2.        .

Sub updatePositions()

If (goingRight) Then

cx += xSpeed

Else

cx -= xSpeed

End If

If ((cx + cheeseImage.Width) >= Me.ClientSize.Width) Then

goingRight = False

'      Beep:

Beep()

End If

If (cx <= 0) Then

goingRight = True

'      Beep:

Beep()

End If

If (goingDown) Then

cy += ySpeed

Else

cy -= ySpeed

End If

If ((cy + cheeseImage.Height) >= Me.ClientSize.Height) Then

goingDown = False

'      Beep:

Beep()

End If

If (cy <= 0) Then

goingDown = True

'      Beep:

Beep()

End If

'   :

cheeseRectangle.X = cx

cheeseRectangle.Y = cy

breadRectangle.X = bx

breadRectangle.Y = by

'  :

If (cheeseRectangle.IntersectsWith(breadRectangle)) Then

'    :

goingDown = Not goingDown

'      Beep:

Beep()

End If

End Sub

   (Build, Build Selection; Debug, Start Without Debugging)            ,  ,    ,   (. 5.3). , ,         45 ,        (   )   45 .




5.4.      




        ,             .        (  ),       .    ,     .

    ,   ,      ,   . 5.4.   1  3         45            .   2         90      .

     ,   ,      ,   . 5.5.








. 5.3.    .








. 5.4.   .


. 5.5.   .

  1  4          45            .   2  3         45 ,      ,    ,   .

     ,   . 5.5,        updatePositions      ,       .

 5.3.        .

Sub updatePositions()

If (goingRight) Then

cx += xSpeed

Else

cx -= xSpeed

End If

If ((cx + cheeseImage.Width) >= Me.ClientSize.Width) Then

goingRight = False

'      Beep:

Beep()

End If

If (cx <= 0) Then

goingRight = True

'      Beep:

Beep()

End If

If (goingDown) Then

cy += ySpeed

Else

cy -= ySpeed

End If

If ((cy + cheeseImage.Height) >= Me.ClientSize.Height) Then

goingDown = False

'      Beep:

Beep()

End If

If (cy <= 0) Then

goingDown = True

'      Beep:

Beep()

End If

'  :

If (goingDown) Then

'      :

If (cheeseRectangle.IntersectsWith(breadRectangle)) Then

'      Beep:

Beep()

'  :

Dim rightIn As Boolean = breadRectangle.Contains( _

cheeseRectangle.Right, _

cheeseRectangle.Bottom)

Dim leftIn As Boolean = breadRectangle.Contains( _

cheeseRectangle.Left, _

cheeseRectangle.Bottom)

' :

If (rightIn And leftIn) Then

' :

goingDown = False

Else

' :

goingDown = False

'  :

If (rightIn) Then

goingRight = False

End If

If (leftIn) Then

goingRight = True

End If

End If

End If

End If

End Sub

   (Build, Build Selection; Debug, Start Without Debugging)    Button         ,  ,         (  ),     ,       .    ,      .




5.5.   




             , ,  (tomatoes)    tomato.gif, . 5.6.








. 5.6.

.

    i-     tomatoes[i]          (. 5.7),          (. 5.8).

         IntersectWith.

      visible,     False ( : tomatoes(i).visible = False).

    Button     ,       ,         ,    .

    (      )    tomato.gif   ,  :  Project  Add Existing Item,      Files of type  All Files,            Add (     ).   Solution Explorer    .

    tomato.gif          ,  :  Solution Explorer     ,    Properties (  )   Build Action (  )       Embedded Resource ( ).




. 5.7.   .








. 5.8.       .

           ,   Form1     .

 5.4.      (tomatoes).

'   System.Drawing.Image  :

Dim tomatoImage As Image

'Position and state of tomato

Structure tomato

Public rectangle As Rectangle

Public visible As Boolean

End Structure

' Spacing between tomatoes. Set once for the game

Dim tomatoSpacing As Integer = 4

' Height at which the tomatoes are drawn. Will change

' as the game progresses. Starts at the top.

Dim tomatoDrawHeight As Integer = 4

' The number of tomatoes on the screen. Set at the start

' of the game by initialiseTomatoes.

Dim noOfTomatoes As Integer

' Positions of the tomato targets.

Dim tomatoes() As tomato

' called once to set up all the tomatoes.

Sub initialiseTomatoes()

noOfTomatoes = (Me.ClientSize.Width  tomatoSpacing) / _

(tomatoImage.Width + tomatoSpacing)

' create an array to hold the tomato positions

ReDim tomatoes(noOfTomatoes)

' xcoordinate of each potato

Dim tomatoX As Integer = tomatoSpacing / 2

Dim i As Integer

For i = 0 To tomatoes.Length  1

tomatoes(i).rectangle = _

New Rectangle(tomatoX, tomatoDrawHeight, _

tomatoImage.Width, tomatoImage.Height)

tomatoX = tomatoX + tomatoImage.Width + tomatoSpacing

Next

End Sub

' Called to place a row of tomatoes.

Sub placeTomatoes()

Dim i As Integer

For i = 0 To tomatoes.Length  1

tomatoes(i).rectangle.Y = tomatoDrawHeight

tomatoes(i).visible = True

Next

End Sub

      Form1_Paint   ,     .

 5.5.    .

Private Sub Form1_Paint(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.PaintEventArgs) _

Handles MyBase.Paint

' ,   :

If (backBuffer Is Nothing) Then

backBuffer = New Bitmap(Me.ClientSize.Width, _

Me.ClientSize.Height)

End If

'   Graphics  :

Using g As Graphics = Graphics.FromImage(backBuffer)

' :

g.Clear(Color.White)

'    backBuffer:

g.DrawImage(cheeseImage, cx, cy)

g.DrawImage(breadImage, bx, by)

Dim i As Integer

For i = 0 To tomatoes.Length  1

If (tomatoes(i).visible) Then

g.DrawImage(tomatoImage, _

tomatoes(i).rectangle.X, _

tomatoes(i).rectangle.Y)

End If

Next

End Using

'    Form1:

e.Graphics.DrawImage(backBuffer, 0, 0)

End Sub

       .   Properties ( Form1)   Events      Load.    Form1_Load       .

 5.6.    .

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

'    System.Drawing.Image

'      

'     (ResourceStream):

cheeseImage = _

New Bitmap(myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "cheese.JPG"))

breadImage = _

New Bitmap(myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "bread.JPG"))

' ,   :

cheeseRectangle = New Rectangle(cx, cy, _

cheeseImage.Width, cheeseImage.Height)

breadRectangle = New Rectangle(bx, by, _

breadImage.Width, breadImage.Height)

' :

tomatoImage = _

New Bitmap(myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "tomato.gif"))

'    :

initialiseTomatoes()

'     :

placeTomatoes()

' :

Timer1.Enabled = True

End Sub

 ,     updatePositions   ,      ,      .

 5.7.        .

Sub updatePositions()

If (goingRight) Then

cx += xSpeed

Else

cx -= xSpeed

End If

If ((cx + cheeseImage.Width) >= Me.ClientSize.Width) Then

goingRight = False

'      Beep:

Beep()

End If

If (cx <= 0) Then

goingRight = True

'      Beep:

Beep()

End If

If (goingDown) Then

cy += ySpeed

Else

cy -= ySpeed

End If

If ((cy + cheeseImage.Height) >= Me.ClientSize.Height) Then

goingDown = False

'      Beep:

Beep()

End If

If (cy <= 0) Then

goingDown = True

'      Beep:

Beep()

End If

'   :

cheeseRectangle.X = cx

cheeseRectangle.Y = cy

breadRectangle.X = bx

breadRectangle.Y = by

'     :

If (goingDown) Then

' only bounce if the cheese is going down

If (cheeseRectangle.IntersectsWith(breadRectangle)) Then

'      Beep:

Beep()

' we have a collision

Dim rightIn As Boolean = breadRectangle.Contains( _

cheeseRectangle.Right, _

cheeseRectangle.Bottom)

Dim leftIn As Boolean = breadRectangle.Contains( _

cheeseRectangle.Left, _

cheeseRectangle.Bottom)

' now deal with the bounce

If (rightIn And leftIn) Then

' bounce up

goingDown = False

Else

' bounce up

goingDown = False

' now sort out horizontal bounce

If (rightIn) Then

goingRight = False

End If

If (leftIn) Then

goingRight = True

End If

End If

End If

Else

' only destroy tomatoes of the cheese is going up

Dim i As Integer

For i = 0 To tomatoes.Length  1

If (Not tomatoes(i).visible) Then

Continue For

End If

If (cheeseRectangle.IntersectsWith( _

tomatoes(i).rectangle)) Then

'      Beep:

Beep()

' hide the tomato

tomatoes(i).visible = False

' bounce down

goingDown = True

' only destroy one at a time

'     ,

'   : Exit For:

Exit For

End If

Next

End If

End Sub '  updatePositions.

   (Build, Build Selection; Debug, Start Without Debugging)  i-          (. 5.7),         (. 5.8).

    Button     ,       ,         ,    .

         .




5.6.     




      ,         ,    ,    .             ( )   ,       , ,    -  .

   (score)        (scorer)       (,  DrawString)  :

g.DrawString(messageString, messageFont, messageBrush,

messageRectangle)

,     DrawString        messageFont,  messageBrush       messageRectangle,         .  . 5.9   20   2  ,   5.10  50   5  .

          , , 10   :

scoreValue = scoreValue + 10

      ,  .

             .

      ,       ,   4  , , , 20:

Dim tomatoDrawHeight As Integer = 20

    Form1      .








. 5.9.  20   2  .








. 5.10.  50 .

 5.8.  .

' Font for score messages.

Dim messageFont As Font = Nothing

' Rectangle for score display.

Dim messageRectangle As Rectangle

' Height of the score panel.

Dim scoreHeight As Integer = 20 '=   tomatoDrawHeight.

' Brush used to draw the messages.

Dim messageBrush As SolidBrush

' The string which is drawn as the user message.

Dim messageString As String = ": 0"

' Score in a game.

Dim scoreValue As Integer = 0

      Form1_Paint   ,     .

 5.9.    .

Private Sub Form1_Paint(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.PaintEventArgs) _

Handles MyBase.Paint

'  ,   :

If (backBuffer Is Nothing) Then

backBuffer = New Bitmap(Me.ClientSize.Width, _

Me.ClientSize.Height)

End If

'   Graphics  :

Using g As Graphics = Graphics.FromImage(backBuffer)

' :

g.Clear(Color.White)

'     backBuffer:

g.DrawImage(cheeseImage, cx, cy)

g.DrawImage(breadImage, bx, by)

Dim i As Integer

For i = 0 To tomatoes.Length  1

If (tomatoes(i).visible) Then

g.DrawImage(tomatoImage, _

tomatoes(i).rectangle.X, _

tomatoes(i).rectangle.Y)

End If

Next

'  :

g.DrawString(messageString, messageFont, _

messageBrush, messageRectangle)

End Using

'    Form1:

e.Graphics.DrawImage(backBuffer, 0, 0)

End Sub

      Form1_Load (     )   ,     .

 5.10.     .

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

'    System.Drawing.Image

'      

'     (ResourceStream):

cheeseImage = _

New Bitmap(myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "cheese.JPG"))

breadImage = _

New Bitmap(myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "bread.JPG"))

' ,   :

cheeseRectangle = New Rectangle(cx, cy, _

cheeseImage.Width, cheeseImage.Height)

breadRectangle = New Rectangle(bx, by, _

breadImage.Width, breadImage.Height)

'    :

tomatoImage = _

New Bitmap(myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "tomato.gif"))

'     ,

'   :

initialiseTomatoes()

'      :

placeTomatoes()

'      :

messageFont = New Font(FontFamily.GenericSansSerif, 10, _

FontStyle.Regular)

'      :

messageRectangle = New Rectangle(0, 0, _

Me.ClientSize.Width, scoreHeight)

'     :

messageBrush = New SolidBrush(Color.Black)

' :

Timer1.Enabled = True

End Sub

 ,     updatePositions   ,      ,   ,     .

 5.11.        .

Sub updatePositions()

If (goingRight) Then

cx += xSpeed

Else

cx -= xSpeed

End If

If ((cx + cheeseImage.Width) >= Me.ClientSize.Width) Then

goingRight = False

'      Beep:

Beep()

End If

If (cx <= 0) Then

goingRight = True

'      Beep:

Beep()

End If

If (goingDown) Then

cy += ySpeed

Else

cy -= ySpeed

End If

If ((cy + cheeseImage.Height) >= Me.ClientSize.Height) Then

goingDown = False

'      Beep:

Beep()

End If

If (cy <= 0) Then

goingDown = True

'      Beep:

Beep()

End If

'   :

cheeseRectangle.X = cx

cheeseRectangle.Y = cy

breadRectangle.X = bx

breadRectangle.Y = by

' check for collisions.

If (goingDown) Then

' only bounce if the cheese is going down

If (cheeseRectangle.IntersectsWith(breadRectangle)) Then

'      Beep:

Beep()

' we have a collision

Dim rightIn As Boolean = breadRectangle.Contains( _

cheeseRectangle.Right, _

cheeseRectangle.Bottom)

Dim leftIn As Boolean = breadRectangle.Contains( _

cheeseRectangle.Left, _

cheeseRectangle.Bottom)

' now deal with the bounce

If (rightIn And leftIn) Then

' bounce up

goingDown = False

Else

' bounce up

goingDown = False

' now sort out horizontal bounce

If (rightIn) Then

goingRight = False

End If

If (leftIn) Then

goingRight = True

End If

End If

End If

Else

' only destroy tomatoes of the cheese is going up

Dim i As Integer

For i = 0 To tomatoes.Length  1

If (Not tomatoes(i).visible) Then

Continue For

End If

If (cheeseRectangle.IntersectsWith( _

tomatoes(i).rectangle)) Then

'     Beep:

Beep()

' hide the tomato

tomatoes(i).visible = False

' bounce down

goingDown = True

' update the score

scoreValue = scoreValue + 10

'  scoreValue   String

'   :

messageString = ": " & _

Convert.ToString(scoreValue)

' only destroy one at a time

'     ,

'   : Exit For:

Exit For

End If

Next

End If

End Sub '  updatePositions.

   (Build, Build Selection; Debug, Start Without Debugging),       ,  Button  ,   20   2   (. 5.9)  50   5   (. 5.10).

,          Button (    Form1)          .

,        ,       .




 6.    





6.1.     


                 Beep (-: ). ,    ,      : Beep().       ,     Beep    , ,        (   )    .

               Beep               . , -        Beep       (     Beep).

           ,       :

        My.

       .

      DirectX.

         ,     ,     .




6.2.         My


          ,                My (    DirectX,    (Embedded) ).      ,  ,   .

    VS   New Project ( File, New, Project).   New Project   Project Types    Visual Basic, Windows,   Templates   Windows Forms Application,   Name    , , Sounds2   OK.  ,   Form1 (. 6.1)   .








. 6.1.

 Form1   .

 (   )  ,       . ,   Properties   Font            (Size).    ,   Properties   Text  (    :  , Paste) .

   Toolbox   ,  ,   Button (Sound 1  Sound 2).   Properties   Text     Sound&1  Sound&2   &,       ,        ,  ,    Alt,          (, Alt+1).

         .    ,           (     ,    Enter),    Properties ( Form1)   AcceptButton    .

  1,     drumpad-crash.wav  ,   Project  Add Existing Item,   Add Existing Item   Files of type  All Files,   "Look in"  (    C, WINDOWS, Media        )     Add (     ).       Solution Explorer.        drumpad-crash.wav,    Windows Media Player,                   .

      drumpad-bass_drum.wav   .

        ,          .

 ,    ,        ,       , , Sounds,     ,    , , D.

   Properties (  Form1)   Events      Load ().

  Form1.vb    Form1_Load,        .

 6.1.       .

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

'    (.wav)

' 1-    :

My.Computer.Audio.Play("..\..\drumpad-crash.wav")



'    (.wav)

' 2-    :

'My.Computer.Audio.Play( _

'"D:\MyDocs\Sounds\drumpad-bass_drum.wav")

End Sub

,   :

My.Computer.Audio.Play("..\..\drumpad-crash.wav")

    My,  Computer,  Audio   Play (. 6.2).

 ..\..\  relative path    () .








. 6.2.    Play.

   (Build, Build Selection; Debug, Start Without Debugging)    ()   ,       (     Sounds ).

      Form1_Load     ,   :

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

My.Computer.Audio.Play("..\..\drumpad-crash.wav")

My.Computer.Audio.Play("..\..\drumpad-bass_drum.wav")

End Sub

         .

       ,     ,     Play       WaitToComplete    AudioPlayMode,     .

 6.2.       .

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

My.Computer.Audio.Play("..\..\drumpad-crash.wav", _

AudioPlayMode.WaitToComplete)

My.Computer.Audio.Play("..\..\drumpad-bass_drum.wav")

End Sub

 .         ,     Play          WaitToComplete    AudioPlayMode,     .

 6.3.       .

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

My.Computer.Audio.Play("..\..\drumpad-crash.wav", _

AudioPlayMode.WaitToComplete)

End Sub

     (Loop)   ,     Play       BackgroundLoop    AudioPlayMode,     .

 6.4.       .

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

My.Computer.Audio.Play("..\..\drumpad-crash.wav", _

AudioPlayMode.BackgroundLoop)

End Sub

  (Stop)  ,     , ,      :

My.Computer.Audio.Stop()

     .

      ,         , , Sounds.      ,   Solution Explorer (. 6.3)      ,     Add, New Folder,            Enter.








. 6.3.  Sounds   Solution Explorer.

    (,  )      ,  :       ,     Add, Existing Item,   Add Existing Item   Files of type  All Files,            Add (     ).   Solution Explorer    .

    Sounds     .

,          ,     (      ,      Shift      ,      Ctrl        ).

,         Sound  ,    .

 6.5.       .

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

My.Computer.Audio.Play("..\..\Sounds\drumpad-crash.wav", _

AudioPlayMode.WaitToComplete)

End Sub

     :

My.Computer.Audio.Play("..\..\drumpad-crash.wav")

   Form1_Load,    ,    .

 , ,        Button,     .        (   Properties        Events      Click).   Form1.vb   (    ),         .

 6.6.   .

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click

'    (.wav)

' 1-    :

My.Computer.Audio.Play("..\..\drumpad-crash.wav", _

AudioPlayMode.BackgroundLoop)



'    (.wav)

' 2-    :

'My.Computer.Audio.Play( _

'"D:\MyDocs\Sounds\drumpad-bass_drum.wav")

End Sub

       (   Properties        Events      Click).   Form1.vb   (    ),         .

 6.7.   .

Private Sub Button2_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button2.Click

'    (.wav)

' 1-    :

My.Computer.Audio.Play("..\..\drumpad-bass_drum.wav")

'    (.wav)

' 2-    :

'My.Computer.Audio.Play( _

'"D:\MyDocs\Sounds\drumpad-crash.wav")

End Sub

   (Build, Build Selection; Debug, Start Without Debugging),  ,    (  )   ,     .  ,       :

My.Computer.Audio.Play("..\..\drumpad-crash.wav", _

AudioPlayMode.BackgroundLoop)

    (Loop)    drumpad-crash.wav           .          :

My.Computer.Audio.Play("..\..\drumpad-bass_drum.wav")

       drumpad-bass_drum.wav    .      ,              .

   ,       ,       Button (   )    -                    ,    ,   ,       .

,            Button (    Form1)     ,      Toolbox    .




6.3.          My


               , ,  -    .                MenuStrip,         .    Toolbox      MenuStrip     (    ).   Form1     Type Here ( ),        (  ,     Properties   Text),  ,     : ,  1,  2, . 6.4.    Properties   Name       : Sounds, Sound1, Sound2.     1.

ٸ     1    Properties (  )   Checked   True (. 6.5),         .           (    ),   Properties      CheckOnClick    True.

      1 (  ).   Form1.vb     ,     ,     ,     .

 6.8.      .

'   OffOn    True:

Dim OffOn As Boolean = True

Private Sub Sound1ToolStripMenuItem_Click( _

ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles Sound1ToolStripMenuItem.Click

'   :

OffOn = Not OffOn

' Stop   Play  1:

If (OffOn = False) Then

My.Computer.Audio.Stop()

Else

My.Computer.Audio.Play("..\..\drumpad-crash.wav", _

AudioPlayMode.BackgroundLoop)

End If

End Sub








. 6.4.  MenuStrip.








. 6.5.   .

    (Build, Build Selection; Debug, Start Without Debugging),           1,     Stop    Play  (Loop)    ,     .

            ,   :

My.Computer.Audio.Play("..\..\drumpad-crash.wav", _

AudioPlayMode.BackgroundLoop)

:

My.Computer.Audio.Play("..\..\drumpad-crash.wav")

     2     .

           ,    MenuStrip            (  ).




6.4.        


       My        ( , , ,    ..)    Windows Mobile.

   .NET Framework   ,    .NET Compact Framework                (Embedded Resource)    Platform Invoke ( P/Invoke)     (dynamic link library) winmm.dll (  )  CoreDll.dll (  )     Windows API (Application Programming Interfaces).

          -  (  )        .

              Sound.vb,      Sound.

     ,          ,         .

   Sound  :

 ,      ;

  ;

 .

       Sound.       ,                filename   (Stream),     :

'    :

Private Sub readStream(ByVal soundStream As Stream)

'  soundBytes    Byte

'    

'    soundStream.Length:

soundBytes = New Byte(soundStream.Length) {}

'  soundStream   

'  soundBytes:

soundStream.Read(soundBytes, 0, soundStream.Length)

End Sub

' -  Sound

'     soundStream  Stream:

Public Sub New(ByVal soundStream As Stream)

'     :

readStream(soundStream)

End Sub

' -  Sound

'     filename   :

Public Sub New(ByVal filename As String)

Dim execAssem As System.Reflection.Assembly = _

System.Reflection.Assembly.GetExecutingAssembly()

Dim soundStream As Stream = _

execAssem.GetManifestResourceStream(filename)

If (soundStream Is Nothing) Then

System.Windows.Forms.MessageBox.Show( _

"Missing file : " +filename, "Audio Load")

Return

End If

readStream(soundStream)

End Sub

 readStream    .    .  Sound   Platform Invoke (P/Invoke),         ,     :

Public Enum Flags

SND_ALIAS = &H10000

SND_ALIAS_ID = &H110000

SND_FILENAME = &H20000

SND_RESOURCE = &H40004

SND_SYNC = &H0

SND_ASYNC = &H1

SND_NODEFAULT = &H2

SND_MEMORY = &H4

SND_LOOP = &H8

SND_NOSTOP = &H10

SND_NOWAIT = &H2000

SND_VALIDFLAGS = &H17201F

SND_RESERVED = &HFF000000

SND_TYPE_MASK = &H170007

End Enum

Private Declare Function PlaySound _

Lib "winmm.dll" Alias "PlaySound" (ByVal szSound() As Byte, _

ByVal hModule As IntPtr, ByVal dwFlags As Integer) As Integer

     (Flags)    .  Sound   ,           (  ).        ,   .  Sound   Play  PlayLoop       ,     :

'     :

Public Sub Play()

loopSound = Nothing

If (Sound.Enabled) Then

PlaySound(soundBytes, IntPtr.Zero, _

Fix(Flags.SND_ASYNC Or _

Flags.SND_MEMORY))

End If

End Sub

'     :

Public Sub PlayLoop()

loopSound = soundBytes

If (Sound.Enabled) Then

PlaySound(soundBytes, IntPtr.Zero, _

Fix(Flags.SND_ASYNC Or _

Flags.SND_MEMORY Or _

Flags.SND_LOOP))

End If

End Sub

 StopSound   Sound   ,   soundBytes   (Zero)  :

Public Sub StopSound()

If (Not loopSound Is Nothing) Then

PlaySound(Nothing, IntPtr.Zero, _

0)

End If

End Sub

 ResumeSound    ,      ,     :

Public Sub ResumeSound()

If (Not Sound.Enabled) Then

Return

End If

If (Not loopSound Is Nothing) Then

PlaySound( _

loopSound, _

IntPtr.Zero, _

Flags.SND_ASYNC Or Flags.SND_MEMORY Or _

Flags.SND_LOOP)

End If

End Sub

      .

 ,    ,        ,    (    )  Sound.vb,   Solution Explorer            Add, New Item.   Add New Item   Code File,   Name   Sound.vb    Add.

  (   Solution Explorer)   ,     ,     .

 6.9.  Sound.vb.

Imports System.IO '  Stream.

Public Class Sound

'    :

Public Shared Enabled As Boolean = True

'     :

Public Property EnabledProperty() As Boolean

Get

Return Enabled

End Get

Set(ByVal value As Boolean)

Enabled = value

If (value) Then

ResumeSound()

Else

StopSound()

End If

End Set

End Property

'   :

Private loopSound() As Byte = Nothing

'    :

Private soundBytes() As Byte



' ()   

'  Windows CE,  ,

' PlaySound   CoreDll.dll

'   :

Public Enum Flags

SND_ALIAS = &H10000

SND_ALIAS_ID = &H110000

SND_FILENAME = &H20000

SND_RESOURCE = &H40004

SND_SYNC = &H0

SND_ASYNC = &H1

SND_NODEFAULT = &H2

SND_MEMORY = &H4

SND_LOOP = &H8

SND_NOSTOP = &H10

SND_NOWAIT = &H2000

SND_VALIDFLAGS = &H17201F

SND_RESERVED = &HFF000000

SND_TYPE_MASK = &H170007

End Enum

'   System.Runtime.InteropServices

'  CoreDll.dll 

'  PlaySound  :

Private Declare Function PlaySound _

Lib "winmm.dll" Alias "PlaySound" (ByVal szSound() As Byte, _

ByVal hModule As IntPtr, ByVal dwFlags As Integer) As Integer

'    :

Private Sub readStream(ByVal soundStream As Stream)

'  soundBytes    Byte

'    

'    soundStream.Length:

soundBytes = New Byte(soundStream.Length) {}

'  soundStream   

'  soundBytes:

soundStream.Read(soundBytes, 0, soundStream.Length)

End Sub

' -  Sound

'     soundStream  Stream:

Public Sub New(ByVal soundStream As Stream)

'     :

readStream(soundStream)

End Sub

' -  Sound

'     filename   :

Public Sub New(ByVal filename As String)

Dim execAssem As System.Reflection.Assembly = _

System.Reflection.Assembly.GetExecutingAssembly()

Dim soundStream As Stream = _

execAssem.GetManifestResourceStream(filename)

If (soundStream Is Nothing) Then

System.Windows.Forms.MessageBox.Show( _

"Missing file : " +filename, "Audio Load")

Return

End If

readStream(soundStream)

End Sub

'     :

Public Sub Play()

loopSound = Nothing

If (Sound.Enabled) Then

PlaySound(soundBytes, IntPtr.Zero, _

Fix(Flags.SND_ASYNC Or _

Flags.SND_MEMORY))

End If

End Sub

'     :

Public Sub PlayLoop()

loopSound = soundBytes

If (Sound.Enabled) Then

PlaySound(soundBytes, IntPtr.Zero, _

Fix(Flags.SND_ASYNC Or _

Flags.SND_MEMORY Or _

Flags.SND_LOOP))

End If

End Sub

'    :

Public Sub StopSound()

If (Not loopSound Is Nothing) Then

PlaySound(Nothing, IntPtr.Zero, _

0)

End If

End Sub

'     :

Public Sub ResumeSound()

If (Not Sound.Enabled) Then

Return

End If

If (Not loopSound Is Nothing) Then

PlaySound( _

loopSound, _

IntPtr.Zero, _

Flags.SND_ASYNC Or Flags.SND_MEMORY Or _

Flags.SND_LOOP)

End If

End Sub

End Class

  Sound.vb           ,        Project, Add Existing Item,         .

    VS   New Project ( File, New, Project).   New Project   Project Types    Visual Basic, Windows,   Templates   Windows Forms Application,   Name    , , Sounds4   OK.  ,   Form1 (. 6.6)   .








. 6.6.  Form1   .

 (   )  ,       .

    move.wav  ,   Project  Add Existing Item,   Add Existing Item   Files of type  All Files,   "Look in"  (,       )     Add (     ).       Solution Explorer.

  Solution Explorer    ,    Properties (  )   Build Action (  )       Embedded Resource ( ).

        win.wav   .

          ,          .

  Form1.vb (, : File, Open, File)         :

Imports System.Reflection '  Assembly.

,       ,            System.Reflection.

   Properties (  Form1)   Events      Load ().

  Form1.vb    Form1_Load,        .

 6.10.       .

'   Sound    :

Dim moveSound As Sound

Dim winSound As Sound

'  myAssembly  System.Reflection.Assembly

'       :

Dim myAssembly As Assembly = Assembly.GetExecutingAssembly()

'  myAssemblyName

' System.Reflection.AssemblyName   

' ,     ,

'Version, Culture, PublicKeyToken:

Dim myAssemblyName As AssemblyName = myAssembly.GetName()

'      Name

'   myName_of_project  String:

Dim myName_of_project As String = myAssemblyName.Name

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

'  :

' 1:

'moveSound = _

' New Sound(myAssembly.GetManifestResourceStream( _

' myName_of_project + "." + "move.wav"))

winSound = _

New Sound(myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "win.wav"))

'  :

' 2:

'moveSound = New Sound(myName_of_project + "." + "move.wav")

'winSound = New Sound(myName_of_project + "." + "win.wav")

'  :

'moveSound.Play()

'  :

winSound.Play()

End Sub

   (Build, Build Selection; Debug, Start Without Debugging)    ()   ,       (     Sounds ).

  :

moveSound.Play()

winSound.Play()

       ,      .

  (Loop)      :

winSound.Play()

 :

winSound.PlayLoop()

  ,      .

 ,       ,         , , Sounds.      ,   Solution Explorer (. 6.7)      ,     Add, New Folder,            Enter.

    (,  )      ,  :       ,     Add, Existing Item,   Add Existing Item   Files of type  All Files,            Add (     ).   Solution Explorer    .








. 6.7.  Sounds   Solution Explorer.

  Solution Explorer    ,    Properties (  )   Build Action (  )       Embedded Resource ( ).

      Sounds          .

             ,     Sounds (  - ,   ).               ,      ,       Sounds.

 ,   ,       ,       Button (   )    -                    ,    ,   ,       .

,            Button (    Form1)     ,      Toolbox    .




6.5.         


               , ,  -    .

               MenuStrip,         .    Toolbox      MenuStrip     (    ).   Form1     Type Here ( ),        (  ,     Properties   Text),  ,     : ,  1,  2, . 6.8.    Properties   Name       : Sounds, Sound1, Sound2.     1.








. 6.8.  MenuStrip.

ٸ     1    Properties (  )   Checked   True,         .           (    ),   Properties      CheckOnClick    True.

      1 (  ).   Form1.vb     ,     ,     ,     .

 6.11.      .

'   OffOn    True:

Dim OffOn As Boolean = True

Private Sub Sound1ToolStripMenuItem_Click( _

ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles Sound1ToolStripMenuItem.Click

'   :

OffOn = Not OffOn

' Stop   Play  1:

If (OffOn = False) Then

winSound.StopSound()

Else

winSound.PlayLoop()

End If

End Sub

    (Build, Build Selection; Debug, Start Without Debugging),           1,     StopSound    PlayLoop  (Loop)    ,     .

            ,   :

winSound.PlayLoop()

 (    ):

winSound.Play()

     2     .            ,    MenuStrip            (  ).




6.6.        


         ,         ,    ,     .

        ,      Sound     (  ):

Dim moveSound As Sound

Dim winSound As Sound

    (array)  Byte     (  ):

Dim array_btSoundBounce() As Byte

Dim array_btSoundExplode() As Byte

      .

    VS   New Project ( File, New, Project).   New Project   Project Types    Visual Basic, Windows,   Templates   Windows Forms Application,   Name    , , Sounds6   OK.  ,   Form1 (. 6.9)   .








. 6.9.  Form1   .

 (   )  ,       .

    bounce.wav ( )  ,   Project  Add Existing Item,   Add Existing Item   Files of type  All Files,   "Look in"  (,       )     Add (     ).       Solution Explorer.

  Solution Explorer    ,    Properties (  )   Build Action (  )       Embedded Resource ( ).

        explode.wav  .           ,          .

  Form1.vb (, : File, Open, File)         :

Imports System.Reflection '  Assembly.

,       ,            System.Reflection.

   Properties (  Form1)   Events      Load ().

  Form1.vb    Form1_Load,        .

 6.12.       .

'   array  Byte

'   :

Dim array_btSoundBounce() As Byte

Dim array_btSoundExplode() As Byte

'         :

'  myAssembly  Assembly   

'     :

Dim myAssembly As Assembly = Assembly.GetExecutingAssembly()

'  myAssemblyName

' System.Reflection.AssemblyName   

' ,     ,

'Version, Culture, PublicKeyToken:

Dim myAssemblyName As AssemblyName = myAssembly.GetName()

'      Name

'    string:

Dim myName_of_project As String = myAssemblyName.Name

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

'    :

array_btSoundBounce = Sound.ReadBytesFromStream( _

myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "bounce.wav"))

array_btSoundExplode = Sound.ReadBytesFromStream( _

myAssembly.GetManifestResourceStream( _

myName_of_project + "." + "explode.wav"))

'      :

Sound.Play(array_btSoundBounce)

'   :

'Sound.Play(array_btSoundExplode)

End Sub

  Solution Explorer            Add, New Item ( Project, Add New Item).   Add New Item   Code File,   Name   Sound.vb    Add.

  (   Solution Explorer)   ,     ,     .

 6.13.  Sound.vb.

Imports System.IO '  Stream.

Public Class Sound

'     :

Const SND_SYNC = &H0

Const SND_ASYNC = &H1

Const SND_NODEFAULT = &H2

Const SND_MEMORY = &H4

Const SND_LOOP = &H8

Const SND_NOSTOP = &H10

'   System.Runtime.InteropServices

'  winmm.dll 

'  PlaySoundBytes  :

Private Declare Function PlaySoundBytes _

Lib "winmm.dll" Alias "PlaySound" (ByVal szSound() As Byte, _

ByVal hModule As IntPtr, ByVal dwFlags As Integer) As Integer

'    :

Public Shared Function ReadBytesFromStream( _

ByRef strBytes As Stream) As Byte()

Dim btRetVal() As Byte

btRetVal = New Byte(strBytes.Length) {}

strBytes.Read(btRetVal, 0, Fix(strBytes.Length))

Return btRetVal

End Function

'     :

Public Shared Sub Play(ByRef btBytes() As Byte)

PlaySoundBytes(btBytes, IntPtr.Zero, _

SND_ASYNC Or SND_MEMORY)

End Sub

End Class

  Sound.vb           ,        Project, Add Existing Item.

   (Build, Build Selection; Debug, Start Without Debugging)    ()   ,       ,      Sounds .




6.7.       DirectX


                 DirectX, ,   DirectSound      Microsoft.DirectX.DirectSound. ,       ,       ,             .

      ,  ,   .

    VS   New Project ( File, New, Project).   New Project   Project Types    Visual Basic, Windows,   Templates   Windows Forms Application,   Name       OK.  ,   Form1 (. 6.10)   .








. 6.10.  Form1   .

 (   )  ,       . ,   Properties   Font           (Size).    ,   Properties   Text  (    :  , Paste) .

   (  Toolbox),  ,   Button (Sound 1  Sound 2).   Properties   Text     Sound &1  Sound &2   &,       ,        ,  ,    Alt,          (, Alt+1).

         .    ,           (     ,    Enter),    Properties ( Form1)   AcceptButton    .

  1,     drumpad-crash.wav  ,   Project  Add Existing Item,   Add Existing Item   Files of type  All Files,   "Look in"  (    C, WINDOWS, Media , ,       )     Add (     ).       Solution Explorer.        drumpad-crash.wav,    Windows Media Player,                   .

      drumpad-bass_drum.wav   .

        ,          .

 ,    ,        ,       , , Sounds,     ,    , , D.

       DirectX,    .     Project  Add Reference,    Add Reference   (.NET)   Microsoft.DirectX.DirectSound   OK.    Add Reference     Microsoft.DirectX.DirectSound,       Microsoft     DirectX SDK      .

  Form1.vb (, : File, Open, File)           (     ):

Imports Microsoft.DirectX.DirectSound

,       ,            Microsoft.DirectX.DirectSound.

     Form1    (     )    DirectX.

 6.14.  .

' -     renderWindow

' Control    System.Windows.Forms:

Dim renderWindow As Control

'    :

' DeviceOfSound  Device  DirectSound:

Dim DeviceOfSound As Microsoft.DirectX.DirectSound.Device

'   SecondaryBuffer

'   -:

Dim mySound1 As SecondaryBuffer ' =Nothing  .

Dim mySound2 As SecondaryBuffer ' =Nothing  .

'    DirectX:

Public Function InitializeDirectX() As Boolean

Try

'renderWindow   this  ( -):

renderWindow = Me

'     :

' DeviceOfSound  Device  DirectSound:

DeviceOfSound = _

New Microsoft.DirectX.DirectSound.Device()

'      Normal:

DeviceOfSound.SetCooperativeLevel(renderWindow, _

CooperativeLevel.Normal)

' DirectX  :

Return True

Catch

'   DirectX:

Return False

End Try

End Function '  InitializeDirectX.

,                 (  ).

   Properties (  Form1))   Events      Load ().

  Form1.vb    Form1_Load,        .




  .


   .

   ,     (https://www.litres.ru/pages/biblio_book/?art=68870631)  .

      Visa, MasterCard, Maestro,    ,   ,     ,  PayPal, WebMoney, ., QIWI ,       .


