How do i change the value of progressbar from minutes?
i'm doing a "shutdowner" project in WinForm.
I can enter there a amount of minutes, after these minutes the pc shutdown.
Now i create a progressbar, min Value of 0, Max Value of 100.
e.g:
I enter 3 minutes (180 sec), and click on a "start" button, the value should be 0, and it should be 100 when the PC shutdowns (after the entered minutes).
I tried some math, but i didn't got it to work.
Thanks for you help!
c# winforms
|
show 4 more comments
i'm doing a "shutdowner" project in WinForm.
I can enter there a amount of minutes, after these minutes the pc shutdown.
Now i create a progressbar, min Value of 0, Max Value of 100.
e.g:
I enter 3 minutes (180 sec), and click on a "start" button, the value should be 0, and it should be 100 when the PC shutdowns (after the entered minutes).
I tried some math, but i didn't got it to work.
Thanks for you help!
c# winforms
Can you show us some of the code you have tried.
– Ryan Schlueter
Nov 20 at 17:33
1
Why not just set the max value to the number of seconds? Saves you having to do any maths.
– Handbag Crab
Nov 20 at 17:34
Did you have a look at the ProgressBar documentation? docs.microsoft.com/en-us/dotnet/api/…
– Klaus Gütter
Nov 20 at 17:34
Show us your math. This is a ridiculously easy problem that can be solved by simple division.
– Frontear
Nov 20 at 17:37
@RyanSchlueter i deleted the codes, because there weren't working HandbagCrab because i want 100% ;)
– maDPname1337
Nov 20 at 17:37
|
show 4 more comments
i'm doing a "shutdowner" project in WinForm.
I can enter there a amount of minutes, after these minutes the pc shutdown.
Now i create a progressbar, min Value of 0, Max Value of 100.
e.g:
I enter 3 minutes (180 sec), and click on a "start" button, the value should be 0, and it should be 100 when the PC shutdowns (after the entered minutes).
I tried some math, but i didn't got it to work.
Thanks for you help!
c# winforms
i'm doing a "shutdowner" project in WinForm.
I can enter there a amount of minutes, after these minutes the pc shutdown.
Now i create a progressbar, min Value of 0, Max Value of 100.
e.g:
I enter 3 minutes (180 sec), and click on a "start" button, the value should be 0, and it should be 100 when the PC shutdowns (after the entered minutes).
I tried some math, but i didn't got it to work.
Thanks for you help!
c# winforms
c# winforms
asked Nov 20 at 17:28
maDPname1337
1
1
Can you show us some of the code you have tried.
– Ryan Schlueter
Nov 20 at 17:33
1
Why not just set the max value to the number of seconds? Saves you having to do any maths.
– Handbag Crab
Nov 20 at 17:34
Did you have a look at the ProgressBar documentation? docs.microsoft.com/en-us/dotnet/api/…
– Klaus Gütter
Nov 20 at 17:34
Show us your math. This is a ridiculously easy problem that can be solved by simple division.
– Frontear
Nov 20 at 17:37
@RyanSchlueter i deleted the codes, because there weren't working HandbagCrab because i want 100% ;)
– maDPname1337
Nov 20 at 17:37
|
show 4 more comments
Can you show us some of the code you have tried.
– Ryan Schlueter
Nov 20 at 17:33
1
Why not just set the max value to the number of seconds? Saves you having to do any maths.
– Handbag Crab
Nov 20 at 17:34
Did you have a look at the ProgressBar documentation? docs.microsoft.com/en-us/dotnet/api/…
– Klaus Gütter
Nov 20 at 17:34
Show us your math. This is a ridiculously easy problem that can be solved by simple division.
– Frontear
Nov 20 at 17:37
@RyanSchlueter i deleted the codes, because there weren't working HandbagCrab because i want 100% ;)
– maDPname1337
Nov 20 at 17:37
Can you show us some of the code you have tried.
– Ryan Schlueter
Nov 20 at 17:33
Can you show us some of the code you have tried.
– Ryan Schlueter
Nov 20 at 17:33
1
1
Why not just set the max value to the number of seconds? Saves you having to do any maths.
– Handbag Crab
Nov 20 at 17:34
Why not just set the max value to the number of seconds? Saves you having to do any maths.
– Handbag Crab
Nov 20 at 17:34
Did you have a look at the ProgressBar documentation? docs.microsoft.com/en-us/dotnet/api/…
– Klaus Gütter
Nov 20 at 17:34
Did you have a look at the ProgressBar documentation? docs.microsoft.com/en-us/dotnet/api/…
– Klaus Gütter
Nov 20 at 17:34
Show us your math. This is a ridiculously easy problem that can be solved by simple division.
– Frontear
Nov 20 at 17:37
Show us your math. This is a ridiculously easy problem that can be solved by simple division.
– Frontear
Nov 20 at 17:37
@RyanSchlueter i deleted the codes, because there weren't working HandbagCrab because i want 100% ;)
– maDPname1337
Nov 20 at 17:37
@RyanSchlueter i deleted the codes, because there weren't working HandbagCrab because i want 100% ;)
– maDPname1337
Nov 20 at 17:37
|
show 4 more comments
1 Answer
1
active
oldest
votes
Try something like...
private int totalSeconds;
private DateTime targetTime;
private void button1_Click(object sender, EventArgs e)
{
int mins = (int)numericUpDown1.Value;
if (mins > 0)
{
TimeSpan ts = TimeSpan.FromMinutes(mins);
targetTime = DateTime.Now.Add(ts);
totalSeconds = (int)ts.TotalSeconds;
progressBar1.Value = 0;
button1.Enabled = false;
timer1.Interval = 1000;
timer1.Start();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
TimeSpan ts = targetTime.Subtract(DateTime.Now);
if (ts.TotalMilliseconds > 0)
{
label1.Text = "-" + ts.ToString(@"mm:ss");
double percent = ((double)totalSeconds - ts.TotalSeconds) / (double)totalSeconds;
progressBar1.Value = (int)(progressBar1.Maximum * percent);
}
else
{
timer1.Stop();
button1.Enabled = true;
progressBar1.Value = progressBar1.Maximum;
// ... do something here! ...
}
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398411%2fhow-do-i-change-the-value-of-progressbar-from-minutes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try something like...
private int totalSeconds;
private DateTime targetTime;
private void button1_Click(object sender, EventArgs e)
{
int mins = (int)numericUpDown1.Value;
if (mins > 0)
{
TimeSpan ts = TimeSpan.FromMinutes(mins);
targetTime = DateTime.Now.Add(ts);
totalSeconds = (int)ts.TotalSeconds;
progressBar1.Value = 0;
button1.Enabled = false;
timer1.Interval = 1000;
timer1.Start();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
TimeSpan ts = targetTime.Subtract(DateTime.Now);
if (ts.TotalMilliseconds > 0)
{
label1.Text = "-" + ts.ToString(@"mm:ss");
double percent = ((double)totalSeconds - ts.TotalSeconds) / (double)totalSeconds;
progressBar1.Value = (int)(progressBar1.Maximum * percent);
}
else
{
timer1.Stop();
button1.Enabled = true;
progressBar1.Value = progressBar1.Maximum;
// ... do something here! ...
}
}
add a comment |
Try something like...
private int totalSeconds;
private DateTime targetTime;
private void button1_Click(object sender, EventArgs e)
{
int mins = (int)numericUpDown1.Value;
if (mins > 0)
{
TimeSpan ts = TimeSpan.FromMinutes(mins);
targetTime = DateTime.Now.Add(ts);
totalSeconds = (int)ts.TotalSeconds;
progressBar1.Value = 0;
button1.Enabled = false;
timer1.Interval = 1000;
timer1.Start();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
TimeSpan ts = targetTime.Subtract(DateTime.Now);
if (ts.TotalMilliseconds > 0)
{
label1.Text = "-" + ts.ToString(@"mm:ss");
double percent = ((double)totalSeconds - ts.TotalSeconds) / (double)totalSeconds;
progressBar1.Value = (int)(progressBar1.Maximum * percent);
}
else
{
timer1.Stop();
button1.Enabled = true;
progressBar1.Value = progressBar1.Maximum;
// ... do something here! ...
}
}
add a comment |
Try something like...
private int totalSeconds;
private DateTime targetTime;
private void button1_Click(object sender, EventArgs e)
{
int mins = (int)numericUpDown1.Value;
if (mins > 0)
{
TimeSpan ts = TimeSpan.FromMinutes(mins);
targetTime = DateTime.Now.Add(ts);
totalSeconds = (int)ts.TotalSeconds;
progressBar1.Value = 0;
button1.Enabled = false;
timer1.Interval = 1000;
timer1.Start();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
TimeSpan ts = targetTime.Subtract(DateTime.Now);
if (ts.TotalMilliseconds > 0)
{
label1.Text = "-" + ts.ToString(@"mm:ss");
double percent = ((double)totalSeconds - ts.TotalSeconds) / (double)totalSeconds;
progressBar1.Value = (int)(progressBar1.Maximum * percent);
}
else
{
timer1.Stop();
button1.Enabled = true;
progressBar1.Value = progressBar1.Maximum;
// ... do something here! ...
}
}
Try something like...
private int totalSeconds;
private DateTime targetTime;
private void button1_Click(object sender, EventArgs e)
{
int mins = (int)numericUpDown1.Value;
if (mins > 0)
{
TimeSpan ts = TimeSpan.FromMinutes(mins);
targetTime = DateTime.Now.Add(ts);
totalSeconds = (int)ts.TotalSeconds;
progressBar1.Value = 0;
button1.Enabled = false;
timer1.Interval = 1000;
timer1.Start();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
TimeSpan ts = targetTime.Subtract(DateTime.Now);
if (ts.TotalMilliseconds > 0)
{
label1.Text = "-" + ts.ToString(@"mm:ss");
double percent = ((double)totalSeconds - ts.TotalSeconds) / (double)totalSeconds;
progressBar1.Value = (int)(progressBar1.Maximum * percent);
}
else
{
timer1.Stop();
button1.Enabled = true;
progressBar1.Value = progressBar1.Maximum;
// ... do something here! ...
}
}
answered Nov 20 at 18:05
Idle_Mind
22.3k21424
22.3k21424
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398411%2fhow-do-i-change-the-value-of-progressbar-from-minutes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you show us some of the code you have tried.
– Ryan Schlueter
Nov 20 at 17:33
1
Why not just set the max value to the number of seconds? Saves you having to do any maths.
– Handbag Crab
Nov 20 at 17:34
Did you have a look at the ProgressBar documentation? docs.microsoft.com/en-us/dotnet/api/…
– Klaus Gütter
Nov 20 at 17:34
Show us your math. This is a ridiculously easy problem that can be solved by simple division.
– Frontear
Nov 20 at 17:37
@RyanSchlueter i deleted the codes, because there weren't working HandbagCrab because i want 100% ;)
– maDPname1337
Nov 20 at 17:37