Click here to Skip to main content
15,890,512 members
Home / Discussions / C#
   

C#

 
QuestionInet in C# ? Pin
youssef2-Oct-04 14:18
youssef2-Oct-04 14:18 
AnswerRe: Inet in C# ? Pin
eggie52-Oct-04 16:25
eggie52-Oct-04 16:25 
GeneralRe: Inet in C# ? Pin
youssef3-Oct-04 0:01
youssef3-Oct-04 0:01 
AnswerRe: Inet in C# ? Pin
Nnamdi Onyeyiri3-Oct-04 0:00
Nnamdi Onyeyiri3-Oct-04 0:00 
GeneralRe: Inet in C# ? Pin
youssef3-Oct-04 0:46
youssef3-Oct-04 0:46 
AnswerRe: Inet in C# ? Pin
Salil Khedkar4-Oct-04 20:57
Salil Khedkar4-Oct-04 20:57 
AnswerRe: Inet in C# ? Pin
youssef5-Oct-04 12:50
youssef5-Oct-04 12:50 
QuestionA timer func problem??? Pin
cemlouis2-Oct-04 14:08
cemlouis2-Oct-04 14:08 
Hi,

I have the below code which runs after choosing an item from the listbox (choose the first one). Goes to the below item after 5 seconds and then goes to another after 5 sec again... So here is my question: I have a func which I named as process() I want to run this func only once when each item is selected in the listbox? So how can I do that???

Thank you,
Cem Louis

<br />
<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
using System.Timers;<br />
using System.Threading;<br />
<br />
namespace WindowsApplication14<br />
{<br />
	/// <br />
	/// Summary description for Form1.<br />
	/// <br />
	public class Form1 : System.Windows.Forms.Form<br />
	{<br />
		private System.Windows.Forms.ListBox listBox1;<br />
		private System.Windows.Forms.Button button1;<br />
		private System.Timers.Timer timerClock = new System.Timers.Timer();<br />
		/// <br />
		/// Required designer variable.<br />
		/// <br />
		private System.ComponentModel.Container components = null;<br />
<br />
		public Form1()<br />
		{<br />
			//<br />
			// Required for Windows Form Designer support<br />
			//<br />
			InitializeComponent();<br />
			InitializeTimer();<br />
<br />
			//<br />
			// TODO: Add any constructor code after InitializeComponent call<br />
			//<br />
		}<br />
<br />
		public void InitializeTimer()<br />
		{<br />
			this.timerClock.Elapsed += new ElapsedEventHandler(OnTimer);<br />
			this.timerClock.Interval = 5000;<br />
		}<br />
<br />
		/// <br />
		/// Clean up any resources being used.<br />
		/// <br />
		protected override void Dispose( bool disposing )<br />
		{<br />
			if( disposing )<br />
			{<br />
				if (components != null) <br />
				{<br />
					components.Dispose();<br />
				}<br />
			}<br />
			base.Dispose( disposing );<br />
		}<br />
<br />
		#region Windows Form Designer generated code<br />
		/// <br />
		/// Required method for Designer support - do not modify<br />
		/// the contents of this method with the code editor.<br />
		/// <br />
		private void InitializeComponent()<br />
		{<br />
			this.listBox1 = new System.Windows.Forms.ListBox();<br />
			this.button1 = new System.Windows.Forms.Button();<br />
			this.SuspendLayout();<br />
			// <br />
			// listBox1<br />
			// <br />
			this.listBox1.Location = new System.Drawing.Point(8, 8);<br />
			this.listBox1.Name = "listBox1";<br />
			this.listBox1.Size = new System.Drawing.Size(120, 95);<br />
			this.listBox1.TabIndex = 0;<br />
			// <br />
			// button1<br />
			// <br />
			this.button1.Location = new System.Drawing.Point(8, 112);<br />
			this.button1.Name = "button1";<br />
			this.button1.Size = new System.Drawing.Size(120, 23);<br />
			this.button1.TabIndex = 1;<br />
			this.button1.Text = "Run";<br />
			this.button1.Click += new System.EventHandler(this.button1_Click);<br />
			// <br />
			// Form1<br />
			// <br />
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
			this.ClientSize = new System.Drawing.Size(136, 142);<br />
			this.Controls.Add(this.button1);<br />
			this.Controls.Add(this.listBox1);<br />
			this.Name = "Form1";<br />
			this.Text = "Form1";<br />
			this.Load += new System.EventHandler(this.Form1_Load);<br />
			this.ResumeLayout(false);<br />
<br />
		}<br />
		#endregion<br />
<br />
		/// <br />
		/// The main entry point for the application.<br />
		/// <br />
		[STAThread]<br />
		static void Main() <br />
		{<br />
			Application.Run(new Form1());<br />
		}<br />
<br />
		private void Form1_Load(object sender, System.EventArgs e)<br />
		{<br />
			listBox1.Items.Add("Arthur");<br />
			listBox1.Items.Add("Alex");<br />
			listBox1.Items.Add("Amie");<br />
			listBox1.Update();<br />
		}<br />
<br />
		private void OnTimer(object source, ElapsedEventArgs e)<br />
		{<br />
			this.nextvalue(this.listBox1.SelectedIndex);<br />
		}<br />
<br />
		private void button1_Click(object sender, System.EventArgs e)<br />
		{<br />
			if(this.listBox1.SelectedItem!=null)<br />
			{<br />
				this.timerClock.Start();<br />
			}<br />
			else<br />
			{<br />
				MessageBox.Show("Select an Item");<br />
			}<br />
		}<br />
<br />
		private void nextvalue(int currentPosition)<br />
		{<br />
			if(currentPosition+1<=this.listBox1.Items.Count-1)<br />
			{<br />
				this.listBox1.SetSelected(currentPosition+1,true);<br />
			}<br />
			else<br />
			{<br />
				this.timerClock.Stop();<br />
			}<br />
		}<br />
<br />
		private void process()<br />
		{<br />
			// Does something in an 5 second interval<br />
			// Must run once<br />
		}<br />
	}<br />
}<br />

