showing form from bottom wth timer
-
what is your problem with this code?
-
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; } } }
-
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...
-
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 ?
-
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 ?
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.
-
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)
-
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
-
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)
-
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.
-
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
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.
-
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
yes, you can create a timer that will start when the form is shown or change your code to make it better, less timer.
-
yes, you can create a timer that will start when the form is shown or change your code to make it better, less timer.