Timer instantely stops - c#

Hi I have 2 questions.
My timer stops immediately and if it doesn't it does not pick up the given interval.
CODE:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ClashRoyaleHack
{
public partial class GoldCMD : Form
{
public GoldCMD()
{
InitializeComponent();
timer2.Interval = 10000;
timer2.Tick += new EventHandler(timer2_Tick);
timer2.Start();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void timer2_Tick(object sender, EventArgs e)
{
this.Close();
}
}
}
On creating the code I notices a slight difference. I am using almost identical forms with the same content but different names and different timer names etc. But one does work with the timer and same code (using ofcourse different names for the timer and form etc) but the other doesn't...
Really weird. Hopefully you guys can help me out. The code above does not have the private void GoldCMD_Load(object sender, EventArgs e) But just the normal private void GoldCMD(object sender, EventArgs e) maybe that has something to do with it.
Code of the one that does work:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ClashRoyaleHack
{
public partial class GemsCMD : Form
{
public GemsCMD()
{
InitializeComponent();
}
private void GemsCMD_Load(object sender, EventArgs e)
{
timer1.Interval = 7500;
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
this.Close();
}
}
}

The Solution:
It is conceivable that the timer may "tick" once upon starting and considering your code closes it immediately after a tick, it is likely the source of your issue. Otherwise if that is not the reasoning, then you are still killing it at its first tick regardless of time.

Related

Autoplay video on windows form

i am new to .net i am having trouble playing videos automatically. I would be showing different textboxes here but i want the video to autplay without any buttons
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WMPLib;
namespace ThinkQDisplay
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
{
AxWindowsMediaPlayer1.URL = "C:\Users\Ramrod\Documents\Visual Studio 2012\Projects\ThinkQDisplay\ThinkQDisplay\sample.avi";
}
}
}
It keeps telling it is an unrecognized escape sequence. Also I would like to have a separate form (form2). Where I can choose what to play here on form 1. Is it also possible to have it looped?
private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = #"C:\Users\Ramrod\Documents\Visual Studio 2012\Projects\ThinkQDisplay\ThinkQDisplay\sampler.avi";
}
private void Form1_Load(object sender, EventArgs e)
{
axWindowsMediaPlayer1.settings.autoStart = true;
}
}
}

Multiform DataGridView and DetailView Issues

I am trying to make a multiform application that takes a DataGridView of table attributes and shows them in a DetailView upon the click of a button. When I click the button and the second form opens it is empty. Then if I close the second form I get 'An unhandled exception of type 'System.NullReferenceException' occurred'. Here is my code:
Form 1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MultiForm
{
public partial class Form1 : Form2
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'personnelDataSet.employee' table. You can move, or remove it, as needed.
this.employeeTableAdapter.Fill(this.personnelDataSet.employee);
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnDetails_Click(object sender, EventArgs e)
{
Form2 dForm = new Form2();
dForm.ShowDialog();
this.tableAdapterManager.UpdateAll(this.personnelDataSet);
}
}
}
Form 2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MultiForm
{
public partial class Form2 : Form
{
//public Form2()
//{
// InitializeComponent();
//}
private void employeeBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.employeeBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.personnelDataSet);
}
private void Form2_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'personnelDataSet.employee' table. You can move, or remove it, as needed.
this.employeeTableAdapter.Fill(this.personnelDataSet.employee);
}
}
}
I get the exception on form 1 at this.tableAdapterManager.UpdateAll(this.personnelDataSet); Any help would be greatly appreciated.
Didn't drag in the data components into the tray duh... Sorry guys.

How can I interrupt playing of text to speech synthesis in my application?

This is the code that I used to speech a richTextBox. My problem is that I can't click on anything when the text is playing. I can't even stop playing. How can I fix the problem? Is there any way to stop playing by clicking on a button?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Synthesis;
namespace Merger
{
public partial class Form1 : Form
{
SpeechSynthesizer tell = new SpeechSynthesizer();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
tell.Rate = trackBar1.Value;
}
private void Form1_Resize(object sender, EventArgs e)
{
this.Refresh();
}
private void pictureBox2_Click(object sender, EventArgs e)
{
tell.Volume = 100;
tell.Speak(richTextBox1.SelectedText);
}
private void trackBar1_ValueChanged(object sender, EventArgs e)
{
tell.Rate = trackBar1.Value;
}
private void button1_Click(object sender, EventArgs e)
{
tell.SpeakAsyncCancelAll();
}
}
}
The problem is that the Speak() method is Synchronous, so it will lock the thread you're on. Assuming you're on a single thread, that will be the UI thread, thus locking anything you're doing.
You might perhaps be better using a different thread to Speak(), which won't lock your current (UI) thread.
SpeechSynthesizer.Speak Method (String) - MSDN
Or you can use the SpeechAsync method, which will do it asyncronously!
SpeechSynthesizer.SpeakAsync Method (String) - MSDN

How Do I Use DisplayLabel.Text In Visual C#?

I'm trying to make certain text appear in the label when a button is clicked, but I always get the error `The name DisplayLabel does not exist in the current context. This is my Code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Chapter_2_HW
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void sinisterButton_Click(object sender, EventArgs e)
{
MessageBox.Show("Left");
}
private void mediumButton_Click(object sender, EventArgs e)
{
}
private void dexterButton_Click(object sender, EventArgs e)
{
}
private void instructionLabel_Click(object sender, EventArgs e)
{
}
private void translateLabel_Click(object sender, EventArgs e)
{
DisplayLabel.Text = "Goodbye";
}
}
}

Multiple form not showing up

I'm trying to make a multiWindowsForm.
Just to try how it is working I started with a a simple form that I added a button to. When clicking on it, another window should pop up. But I can't get it to work. It crashes with error:
Object reference not set to an instance of an object!
I used Project → Add → Windows form and named it Mupp.cs
Here's my code for Form1.cs :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MultiForm
{
public partial class tryout : Form
{
public tryout()
{
InitializeComponent();
}
Mupp theMupp;
private void Form1_Load(object sender, EventArgs e)
{
theMupp = new Mupp();
}
private void button1_Click(object sender, EventArgs e)
{
theMupp.Show();
}
}
}
What can I have missed out on?
It looks like the load event is not firing and thus not initilising your object. Make sure that the load event is hooked up.
Alternatively, initialise in the click event.
private void button1_Click(object sender, EventArgs e)
{
using (Mupp theMupp = new Mupp())
{
theMupp.ShowDialog();
}
}
I hope this helps.
public tryout()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}

Categories

Resources