AnswerRe: A timer func problem??? Pin
partyganger2-Oct-04 16:21
partyganger2-Oct-04 16:21 
Questionadding to the byte[] ? Pin
SniperED0072-Oct-04 10:00
SniperED0072-Oct-04 10:00 
AnswerRe: adding to the byte[] ? Pin
Nnamdi Onyeyiri2-Oct-04 23:58
Nnamdi Onyeyiri2-Oct-04 23:58 
GeneralColor of Column Headers in a DataGrid Pin
MarkMokris2-Oct-04 7:44
MarkMokris2-Oct-04 7:44 
GeneralRe: Color of Column Headers in a DataGrid Pin
sreejith ss nair3-Oct-04 19:50
sreejith ss nair3-Oct-04 19:50 
GeneralBest way to store and access Global variables Pin
Zapss2-Oct-04 3:02
Zapss2-Oct-04 3:02 
GeneralRe: Best way to store and access Global variables Pin
Colin Angus Mackay2-Oct-04 4:00
Colin Angus Mackay2-Oct-04 4:00 
GeneralRe: Best way to store and access Global variables Pin
Andres Coder3-Oct-04 6:14
Andres Coder3-Oct-04 6:14 
GeneralDesign Optimization Pin
sreejith ss nair2-Oct-04 2:56
sreejith ss nair2-Oct-04 2:56 
GeneralRe: Design Optimization Pin
Colin Angus Mackay2-Oct-04 4:11
Colin Angus Mackay2-Oct-04 4:11 
GeneralRe: Design Optimization Pin
sreejith ss nair2-Oct-04 18:43
sreejith ss nair2-Oct-04 18:43 
GeneralRe: Design Optimization Pin
Nnamdi Onyeyiri2-Oct-04 12:14
Nnamdi Onyeyiri2-Oct-04 12:14 
GeneralRe: Design Optimization Pin
sreejith ss nair2-Oct-04 18:43
sreejith ss nair2-Oct-04 18:43 
GeneralRe: Design Optimization Pin
hatim_ali3-Oct-04 19:33
hatim_ali3-Oct-04 19:33 
GeneralRe: Design Optimization Pin
sreejith ss nair3-Oct-04 19:48
sreejith ss nair3-Oct-04 19:48 
GeneralRe: Design Optimization Pin
Dave Kreskowiak4-Oct-04 7:07
mveDave Kreskowiak4-Oct-04 7:07 
Generalimage.saveadd function Pin
hudhud2-Oct-04 2:52
hudhud2-Oct-04 2:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.