Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. showing form from bottom wth timer

showing form from bottom wth timer

Scheduled Pinned Locked Moved C#
help
19 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eng iris
    wrote on last edited by
    #1

    hi every body i wish i could find somebody help i want my window to be shown slowly from left corner up and then go down when a button clicked and after a atimer interval the form shown again this the code i tries but the form doesnt shown again :sigh: :sigh: :sigh:

    namespace moving_form
    {
    public partial class Form1 : Form
    {
    bool flag = true;
    public Form1()
    {
    InitializeComponent();
    }

        private void Form1\_Load(object sender, EventArgs e)
        {
            this.Left = 0; // right -->Screen.PrimaryScreen.Bounds.Width - this.Width;
            this.Top = Screen.PrimaryScreen.Bounds.Height + this.Height - 30;
            // to make it in the corner + this.height
             
            timer1.Enabled = true;
        }
    
        private void timer1\_Tick(object sender, EventArgs e)
        {         flag = true;
                if (this.Top >= Screen.PrimaryScreen.Bounds.Height - this.Height - 30)
                    this.Top = this.Top - 10;  
                           }
            
        private void button1\_Click(object sender, EventArgs e)
        {
           timer2.Enabled = true;
        }
    
        private void timer2\_Tick(object sender, EventArgs e)
        {
           
            flag = false;
                if (this.Top > Screen.PrimaryScreen.Bounds.Height)
                {
                   
                    return;
                }
          
            else
            {
                this.Top = this.Top + 10; 
                flag = true;
            }
            
        }
    
       
       
    }
    

    }

    thanx again

    M K V 3 Replies Last reply
    0
    • E eng iris

      hi every body i wish i could find somebody help i want my window to be shown slowly from left corner up and then go down when a button clicked and after a atimer interval the form shown again this the code i tries but the form doesnt shown again :sigh: :sigh: :sigh:

      namespace moving_form
      {
      public partial class Form1 : Form
      {
      bool flag = true;
      public Form1()
      {
      InitializeComponent();
      }

          private void Form1\_Load(object sender, EventArgs e)
          {
              this.Left = 0; // right -->Screen.PrimaryScreen.Bounds.Width - this.Width;
              this.Top = Screen.PrimaryScreen.Bounds.Height + this.Height - 30;
              // to make it in the corner + this.height
               
              timer1.Enabled = true;
          }
      
          private void timer1\_Tick(object sender, EventArgs e)
          {         flag = true;
                  if (this.Top >= Screen.PrimaryScreen.Bounds.Height - this.Height - 30)
                      this.Top = this.Top - 10;  
                             }
              
          private void button1\_Click(object sender, EventArgs e)
          {
             timer2.Enabled = true;
          }
      
          private void timer2\_Tick(object sender, EventArgs e)
          {
             
              flag = false;
                  if (this.Top > Screen.PrimaryScreen.Bounds.Height)
                  {
                     
                      return;
                  }
            
              else
              {
                  this.Top = this.Top + 10; 
                  flag = true;
              }
              
          }
      
         
         
      }
      

      }

      thanx again

      M Offline
      M Offline
      Midnight Ahri
      wrote on last edited by
      #2

      Maybe you didn't start your timer? :doh:

      E 1 Reply Last reply
      0
      • M Midnight Ahri

        Maybe you didn't start your timer? :doh:

        E Offline
        E Offline
        eng iris
        wrote on last edited by
        #3

        no, unfotunately its enabled and sterted :(

        M 1 Reply Last reply
        0
        • E eng iris

          no, unfotunately its enabled and sterted :(

          M Offline
          M Offline
          Midnight Ahri
          wrote on last edited by
          #4

          Edit : I changed your code but yeah it's messy. My advice, * Reduce timer usage * Stop your timer when you don't need them (not keep returning)

          public partial class Form1 : Form
          {
          public Form1()
          {
          InitializeComponent();
          timer3.Interval = 1000;
          }

              bool flag = true;
              int delay = 0;
          
              private void Form1\_Load(object sender, EventArgs e)
              {
                  this.Left = 0; // right -->Screen.PrimaryScreen.Bounds.Width - this.Width;
                  this.Top = Screen.PrimaryScreen.Bounds.Height + this.Height - 30;
                  // to make it in the corner + this.height
          
                  timer1.Enabled = true;
              }
          
              private void timer1\_Tick(object sender, EventArgs e)
              {
                  flag = true;
                  if (this.Top >= Screen.PrimaryScreen.Bounds.Height - this.Height - 30)
                  {
                      this.Top = this.Top - 10;
                  }
                  else
                  {
                      timer1.Enabled = false;
                  }
              }
          
              private void timer2\_Tick(object sender, EventArgs e)
              {
                  flag = false;
                  if (this.Top > Screen.PrimaryScreen.Bounds.Height)
                  {
                      timer2.Enabled = false;
                      timer3.Enabled = true;
                      return;
                  }
          
                  else
                  {
                      this.Top = this.Top + 10;
                      flag = true;
                  }
              }
          
              private void button1\_Click(object sender, EventArgs e)
              {
                  timer2.Enabled = true;
              }
          
              private void timer3\_Tick(object sender, EventArgs e)
              {
                  if (this.delay >= 5) //delay for 5 second
                  {
                      this.delay = 0;
                      timer1.Enabled = true;
                      timer3.Enabled = false;
                  }
                  else
                  {
                      this.delay += 1;
                  }
              }
          }
          
          E 1 Reply Last reply
          0
          • E eng iris

            hi every body i wish i could find somebody help i want my window to be shown slowly from left corner up and then go down when a button clicked and after a atimer interval the form shown again this the code i tries but the form doesnt shown again :sigh: :sigh: :sigh:

            namespace moving_form
            {
            public partial class Form1 : Form
            {
            bool flag = true;
            public Form1()
            {
            InitializeComponent();
            }

                private void Form1\_Load(object sender, EventArgs e)
                {
                    this.Left = 0; // right -->Screen.PrimaryScreen.Bounds.Width - this.Width;
                    this.Top = Screen.PrimaryScreen.Bounds.Height + this.Height - 30;
                    // to make it in the corner + this.height
                     
                    timer1.Enabled = true;
                }
            
                private void timer1\_Tick(object sender, EventArgs e)
                {         flag = true;
                        if (this.Top >= Screen.PrimaryScreen.Bounds.Height - this.Height - 30)
                            this.Top = this.Top - 10;  
                                   }
                    
                private void button1\_Click(object sender, EventArgs e)
                {
                   timer2.Enabled = true;
                }
            
                private void timer2\_Tick(object sender, EventArgs e)
                {
                   
                    flag = false;
                        if (this.Top > Screen.PrimaryScreen.Bounds.Height)
                        {
                           
                            return;
                        }
                  
                    else
                    {
                        this.Top = this.Top + 10; 
                        flag = true;
                    }
                    
                }
            
               
               
            }
            

            }

            thanx again

            K Offline
            K Offline
            Kamran Ayati
            wrote on last edited by
            #5

            what is your problem with this code?

            E 1 Reply Last reply
            0
            • E eng iris

              hi every body i wish i could find somebody help i want my window to be shown slowly from left corner up and then go down when a button clicked and after a atimer interval the form shown again this the code i tries but the form doesnt shown again :sigh: :sigh: :sigh:

              namespace moving_form
              {
              public partial class Form1 : Form
              {
              bool flag = true;
              public Form1()
              {
              InitializeComponent();
              }

                  private void Form1\_Load(object sender, EventArgs e)
                  {
                      this.Left = 0; // right -->Screen.PrimaryScreen.Bounds.Width - this.Width;
                      this.Top = Screen.PrimaryScreen.Bounds.Height + this.Height - 30;
                      // to make it in the corner + this.height
                       
                      timer1.Enabled = true;
                  }
              
                  private void timer1\_Tick(object sender, EventArgs e)
                  {         flag = true;
                          if (this.Top >= Screen.PrimaryScreen.Bounds.Height - this.Height - 30)
                              this.Top = this.Top - 10;  
                                     }
                      
                  private void button1\_Click(object sender, EventArgs e)
                  {
                     timer2.Enabled = true;
                  }
              
                  private void timer2\_Tick(object sender, EventArgs e)
                  {
                     
                      flag = false;
                          if (this.Top > Screen.PrimaryScreen.Bounds.Height)
                          {
                             
                              return;
                          }
                    
                      else
                      {
                          this.Top = this.Top + 10; 
                          flag = true;
                      }
                      
                  }
              
                 
                 
              }
              

              }

              thanx again

              V Offline
              V Offline
              V 0
              wrote on last edited by
              #6

              I can see several problems: - are the timers started when the button is pressed? What is the interval? - It's possible that you need to send a redraw command on each tick (like update or invalidate or something) - I'm confused the compiler doesn't complain about the flag variable. It's accessed across threads. - why two timers? I believe 1 timer should be able to do the trick ? the simplest way to go on about this IMHO is: - 1 timer. - 1 static boolean (true when button pressed, false when movement was done) - 1 static counter that counts each passing of the the timer_tick handler. - 1 static (final) stopvalue for when the work should stop. in timer_tick you then check counter vs stopvalue (= amount of time), set the flag on false and reset the form, in an if(flag==true) block you can then move the form. this is quick thinking, you can go into the details from there. hope this helps...

              V.
              (MQOTD Rules and previous Solutions )

              E 1 Reply Last reply
              0
              • K Kamran Ayati

                what is your problem with this code?

                E Offline
                E Offline
                eng iris
                wrote on last edited by
                #7

                it doesnt do the movement up-down an down-up of the form in the corner of the screen

                K 1 Reply Last reply
                0
                • M Midnight Ahri

                  Edit : I changed your code but yeah it's messy. My advice, * Reduce timer usage * Stop your timer when you don't need them (not keep returning)

                  public partial class Form1 : Form
                  {
                  public Form1()
                  {
                  InitializeComponent();
                  timer3.Interval = 1000;
                  }

                      bool flag = true;
                      int delay = 0;
                  
                      private void Form1\_Load(object sender, EventArgs e)
                      {
                          this.Left = 0; // right -->Screen.PrimaryScreen.Bounds.Width - this.Width;
                          this.Top = Screen.PrimaryScreen.Bounds.Height + this.Height - 30;
                          // to make it in the corner + this.height
                  
                          timer1.Enabled = true;
                      }
                  
                      private void timer1\_Tick(object sender, EventArgs e)
                      {
                          flag = true;
                          if (this.Top >= Screen.PrimaryScreen.Bounds.Height - this.Height - 30)
                          {
                              this.Top = this.Top - 10;
                          }
                          else
                          {
                              timer1.Enabled = false;
                          }
                      }
                  
                      private void timer2\_Tick(object sender, EventArgs e)
                      {
                          flag = false;
                          if (this.Top > Screen.PrimaryScreen.Bounds.Height)
                          {
                              timer2.Enabled = false;
                              timer3.Enabled = true;
                              return;
                          }
                  
                          else
                          {
                              this.Top = this.Top + 10;
                              flag = true;
                          }
                      }
                  
                      private void button1\_Click(object sender, EventArgs e)
                      {
                          timer2.Enabled = true;
                      }
                  
                      private void timer3\_Tick(object sender, EventArgs e)
                      {
                          if (this.delay >= 5) //delay for 5 second
                          {
                              this.delay = 0;
                              timer1.Enabled = true;
                              timer3.Enabled = false;
                          }
                          else
                          {
                              this.delay += 1;
                          }
                      }
                  }
                  
                  E Offline
                  E Offline
                  eng iris
                  wrote on last edited by
                  #8

                  thaks alot the code ig going down an back up when button pressed but there is one more thing how can i make the form come up again after two minutes for example? i have try adding interval time but no use thanx again waiting

                  1 Reply Last reply
                  0
                  • V V 0

                    I can see several problems: - are the timers started when the button is pressed? What is the interval? - It's possible that you need to send a redraw command on each tick (like update or invalidate or something) - I'm confused the compiler doesn't complain about the flag variable. It's accessed across threads. - why two timers? I believe 1 timer should be able to do the trick ? the simplest way to go on about this IMHO is: - 1 timer. - 1 static boolean (true when button pressed, false when movement was done) - 1 static counter that counts each passing of the the timer_tick handler. - 1 static (final) stopvalue for when the work should stop. in timer_tick you then check counter vs stopvalue (= amount of time), set the flag on false and reset the form, in an if(flag==true) block you can then move the form. this is quick thinking, you can go into the details from there. hope this helps...

                    V.
                    (MQOTD Rules and previous Solutions )

                    E Offline
                    E Offline
                    eng iris
                    wrote on last edited by
                    #9

                    thanks alot for your hints i will try them my problem is in how make the form come up again after its hidden in the corner after 2 minutes ?

                    V M 2 Replies Last reply
                    0
                    • E eng iris

                      thanks alot for your hints i will try them my problem is in how make the form come up again after its hidden in the corner after 2 minutes ?

                      V Offline
                      V Offline
                      V 0
                      wrote on last edited by
                      #10

                      if the goal is to hide the form you should use the Visible property (see here[^]) else you just reset the location of the form. You could keep the initial location in a Point variable and reset it to that when you reset the form.

                      V.
                      (MQOTD Rules and previous Solutions )

                      E 1 Reply Last reply
                      0
                      • E eng iris

                        thanks alot for your hints i will try them my problem is in how make the form come up again after its hidden in the corner after 2 minutes ?

                        M Offline
                        M Offline
                        Midnight Ahri
                        wrote on last edited by
                        #11

                        I've put the comment on where to change the delay. And I changed the interval to 1000 so the tick event execute every 1 second. So you don't have to change the interval anymore.

                        E 1 Reply Last reply
                        0
                        • E eng iris

                          it doesnt do the movement up-down an down-up of the form in the corner of the screen

                          K Offline
                          K Offline
                          Kamran Ayati
                          wrote on last edited by
                          #12

                          you must set timer.enabled= true timer.interval =1000 milissecond and in timer event timer copy your code for move for example buton1.left=buton1.left+100;(for x axis) buton1.top=buton1.top+200;(for y axis)

                          E 1 Reply Last reply
                          0
                          • V V 0

                            if the goal is to hide the form you should use the Visible property (see here[^]) else you just reset the location of the form. You could keep the initial location in a Point variable and reset it to that when you reset the form.

                            V.
                            (MQOTD Rules and previous Solutions )

                            E Offline
                            E Offline
                            eng iris
                            wrote on last edited by
                            #13

                            the goal is not hiding the form i want to move it down and after an interval make it move up again as its shown first if i hide data order will be lost " bindingsource.movenext " so i just wan to delay its appearance wth the samem data >>> by move it up and down ,,up and down how can i move it up again after passed time ? hope u got me thank you all again i appreciate

                            V 1 Reply Last reply
                            0
                            • K Kamran Ayati

                              you must set timer.enabled= true timer.interval =1000 milissecond and in timer event timer copy your code for move for example buton1.left=buton1.left+100;(for x axis) buton1.top=buton1.top+200;(for y axis)

                              E Offline
                              E Offline
                              eng iris
                              wrote on last edited by
                              #14

                              i didi that still no use :(

                              1 Reply Last reply
                              0
                              • M Midnight Ahri

                                I've put the comment on where to change the delay. And I changed the interval to 1000 so the tick event execute every 1 second. So you don't have to change the interval anymore.

                                E Offline
                                E Offline
                                eng iris
                                wrote on last edited by
                                #15

                                yessssssss that wat i want thanks alot midnight thanks all :)

                                E 1 Reply Last reply
                                0
                                • E eng iris

                                  the goal is not hiding the form i want to move it down and after an interval make it move up again as its shown first if i hide data order will be lost " bindingsource.movenext " so i just wan to delay its appearance wth the samem data >>> by move it up and down ,,up and down how can i move it up again after passed time ? hope u got me thank you all again i appreciate

                                  V Offline
                                  V Offline
                                  V 0
                                  wrote on last edited by
                                  #16

                                  I answered it already. To move the form you need to change the location property. Possibly you'll need to force a redraw by calling invalidate or refresh or update or something. If you want to set it back after an amount of time you need to store the original location before moving. Moving is with X-Y coordinates (per pixel) where X is moving from left to right and Y from top to bottom. So on a 1024x768 screen the top-left corner is 0,0 and the bottom-right corner 1024,768. This should provide you with enough information to get you going.

                                  V.
                                  (MQOTD Rules and previous Solutions )

                                  1 Reply Last reply
                                  0
                                  • E eng iris

                                    yessssssss that wat i want thanks alot midnight thanks all :)

                                    E Offline
                                    E Offline
                                    eng iris
                                    wrote on last edited by
                                    #17

                                    the form is comimg up and then come back down when click a button what if i want the for to come down again after its shown for 1 minutes for example have i add a timer test the i will be gratefull

                                    M 1 Reply Last reply
                                    0
                                    • E eng iris

                                      the form is comimg up and then come back down when click a button what if i want the for to come down again after its shown for 1 minutes for example have i add a timer test the i will be gratefull

                                      M Offline
                                      M Offline
                                      Midnight Ahri
                                      wrote on last edited by
                                      #18

                                      yes, you can create a timer that will start when the form is shown or change your code to make it better, less timer.

                                      E 1 Reply Last reply
                                      0
                                      • M Midnight Ahri

                                        yes, you can create a timer that will start when the form is shown or change your code to make it better, less timer.

                                        E Offline
                                        E Offline
                                        eng iris
                                        wrote on last edited by
                                        #19

                                        ok i will try it thank u soo much

                                        1 Reply Last reply
                                        0
                                        Reply
                                        • Reply as topic
                                        Log in to reply
                                        • Oldest to Newest
                                        • Newest to Oldest
                                        • Most Votes


                                        • Login

                                        • Don't have an account? Register

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • World
                                        • Users
                                        • Groups