I have two DateTimePickers one as Start Time and other one as end time.
I also have a text box that has duration.
I would like to know how can I add the duration to start time datetimePicker to automatically get the end time in the endTime dateTimePicker?
Though I believe your Service Duration is a combobox, I've still used textbox as per your question.
Call textchanged. When text in textbox changes, the time is added to dateTimePicker2
private void textBox1_TextChanged(object sender, EventArgs e)
{
int mins = Convert.ToInt32(textBox1.Text);
dateTimePicker2.Value = dateTimePicker1.Value.AddMinutes(mins);
}
For combobox, call textchanged as well.
private void comboBox1_TextChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == -1 || comboBox1.Text == null)
{
dateTimePicker2.Value = dateTimePicker1.Value;
}
else if (comboBox1.Text == "15")
{
dateTimePicker2.Value = dateTimePicker1.Value.AddMinutes(15);
}
else if (comboBox1.Text == "30")
{
dateTimePicker2.Value = dateTimePicker1.Value.AddMinutes(30);
}
else if (comboBox1.Text == "60")
{
dateTimePicker2.Value = dateTimePicker1.Value.AddMinutes(60);
}
}
Related
I'm trying to load information with worker and using reportprogress to update progress bar until finshing, but the worker stop working and doesn't finish the for loop or continue after several minutes. I don't know what's the problem and I tried every post here I can find related to this problem and didn't get anything. I hope I can finally get an answer posting my problem here.
Here's the relevant code:
public class Class1
{
public BackgroundWorker unit_read_data_setting_Worker;
public Class1()
{
unit_read_data_setting_Worker = new BackgroundWorker();
unit_read_data_setting_Worker.WorkerReportsProgress = true;
unit_read_data_setting_Worker.WorkerSupportsCancellation = false;
unit_read_data_setting_Worker.DoWork += new DoWorkEventHandler(unit_read_data_setting);
unit_read_data_setting_Worker.ProgressChanged += new ProgressChangedEventHandler(_update_progress);
unit_read_data_setting_Worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Completed);
}
public void unit_read_data_setting(object sender = null, DoWorkEventArgs e = null)
{
lock (FamilyTreeViewModel.Lock_ParameterList)
{
ObservableCollection<Parameter_UC_ViewModel> _internal_parameter_list =
FamilyTreeViewModel.GetInstance.ParameterList;
if (FamilyTreeViewModel.GetInstance.SelectedUnitSetting != null)
{
if (_internal_parameter_list.Count > 0)
{
for (int i = 0; i < _internal_parameter_list.Count; i++)
{
int startValue = i * 100 / _internal_parameter_list.Count;
unit_read_data_setting_Worker.ReportProgress(startValue);
// do stuff related to the index
// when progress_bar at 76 value, the loop stoppes and cotinue after a minute
}
}
}
}
}
private void _update_progress(object sender, ProgressChangedEventArgs e)
{
FamilyTreeViewModel.GetInstance.Unit_read_data_setting_progress_bar = e.ProgressPercentage;
}
private void Completed(object sender, RunWorkerCompletedEventArgs e)
{
// never gets here but there's no error
}
}
I have a windows form it has 8 textboxes , 3 combobox and a radio button.
I am using this code but it does not work.
I put the beakpoint and checked the control does not go inside if(Cnt is TextBox) It is evaluating to false. I am keeping all the controls in the panel. May be because of this I am having a problem
private void button1_Click(object sender, EventArgs e)
{
foreach (Control cnt in this.Controls)
{
if (cnt is TextBox)
{
if (cnt.Text == "")
{
MessageBox.Show("TextBox is Blank.");
cnt.BackColor = Color.Pink;
}
}
else if (cnt is ComboBox)
{
ComboBox cmb = (ComboBox)cnt;
if (cmb.SelectedItem == null)
{
MessageBox.Show("Combox is not Selected.");
cnt.BackColor = Color.Plum;
}
}
}
}
I am trying to make a sound play with the timer goes to 3, 2, 1.
My timer starts at ten and has a three second delay. If I use the following code:
if (tl.myCoolTimer == 10)
{
print("Play Sound");
myAudioSource.Play();
}
It plays the Beep over and over again until the game starts and the counter goes below 10.
If I use the code:
if (tl.myCoolTimer == 3)
{
print("Play Sound");
myAudioSource.Play();
}
It doesn't play the sound at all. It doesn't even print the print statement.
I literally only changed the number. I am not sure why this isn't working.
I have also tried setting it to 3f to see if it is a float issue.
Timer Scripts
This is the starting Timer. it counts down to 3 (then the game starts)
public Text startGameTimerText;
public float startGameTimer = 3;
public void Start ()
{
startGameTimerText = GetComponent<Text> ();
}
public void Update ()
{
startGameTimer -= Time.deltaTime;
startGameTimerText.text = startGameTimer.ToString ("f1");
if (startGameTimer < 0) {
GameObject.Find ("GameStartTimer").SetActive (false);
}
}
This is the Game Timer It starts at 10 and counts down to 0.
public StartGameTimer gt; //this is the script the other timer is on
public Text timerText;
public float myCoolTimer = 10;
public void Start ()
{
timerText = GetComponent<Text> ();
}
public void Update ()
{
if (gt.startGameTimer > 0) {
myCoolTimer = 10;
} else {
myCoolTimer -= Time.deltaTime;
timerText.text = myCoolTimer.ToString ("f1");
}
}
Thanks Joe for the help. Here was my final answer. I know it is hacked, but I haven't figured out the Invoke thing yet. When I set the into it kept playing the entire time it was at "3", so i need to make it play only once.
private AudioSource myAudioSource;
public bool isSoundPlayed;
void Start()
{
myAudioSource = GetComponent<AudioSource>();
isSoundPlayed = false;
}
void Update()
{
if((int)tl.myCoolTimer == 3)
{
if (isSoundPlayed == false)
{
myAudioSource.Play();
isSoundPlayed = true;
}
return;
}
if ((int)tl.myCoolTimer == 2)
{
if (isSoundPlayed == true)
{
myAudioSource.Play();
isSoundPlayed = false;
}
return;
}
if ((int)tl.myCoolTimer == 1)
{
if (isSoundPlayed == false)
{
myAudioSource.Play();
isSoundPlayed = true;
}
return;
}
}
I tried to get the code below working, but to no avail.
I have to make a login window, and except from the Log in button I want by pressing the Enter key in password textbox the result to be the same. C# 2010.
private void button1_Click(object sender, EventArgs e)
{
int ok=0;
if (textBox1.Text == "administrator" && textBox2.Text == "administrator")
{
ok = 1;
this.Hide();
Admin admin = new Admin();
admin.ShowDialog();
}
if (textBox1.Text == "jucator" && textBox2.Text == "jucator")
{
ok = 1;
this.Hide();
}
if (ok == 0)
{
label2.Text = "nume user sau parola incorecta";
label2.Visible = true;
}
}
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
button1_Click(this, new EventArgs());
}
}
You should use the KeyUp event It's more reliable in you case.
Then check for the pressed key.
e.g.:
private void textBox2_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
//DoLogin... in your case it would be
button1_Click(null,null);
e.Handled = true;
}
else
{
e.Handled = false;
}
}
On a side note: I really discourage you to use that Log In method, comparing strings to a hardcoded strings is really a waste, there're better scenarios specially in an environment where you have multiple users Otherwise why would you require a login?
How to change text of a cell at runtime in XtraReport?
I am using "DevExpress v2011 vol 1".
I have a few cells and I can change their text one by one using PreviewClick event as below.
private void _cell_PreviewClick(object sender, PreviewMouseEventArgs e)
{
e.Brick.Text = "aaabbbccc"; e.PreviewControl.Refresh();
}
But, in that event I need to change text of other cells simultaneously. I tried below and got no luck
private void _cell_PreviewClick(object sender, PreviewMouseEventArgs e)
{
e.Brick.Text = "aaabbbcc";
otherCell1.Text = "rrrttcwwww"
e.PreviewControl.Refresh();
}
Best Regards,
Orgil.D
You can handle the DataSourceRowChanged event of the XtraReport Class
private void rpt_DataSourceRowChanged(object sender, DataSourceRowEventArgs e)
{
MyClass xx = bidingSource[e.CurrentRow] as MyClass ;
if (string.IsNullOrWhiteSpace(xx.WorkDescription))
{
xrTableCell25.Visible = false;
xrTableRow3.Visible = false;
xrTableCell25.Text = "456";
}
else
{
xrTableCell25.Visible = true;
xrTableRow3.Visible = true;
xrTableCell25.Text = "123";
}
}