     .  1:  Visual C#  
  


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





     

 1:  Visual C#  



  



  ,2022



ISBN978-5-0056-6545-4 (. 1)

ISBN978-5-0056-6546-1

     Ridero







                        ,     ,       Visual C#       Microsoft ().

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

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

      ,     .         Visual C#      VC#.    ,       (      ZharkovPress.com    )   ,       .         ,           VC#,    ;       ,         Visual C#   . ʠ  ,      ,    ,   (   ,   ,      ),     ,    .        ,         .    .          (      ,   )   (: ,  )         VS. Ƞ           (   )       .              (   Help Visual Studio,  ,     ),     , ,    (   )  , , , , ,     (  )    .          VS  ( ),          ,     .

     .

     ,    Microsoft,     Microsof.                ,     .     ,       (     )  ,           ,            ,           () .

                   ,   ( )    Visual C#      ,                  .     ,   ,    , , , ,   .

    (     )       .

,       email:

valery-zharkov@mtu-net.ru

     :

www.ZharkovPress.com.

          ( ).




 I.   VisualC#





 1.   





1.1.  


  (computer game)        ,   .

   ,       (game program),         ,      .

     ,           ,      .  ,  ,  ,    .

               .

Ѡ       Microsoft Windows.

Ѡ          Microsoft Visual C#   Microsoft Visual Studio  .

Ѡ    ( )  .             DirectX.

,  ,   .

堖 ,     (   ,   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     [1]  ZharkovPress.com.

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

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

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

  ,   ZharkovPress.com        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,       .




 2.        





2.1.  - 


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

   (  )  :

1)  ,     (, ࠖ ,        Visual Studio),    ,      ,          (,     ) -  ()    VisualC#;

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




2.2.  


    -  ( )      .   ,  ,         ,           ().

   ( )  Visual C#   Visual Studio        .

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

2.   New Project (. 2.1)  Project types    Visual C#, Windows ,   Templates   ( , )  Templates, Visual C#, Windows Classic Desktop, Windows Forms App (.NET Framework);  Name   , , Calculator.

    Location    (    ),     .

     Location (  Browse)         ,        Create New Folder.

3.     (Solution)    ,         (  ),    (  )  Create directory for solution (. 2.1)    .








. 2.1.   Project Types    Visual C#, Windows.



4.  New Projects (. 2.1) OK.

Visual C#      Form1   (,   )  Form1.cs [Design],          (. 2.2).

5.  ,         ,       Visual Studio.      Visual Studio   :

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

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

     Output  Output (. 2.2)   C#     :



Compile complete 0errors, 0warnings

Calculator -> D:\MyDocs\DesktopProjects\DesktopProjects2\Calculator\bin\Debug\Calculator.exe

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













. 2.2.  Form1   (,   ).



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

  Form1      Form1  ,        .     Close ()        .

   Visual Studio ,      (   ).




2.3.   


  (       Toolbox, . 2.3)         .

1.  Properties ()   Form1 (. 2.4)    (   )    View, Properties Window       ,       .

  Properties   Form1,     ,         Properties.   Properties        Properties (  , ,   Events).   ( )             ;          Enter.

   ( )  ,      Form1.cs [Design]   Solution Explorer (- )    Form1.cs.

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

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

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

5.    BackColor (. 2.4)    (    Control)      Form1.       , , [9]. ,         .

6.    BackgroundImage (), . 2.4,         ( (.bmp), (.jpg), (.gif) .)    ,            ;         (, TextBox Button)  (, Timer),     , ,[9].

7. ,    Toolbox (. 2.3)    Windows Forms  .                GroupBox,        .     Toolbox (. 2.3)   GroupBox ( ).   .    groupBox1,  Properties  Text  groupBox1  (   :  , Paste), ,   (Addition ofnumbers);    Text (   Enter)   Properties      .

8.      TextBox (   );  Properties    textBox1;   ()  textBox1,  Properties  Text   (      Enter).

9.          .

10.    ,    ,      Label. ,   label1      ,   Properties  label1  Text  label1  (   :  , Paste), ,  1(number1).

11.       ,    蠖  +.

12.          =,      :  Toolbox  Button;  ;  button1      ,   Properties  Text  button1  (   :  , Paste), ,   =;    Text (   Enter).

  Form1  Class View    .      (. 2.6).

,        Visual Studio    ,         .

 ,   ,     ,        () Visual Studio.













. 2.3.   Toolbox. . 2.4.  Solution Explorer Properties.








. 2.5.   Font  .








. 2.6.    () .




