Click here to Skip to main content
15,926,939 members
Home / Discussions / C#
   

C#

 
QuestionAuto-copy to clipboard selected text Pin
Toki8422-Mar-07 6:11
Toki8422-Mar-07 6:11 
Questionumm..how to get screen shot of a C# project Pin
Saira Tanwir22-Mar-07 6:09
Saira Tanwir22-Mar-07 6:09 
AnswerRe: umm..how to get screen shot of a C# project Pin
Leslie Sanford22-Mar-07 6:35
Leslie Sanford22-Mar-07 6:35 
GeneralRe: umm..how to get screen shot of a C# project Pin
Saira Tanwir22-Mar-07 23:20
Saira Tanwir22-Mar-07 23:20 
GeneralRe: umm..how to get screen shot of a C# project Pin
Leslie Sanford23-Mar-07 1:32
Leslie Sanford23-Mar-07 1:32 
QuestionC# Multi threading Pin
Tipzen22-Mar-07 5:53
Tipzen22-Mar-07 5:53 
AnswerRe: C# Multi threading Pin
Christian Graus22-Mar-07 5:58
protectorChristian Graus22-Mar-07 5:58 
GeneralRe: C# Multi threading Pin
sewez8-Sep-08 5:38
sewez8-Sep-08 5:38 
actually i have the same problem and i'll show you what i got so far.
class DrawBall
{
   private float initialX;
   private float initialY;
   private Random generator;
   private int direction;
   private Panel drawPanel;
   private float radius;
   private float velocity;

   public DrawBall( Panel panel )
   {
      drawPanel = panel;
      generator = new Random();
      radius = (float)generator.Next( 10, 30 );
      float temp = drawPanel.Size.Width - ( radius * 2 );
      initialX = 100;
      initialY = 100;
      direction = generator.Next( 8 );
      velocity = 10;
   }

   private delegate void DrawBallDelegate( float x, float y );
   private void DrawBallInPanel( float x, float y )
   {
      Graphics myGraphics = drawPanel.CreateGraphics();
      myGraphics.FillEllipse( new SolidBrush( Color.Red ),
         x, y, radius * 2, radius * 2 );
   }

   private delegate void ClearPanel();
   private void ClearBallsPanel()
   {
      Graphics myGraphics = drawPanel.CreateGraphics();
      myGraphics.Clear( Color.White );
   }

   public void BallGenerator()
   {
      while ( true )
      {
         drawPanel.Invoke( new DrawBallDelegate( DrawBallInPanel ),
            new object[] { initialX, initialY } );

         Thread.Sleep( 50 );

         if ( ( initialX  <= drawPanel.Size.Width ) ||
            ( initialX > 0 ) || ( initialY > 0 ) ||
            ( initialY <= drawPanel.Size.Height ) )
         {
            switch ( direction )
            {
               case 0:
                  initialY -= velocity;
                  break;
               case 1:
                  initialX += velocity;
                  initialY -= velocity;
                  break;
               case 2:
                  initialX += velocity;
                  break;
               case 3:
                  initialX += velocity;
                  initialY += velocity;
                  break;
               case 4:
                  initialY += velocity;
                  break;
               case 5:
                  initialX -= velocity;
                  initialY += velocity;
                  break;
               case 6:
                  initialX -= velocity;
                  break;
               case 7:
                  initialX -= velocity;
                  initialY -= velocity;
                  break;
            }
         }
         else
         {
            if ( direction == 0 )
               direction = 4;
            if ( direction == 1 )
               direction = 5;
            if ( direction == 2 )
               direction = 6;
            if ( direction == 3 )
               direction = 7;
            if ( direction == 4 )
               direction = 0;
            if ( direction == 5 )
               direction = 1;
            if ( direction == 6 )
               direction = 2;
            if ( direction == 7 )
               direction = 3;

            velocity = (float)generator.Next( 10, 20 );

            switch ( direction )
            {
               case 0:
                  initialY -= velocity;
                  break;
               case 1:
                  initialX += velocity;
                  initialY -= velocity;
                  break;
               case 2:
                  initialX += velocity;
                  break;
               case 3:
                  initialX += velocity;
                  initialY += velocity;
                  break;
               case 4:
                  initialY += velocity;
                  break;
               case 5:
                  initialX -= velocity;
                  initialY += velocity;
                  break;
               case 6:
                  initialX -= velocity;
                  break;
               case 7:
                  initialX -= velocity;
                  initialY -= velocity;
                  break;
            }
         }
         drawPanel.Invoke( new ClearPanel( ClearBallsPanel ) );
      }
   }
}

the problem now is that the ball wont stop at the panel borders and just keep moving. i have already tried to remove that bug by putting a if condition.
if ( ( initialX  &lt;= drawPanel.Size.Width ) ||
   ( initialX &gt; 0 ) || ( initialY &gt; 0 ) ||
   ( initialY &lt;= drawPanel.Size.Height ) )

but it just doesn't work. i have done all the rest of the code including add a thread and mouse event handler.
the only problem now with this condition and the ball that doesn't stop.

Thanks Smile | :)
QuestionExcel and OleDb.Net Pin
manustone22-Mar-07 5:36
manustone22-Mar-07 5:36 
QuestionCommandName in a Windows Application Pin
davidstern10022-Mar-07 5:32
davidstern10022-Mar-07 5:32 
QuestionWindows User Control Pin
Ashok Bansal22-Mar-07 5:32
Ashok Bansal22-Mar-07 5:32 
AnswerRe: Windows User Control Pin
Dave Kreskowiak22-Mar-07 7:07
mveDave Kreskowiak22-Mar-07 7:07 
GeneralRe: Windows User Control Pin
Ashok Bansal22-Mar-07 18:16
Ashok Bansal22-Mar-07 18:16 
GeneralRe: Windows User Control Pin
Dave Kreskowiak23-Mar-07 13:21
mveDave Kreskowiak23-Mar-07 13:21 
Questionmultiple controls label,&Checkboxex DOUBT Pin
pashitech22-Mar-07 5:25
pashitech22-Mar-07 5:25 
AnswerRe: multiple controls label,&Checkboxex DOUBT Pin
Christian Graus22-Mar-07 5:30
protectorChristian Graus22-Mar-07 5:30 
GeneralRe: multiple controls label,&Checkboxex DOUBT Pin
pashitech22-Mar-07 5:40
pashitech22-Mar-07 5:40 
GeneralRe: multiple controls label,&Checkboxex DOUBT Pin
Christian Graus22-Mar-07 5:42
protectorChristian Graus22-Mar-07 5:42 
GeneralRe: multiple controls label,&Checkboxex DOUBT Pin
pashitech22-Mar-07 6:10
pashitech22-Mar-07 6:10 
GeneralRe: multiple controls label,&Checkboxex DOUBT Pin
Christian Graus22-Mar-07 7:22
protectorChristian Graus22-Mar-07 7:22 
QuestionAssembly headache during Office plugin deployment Pin
dabs22-Mar-07 5:24
dabs22-Mar-07 5:24 
QuestionProblems creating controls dinamicly thru code Pin
sinosoidal22-Mar-07 5:23
sinosoidal22-Mar-07 5:23 
AnswerRe: Problems creating controls dinamicly thru code Pin
Christian Graus22-Mar-07 5:24
protectorChristian Graus22-Mar-07 5:24 
GeneralRe: Problems creating controls dinamicly thru code Pin
sinosoidal22-Mar-07 5:39
sinosoidal22-Mar-07 5:39 
GeneralRe: Problems creating controls dinamicly thru code Pin
Christian Graus22-Mar-07 5:42
protectorChristian Graus22-Mar-07 5:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.