Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am not very good at this, but I have an idea, and I want to ask here if it is possible. So I want to make, so PictureBox grows bigger, grows to some size and then goes smaller again, and continue doing this. I have only figured out how to make, so it goes bigger or smaller, but I can not figure out how to make so it detects specific size, and then do the opposite. The code I use.
Size size = pictureBox.Size;
size.Height--;
size.Width--;
pictureBox.Size = size;
Just an example, since you didn't specify your criterion for enlarging and reducing. Initialize your timer:
// set the interval you prefer
System.Timers.Timer timer = new System.Timers.Timer(500);
timer.Elapsed += OnElapsed;
timer.AutoReset = true;
timer.Enabled = true;
Create a member variable that controls whether the PictureBox must be enlarged or reduced:
private Boolean m_Reducing = false;
And then put everything together in your subscribed timer handler:
private static void OnElapsed(Object sender, ElapsedEventArgs e)
{
Size size = pictureBox.Size;
if (m_Reducing)
{
--size.Height;
--size.Width;
if ((size.Width == minimumWidth) && (size.Height == minimumHeight))
m_Reducing = false;
}
else
{
++size.Height;
++size.Width;
if ((size.Width == maximumWidth) && (size.Height == maximumHeight))
m_Reducing = true;
}
pictureBox.Size = size;
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
So this algorithm should flash the word finished in 1 second intervals 3 times but it just freezes for 5 seconds instead. Any ideas?
bool appear = false;
int i = 0;
while (i < 5)
{
i++;
if (appear == false)
{
appear = true;
Finished_label.Visible = true;
}
else
{
appear = false;
Finished_label.Visible = false;
}
System.Threading.Thread.Sleep(1000);
}
*Edit I am writing this in C# Visual Studio Windows Forms Application
Thread.Sleep() blocks the UI thread, so you don't see the changes. You could use
await Task.Delay(1000);
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am making a food ordering desktop application , so i want to calculate time between ordering food and delivering food so i added timers to the app and made a start and end buttons , on starting i start a time and put it interval value ,make a variable counter, count and save its value on end button to database , what i want to made is to start a new timer dynamically on new orders and when ending an order stop its timer
i tried inserting 3 timers and made variables c1,c2,c3 and made a loop to start timers on every order if interval!=null , but i didn't know how to stop a specific timer on ending the order
code :
int c1=0;
int c2=0;
int c3=0;
private void button_start_Click(object sender, EventArgs e)
{
if (timer1.Interval == null)
{
timer1.Start();
timer1.Interval = 1000;
}
else if (timer2.Interval == null)
{
timer2.Start();
timer2.Interval = 1000;
}
else if (timer3.Interval == null)
{
timer3.Start();
timer3.Interval = 1000;
}
}
Well as you have not shown us any code, let me assume that you at least have a class to encapsulate order.
public class Order
{
public int OrderNumber{get;set;}
///other properties
}
Now if you add following two properties and a method, your problem is resolved.
public class Order
{
public int OrderNumber{get;set;}
//other properties
public DateTime OrderPlacedOn{get;set;}
public DateTime OrderCompletedOn{get;set;}
public TimeSpan TimeToComplete()
{
if(OrderCompletedOn==DateTime.MinValue)//order not completed yet
return TimeSpan.FromSeconds(0);
return OrderCompletedOn - OrderPlacedOn;
}
}
This saves you from keeping countless timers. You can set values of start and complete on clicking of your buttons.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Its my code, Can anyone please suggest me how i can put my progress bar so it can perform progress with function simultaneously..
i used progress bar in my application.
private void button1_Click(object sender, EventArgs e)
{
canaryTimer.Start();
canaryTimer.Interval = 1000;
canaryTimer.Tick += new EventHandler(canaryTimer_Tick);
PickDatafromTextFile();
CallRichtextbox();
GenerateExcel();
DeleteExcelRows();
SplitDateandTime();
SortDateandTime();
CombineDataoftwoExcel();
UpdateExcelFile();
}
private void canaryTimer_Tick(object sender, EventArgs e)
{
for (int i = 0; i <= 100; i++)
{
canaryProgressBar.Value=i;
}
}
A very simple suggestion:
Update your Progressbar from within the Button1_Click after each function completes.
Assuming your myProgressBar.Value is initialized with 0;
Example:
PickDatafromTextFile();
myProgressBar.Value += 14;
CallRichtextbox();
myProgressBar.Value += 14;
GenerateExcel();
myProgressBar.Value += 14;
DeleteExcelRows();
myProgressBar.Value += 14;
SplitDateandTime();
myProgressBar.Value += 14;
SortDateandTime();
myProgressBar.Value += 14;
CombineDataoftwoExcel();
myProgressBar.Value += 14;
UpdateExcelFile();
myProgressBar.Value = 100;
I know this isn't the correct way to do so. But for a simple task like this any other method would seem overkill to me.
I don't get the point of your question... If you want to load a textfile and than work with the information, you have to check out how much percent of the work is done. after that, you can increase the progressbar with this command:
progressBar1->Increment(1);
also you can set it to a value
progressBar1->Value = 5;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How to execute the multiple timers in different time interval using window scheduler....?
Is it possible using this functionality in .net...?
Thanks
You can also use single timer for different time intervals
for example:
private void Form_Load()
{
timer1.Interval = 1000; // 1 second
timer1.Start(); // Start timer, This will raise Tick event after 1 second
OnTick(); // So, call Tick event explicitly when we start timer
}
Int32 counter = 0;
private void timer1_Tick(object sender, EventArgs e)
{
OnTick();
}
private void OnTick()
{
if (counter % 1 == 0)
{
OnOneSecond();//Write your code in this method for one second
}
if (counter % 2 == 0)
{
OnTwoSecond();
}
counter++;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
what is another command for 'Goto' ? I am using VSTO to make a ribbon for excel and is doesnt seem to support Goto, and I am trying to create a loop.
Edit: This is the loop i am trying to create :
TimeSpan startTimeSpan = new TimeSpan(0, 0, 0, 20);
TimeSpan timeDecrease = TimeSpan.FromSeconds(1);
private Timer timer = new Timer();
public void Ribbon_Load(Office.IRibbonUI ribbonUI)
{
timer.Interval = 1000;
this.ribbon = ribbonUI;
timer.Tick += timer_Tick;
timer.Start();
}
private void timer_Tick(object sender, EventArgs e)
{
if (startTimeSpan.ToString() != "00:00:00")
{
startTimeSpan = startTimeSpan - timeDecrease;
ribbon.InvalidateControl("timerLabel");
}
else
{
//when timer drop to "00:00:00" then loop to "TimeSpan startTimeSpan = new TimeSpan(0, 0, 0, 20);"
}
}
You probably want to be using a while loop, with the exit condition in the while statement, and use break to quit the loop before the exit condition is reached, or continue to skip the current iteration of the loop and go on to the next.
C# does support goto command, but it isn't for looping. Jump statements are very often not the best solution.
goto - http://msdn.microsoft.com/en-us/library/13940fs2.aspx
If you are trying to loop just use a looping statement.
looping - http://msdn.microsoft.com/en-us/library/ms228598(v=vs.90).aspx
You can find a lot of q&a on excel VSTO.
Whats wrong with something like:
for (int i = selectedRange.Rows.Count; i > 0; i--)
{
---YOUR CODE HERE---
}
OR
foreach (Excel.Range row in rng.Areas[1].Rows)
{
---YOUR CODE HERE---
}