2.4.  


  Form1.cs           .        ,             Events (  )  Properties (. 2.4). ,      = (. 2.6)       Click  Events  Properties.        ,                .  .   Form1.cs    :

		using System;
		using System.Collections.Generic;
		using System.ComponentModel;
		using System. Data;
		using System. Drawing;
		using System.Linq;
		using System. Text;
		using System.Threading. Tasks;
		using System.Windows.Forms;

		namespace Calculator
		{
		public partial class Form1:Form
		{
		public Form1()
		{
		InitializeComponent();

}

}

}



Ƞ  Form1.cs            :



private void button1_Click (object sender, EventArgse)

{



}



         (using System;),   System (  )      .

            .

     (  , , TextBox) ,   ( )      .



   :



 2.1.     .

		double a, b,c;
		a= Convert.ToDouble (textBox1.Text);
		b = Convert.ToDouble (textBox2.Text);
		c = a+b;

textBox3.Text = c.ToString();




   :


		double a,b;
		a= Convert.ToDouble (textBox1.Text);
		b = Convert.ToDouble (textBox2.Text);
		textBox3.Text = (a+ b).ToString();

   :

		doublea;
		a= Convert.ToDouble (textBox1.Text);
		textBox3.Text = (a+
		Convert.ToDouble(textBox2.Text)).ToString();

    :



textBox3.Text = (Convert.ToDouble (textBox1.Text)+

Convert.ToDouble(textBox2.Text)).ToString();



         .     (  , ,    )    [13].

   ( Build, Build Selection     )     Output   C#   ,   (        )       .   ,   ,   ,       .

  ,   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 C# ( ).




2.6.   


        .       , , ,  ( 2). ,       (  ,     ),        .     .     , ,   ( 3).    =   .2.8.








. 2.8.     .



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

           .



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-, - .

   ,        ,    ,  (   )        -        ,        ( )        .

    ,         Form1.




2.7.    


             , ,   ,            (  ).        .

       Timer :

1.   Toolbox   Timer (. 2.3).

2. ٸ .

 Form1    timer1 (. 2.9),       .

,             .

3.   Properties  timer1:

 Enabled  False  True (. 2.10);

 Interval    100 , ,  500 (,  1000  1).

,       Properties, , ,    .



 2.2.       .

		private void InitializeTimer()
		{
		//We turn on the timer:
		timer1.Enabled = true;
		//We generate the Tick event through each Interval oftime:
		timer1.Interval =500;

}













. 2.9.   Timer. . 2.10.  Properties.



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

,            .      .

, ,  :



1)   ,    ,   (, ,  ..)     Interval;

2)    ,    ,       Interval,      N_Interval;

3)    ,      ,         .



   ,        Interval.      timer1 (. 2.8)   (  Properties  Events      Tick).

  Form1.cs    ,     ,   .



 2.3.    . 1.



//We declare the Boolean myText variable and appropriateit

//false (bydefault too false):

bool myText = false;



private void timer1_Tick (object sender, EventArgse)

{

//We set the alternation ofCalculatorand

//" Calculator with animation:

if (myText == false)

{

this. Text = " Calculator;

//We change the myText value toopposite:

myText = true; //or so: myText =! myText;

}

else

{

this. Text = " Calculator with animation;

//We change the myText value toopposite:

myText = false; //or so: myText =! myText;

}

}



         .

   ,     ,    ,       Interval,      N_Interval.    Form1.cs   (  )      ,   ,    .



 2.4.    . 2.



//We declare the counter ofnumber ofintervals

//and set its initial value:

private int counter = 0; //bydefault too it is equal to0.

//We declare and set the number N_Interval ofintervals,

//after which one text is replaced byanother:

private int N_Interval =3;



private void timer1_Tick (object sender, EventArgse)

{

//We check, value ofthe counter

//equally or yet is not present tonumber N_Intervalof

//intervals,

//after which one text is replaced byanother:

if (counter> =N_Interval)

{

//If value ofthe counter collected and is equal

//N_Interval, we output other text:

this. Text = Calculator;

//We nullify the value ofthe counter again:

counter =0;

}

else

{

//If value ofthe counter did not collectyet

//and N_Interval is not equal,

//that we output the first text:

this. Text = Calculator with animation;

//We increase value ofthe counter on1:

counter = counter+1;

}

}



Ƞ,   ,     ,     N_Interval_Stop  ,         .    Form1.cs   (  )        ,     ,    .



 2.5.    . 3.



//We declare the counter ofnumber ofintervals

//and set its initial value:

private int counter =0;

//We declare and set the number N_Interval ofintervals,

//after which one text is replaced byanother:

private int N_Interval =3;

//We declare and nullify the i_Interval_Stop counter,

//which calculates the number ofintervals

//toan animation stop:

private int i_Interval_Stop =0;

//We declare and set the number N_Interval_Stop ofintervals,

//on reaching which animation stops:

private int N_Interval_Stop =10;



private void timer1_Tick (object sender, EventArgse)

{

//Value ofthe i_Interval_Stop counter,

//which calculates the number ofintervals

//toan animation stop, we increase on1:

i_Interval_Stop = i_Interval_Stop+1;

//We check the number i_Interval_Stop ofintervals,

//on reaching which animation stops:

if (i_Interval_Stop> =N_Interval_Stop)

timer1.Enabled = false;

//We check, value ofthe counter

//equally or yet is not present tonumber N_Intervalof

//intervals,

//after which one text is replaced byanother:

if (counter> =N_Interval)

{

//If value ofthe counter collected and is equal

//N_Interval, we output other text:

this. Text = Calculator;

//We nullify value ofthe counter again:

counter =0;

}

else

{

//If value ofthe counter did not collectyet

//and N_Interval is not equal,

//that we output the first text:

this. Text = Calculator with animation;

//We increase value ofthe counter on1:

counter = counter+1;

}

}



       timer1_Tick,     ,    .



   



private void timer1_Tick (object sender, EventArgse)



  ,   timer1_Tick  (Handles)  Tick,  (     Interval)   () timer1.   (bool myText = false;)      myText   timer1_Tick.   myText        timer1_Tick,      ( )   timer1_Tick   myText  ,  .

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

  Visual C#        .      500 ( 0,5)   (Calculator)   ࠫ  (Calculator with animation)  (. 2.10),     .








. 2.10.   .



  2.3 2.5   (Calculator)    (..    (Calculator)),           (Calculator with animation),      (  )  .         (. 2.10).

     ( 2.4)   ( 2.5);     . Ƞ      .    , ,  ,   .

,            . ,        ,      2.3 2.5   this    Name  -   (label1, button1 ..),          .



2.8.    



          (   - ), ,    ,   ,      , ,  ..          .     ,     -        true  Enabled     false, ,       (     ).



 2.6.  ,  .



timer1.Enabled = false;



        ,         .

  ,        :



 2.7.  ,  .



timer1.Enabled = true;



               , , .     Form1  (  )    Button,  Text  &Stop/Start Animation     (  Properties     Events     Click).   Form1.cs    ,     ,   ,    :



 2.8.     .



//We declare the Boolean OffOn variable and set it false:

bool OffOn = false;



private void button2_Click (object sender, EventArgse)

{

//We set alternation ofastop and resuming ofanimation

//after each click ofthe button2 button:

if (OffOn == false)

{

//We stop the animation:

timer1.Enabled = false;

//We change the OffOn value toopposite:

OffOn = true; //or so: OffOn =! OffOn;

}

else

{

//We resume the animation:

timer1.Enabled = true;

//We change OffOn value toopposite:

OffOn = false; //or so: OffOn =! OffOn;

}

}



      ( 2.3)  , , : Ctrl+F5.   Visual C#        .      500 ( 0,5)   (Calculator)   ࠫ  (Calculator with animation)  (. 2.11),     .








. 2.11.       Stop/Start Animation.



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

  ,         ,   Properties     Events     Click     ,   2.8.

     ,      ,     , , [9]   ZharkovPress.com.



2.9.          



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

  , , Visual Basic   .

1.   Project  Add Reference (  Solution Explorer          Add Reference).

   Add Reference (. 2.12).

2.   Add Reference  (.NET)     (dynamic link library), , Microsoft.VisualBasic  OK.

      Solution Explorer (. 2.13).

     Visual Basic       ( )  ,    .













. 2.12.  Microsoft.VisualBasic. . 2.13.  Solution Explorer.



2.10.         



,        ,      .

       ,     Visual Basic  ,      -        Beep ().   Visual Basic   Beep ()     Tick ,          Tick    .

   Beep ()   , ,  Tick   Visual C#,    ,  Visual C#  .

         ()   ,   Visual Basic.     , ,  Tick  Visual C#   (   Microsoft)    (.),      ,       (. 2.14).








. 2.14.  ,    VC#.

   Visual Basic,       (Microsoft.VisualBasic).

    Microsoft.VisualBasic     (.),        VisualBasic,       (. 2.15). ,          (dynamic link library) Microsoft.VisualBasic,       .     Interaction,      :



Microsoft.VisualBasic.Interaction








. 2.15.  ,    .



    Microsoft.VisualBasic.Interaction    (.),       ( ) Visual Basic  Interaction,       (. 2.16).     Beep (),       (Microsoft.VisualBasic.Interaction.Beep()).

 ,       , ,  Tick  Visual C#     Beep():



Microsoft.VisualBasic.Interaction.Beep();



   Beep       Tick     Interval.








. 2.16.  ,    .



        N_Beep,       (, 10)   N_Beep:



//We declare the counter ofnumber ofintervals

//and set its initial value:

int i=0;

//We declare and set the number N_Beepof ofintervals,

//after which agiving ofasound signal will stop:

int N_Beep =10;



     i:



i= i+1;

if (i<= N_Beep)

Microsoft.VisualBasic.Interaction.Beep();



          , ,        (   ).

  ,    (, [9])          ,           .

    ,    ()              ( )     Visual C#   ,  ( )   ( ) ,          .

         - ,  ()           .




 3.          





3.1.     


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

 :

    ;

    ;

   ;

   (  ):

  OK,        .

 ()           (        ,   );   ,     .

,   (     ),      -.

1.  VS   New Project (  File, New, Project).

2.   New Projects ( )  Project Types  Visual C#;  Templates ,   ()  Templates, Visual C#, Windows Classic Desktop, Windows Forms App (.NET Framework);  Name   , , Calculator2_2(  2   ,   2  ). ٸOK.

  Visual C#       Form1 (   ).

       (. 3.1)    ( , , , )   (  Timer:  Enabled  True;  Interval, ,  ,  100).




3.2.   


      Project  Add Windows Form (  Solution Explorer       Add, Add Windows Form).    Add New Item (. 3.2).

  Add New Item      Add (  VS   Open).   Visual C#    VS  Form2, ,  Form1 (. 3.3)   Solution Explorer   Form2.cs (. 3.4).   Form2 ,   Solution Explorer    Form2.cs (. 3.4).

,  ,    Form2 (. 3.3).

      ,      .








. 3.1.    .








. 3.2.   Add New Item    Add.













. 3.3. Form2  . . 3.4.  Solution Explorer.




3.3.  


   Form1  .   (   )    .



 3.1.  Button1_Click     .

		private void button1_Click (object sender, EventArgse)
		{
		double A,B;
		A= Convert.ToDouble (textBox1.Text);
		B = Convert.ToDouble (textBox2.Text);
		Form2 myForm2 = new Form2();
		myForm2.C =A;
		myForm2.D =B;
		myForm2.Show();

}



,  Visual C#,  Visual Basic,     .  Show ()   ,     ShowDialog().

   Form2.         C D,      ,       .



 3.2.   Button1_Click    Form2.

		public double C,D;

		private void button1_Click (object sender, EventArgse)
		{
		double F,G;

F =C;
G =D;
textBox1.Text = F.ToString();
textBox2.Text = G.ToString();
textBox3.Text = (F * G).ToString();
}



  ,  AB, , ,   C D,  ,    ,      TextBox,       .  F, G   (    )   C, D. ,            ,       ( 3.13.2),   .

        ZharkovPress.com.




3.4.      


                  ,   ,   -  .        , :

 ࠖ    ;

 ࠖ    .

  ࠖ     :

  ,     ( )    Properties   Interval;

      ,   ()   .

        timer1     .   Form1.cs   timer1_Tick    Tick,  ( )   () timer1.     ,      ,    .



 3.3.    ࠖ  .



//We declare and nullify the global variable:

int i=0;



private void timer1_Tick (object sender, EventArgse)

{

//We write the text ofheading inthe myString variable:

string myString = Calculator2_2;

//On the right tothe left appear the i -letterof

//aheading ofform:

this. Text = myString.Substring (0,i);

//We organize acycle ofoutputof

//the following i -letter:

i= i+1;

if (i== myString. Length)

i=1;


}



           .

  ࠖ       ( ):

   ;

  ,     ( )    Properties   Interval;

            ()   .

   timer1     .

  Form2.cs ;      ,     ,    .



 3.4.    ࠖ  .



//We declare the global variable myString

//and write init the text ofheading:

public static string myString = Calculator2_2. Form2;

//We declare the global variablei

//and equate its value tonumber ofsigns ofheading:

int i= myString. Length;



private void timer1_Tick (object sender, EventArgse)

{

//At the left tothe right leaves one i -letter

//ofaheading:

this. Text = myString.Substring (0,i);

//We organize aremoval cycleof

//the following i -letter ofheading:

i= i1;

if (i==-1)

i= myString. Length;

}



      -   (   ),   3.33.4



this. Text = myString.Substring (0,i);



   this       ( Name), , (button1.)  .




3.5.  


     ()  -, ,     :

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

  Visual C#              (. 3.5).     ࠖ   .

2.      .

3. ٸ  ,     =.

   (. 3.6)    .     ࠖ   .

4.    OK.

  Visual C#    (. 3.6):

 堖   ;

 堖   ;

 堖    .

     x (Close).   Visual C#   ,    .              .








. 3.5.  .








. 3.6.  .



             .

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

       .

2. ٸ OK        .

         .      (    ) .

      x (Close)  ,    () .

 ,          .

    ( )     -      ,    ,   ,      .

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

    ( )      (, )               ,    .    ,   ,      ,      Visual Studio   ,  .




 II.       





 4.     





4.1.    


        ,        ,    microsoft.com: Rob Miles. Games Programming with Cheese: Part One.         , ,     Visual Studio,            , ,     Visual Studio.

         .       ( )           (arcade).

  ,  , , , -  , ,    (cheese).         ,        , , 25x 32.       ,    -  , , Paint,      Windows.

  , ,       ,    ,   .

     : VS  New Project  Project types    Visual C#, Windows,  Templates   Templates, Visual C#, Windows Classic Desktop, Windows Forms App (.NET Framework),  Name  (  )    OK.  , ,  ,    ,         ,   Name    .  ,   Form1 (. 4.1)  .  (  ) ,       . ,        ,   Properties ( Form1)  BackColor   Window.

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

  Solution Explorer     (. 4.2).

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

  ,    Form1.cs    System.Reflection    Assembly:



using System.Reflection; //For the Assembly class.



  Properties ( Form1)  Events     Paint.    Form1_Paint      .

   , ,   PictureBox   -     .


















. 4.1. . . 4.2.   SE () Properties ().



 4.1.    .



//We declare the object ofclass System.Drawing.Image

//for aproduct:

Image cheeseImage;

//We load into the project the image files according

//tosuch scheme:

//We create an object myAssembly ofthe Assembly class

//and appropriate toit

//the link tothe executed assembly ofour application:

static Assembly myAssembly = Assembly.GetExecutingAssembly();

//We create the myAssemblyName objectof

//the System.Reflection.AssemblyName class and appropriateto

//it the assembly name, which consists ofaproject name,

//Version, Culture, PublicKeyToken:

static AssemblyName myAssemblyName = myAssembly.GetName();

//From the assembly name bymeans ofthe Name property

//we select astring project name:

static string myName_of_project = myAssemblyName.Name;



private void Form1_Paint (object sender, PaintEventArgse)

{

//We load into object ofthe System.Drawing.Image class

//the image file ofthe set format, added tothe project,

//bymeans ofResourceStream:

cheeseImage=

new Bitmap(myAssembly.GetManifestResourceStream(

myName_of_project +. + "cheese.JPG));

//We draw the image on the Form1:

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

}



     :

Build, Build Selection; Debug, Start Without Debugging.

  Form1       cheese.jpg (. 4.1).

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




4.2.   


     .     ,       .      ,    ().

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



 4.2.   .

		//Current abscissa ofan object:
		int cx =50;
		//Current ordinate ofan object:
		int cy =100;

		private void updatePositions()
		{
		cx++; //or cx = cx+1;
		cy++; //or cy = cy+1;

}



,     cx cy,    .        ,    ,      .

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

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

 ,    ,    .     Form1_Paint   :



//We turn on the timer:

timer1.Enabled = true;



,    Form1_Paint   .



 4.3.    .



private void Form1_Paint (object sender, PaintEventArgse)

{

//We load into object ofthe System.Drawing.Image class

//the image file ofthe set format, added tothe project,

//bymeans ofResourceStream:

cheeseImage=

new Bitmap(myAssembly.GetManifestResourceStream(

myName_of_project +. + "cheese.JPG));

//We draw the image on the Form1:

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

//We turn on the timer:

timer1.Enabled = true;

}



  ,    Form1_Paint,       cx cy.

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



 4.4.       .

		private void timer1_Tick (object sender, EventArgse)
		{
		//We call the method:
		updatePositions();
		//We redraw the screen:
		Invalidate();

}



     :

Build, Build Selection; Debug, Start Without Debugging.

  Visual C#   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.   .

		//Movement on an axis x tothe right:
		bool goingRight = true;
		//Movement on an axis ofy tothe down:
		bool goingDown = true;

		private void updatePositions()
		{
		if (goingRight)
		{
		cx++;
		}
		else
		{
		cx;
		}
		if ((cx + cheeseImage. Width)> =this.ClientSize. Width)




  .


   .

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

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


