473,769 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Timer and Random

hi,
i have a WELCOME screen. here i have a PICTURE BOX. there are 8 pictures
that go into this Picture Box.

At every 5 seconds i want to RANDOMLY load a new Picture.
this is what i am using but it is not loading the new picture.
Can any one help?
public void Presentation_Lo ad(object sender, System.EventArg s e)
{
Timer timer1= new Timer();
timer1.Interval = 5000;
timer1.Enabled = true;
timer1.Tick += new System.EventHan dler (OnTimerEvent);
}

public static void OnTimerEvent(ob ject source, EventArgs e)
{
// 8 pictures
Random objRandom= new Random();
int num= objRandom.Next( 1,8);

Presentation obj= new Presentation(); /// presentation is the name of
the class
if(num.ToString ()=="1")
{
obj.DisplayCRMI nfo(); ///// this function is as below
obj.Refresh();
return;
}
////// 7 more ifs follow
}

public void DisplayCRMInfo( )
{
string picture = Application.Sta rtupPath +@"\Presentatio n\CRM.jpg";
pictureBox1.Ima ge = Image.FromFile( picture);
}

Nov 17 '05 #1
3 6078
Hi VenuGupal,

It's not terribly clear to me what you are actually doing. Are you running all code inside a WinForm class called Presentation? If so, why are you creating a new Presentation on every tick?

Also, in your tick event, you might benefit from using a switch/case instead of if/else if to find out which random number you got, or even better, store all pictures addresses in an string array and load the picture without checking which number it is.

int num = objRandom.Next( 1,8);
pictureBox1.Pic ture = Image.FromFile( pictureAddresse s[num] );
On Mon, 11 Jul 2005 09:34:01 +0200, VenuGopal <Ve*******@disc ussions.microso ft.com> wrote:
hi,
i have a WELCOME screen. here i have a PICTURE BOX. there are 8 pictures
that go into this Picture Box.

At every 5 seconds i want to RANDOMLY load a new Picture.
this is what i am using but it is not loading the new picture.
Can any one help?
public void Presentation_Lo ad(object sender, System.EventArg s e)
{
Timer timer1= new Timer();
timer1.Interval = 5000;
timer1.Enabled = true;
timer1.Tick += new System.EventHan dler (OnTimerEvent);
}

public static void OnTimerEvent(ob ject source, EventArgs e)
{
// 8 pictures
Random objRandom= new Random();
int num= objRandom.Next( 1,8);
Presentation obj= new Presentation(); /// presentation is the name of
the class
if(num.ToString ()=="1")
{
obj.DisplayCRMI nfo(); ///// this function is as below
obj.Refresh();
return;
}
////// 7 more ifs follow
}

public void DisplayCRMInfo( )
{
string picture = Application.Sta rtupPath +@"\Presentatio n\CRM.jpg";
pictureBox1.Ima ge = Image.FromFile( picture);
}


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #2
Hi Venu,

OnTimerEvent(ob ject source, EventArgs e), method is not a static method, its
a reference method.

public void OnTimerEvent(ob ject source, EventArgs e)
{
// 8 pictures
Random objRandom= new Random();
int num= objRandom.Next( 1,8);

Presentation obj= new Presentation(); /// presentation is the name of
//the class
if(num.ToString ()=="1")
{
obj.DisplayCRMI nfo(); ///// this function is as below
obj.Refresh();
return;
}
////// 7 more ifs follow
}

try it now ... GoodLuck... Veera Sekhar...

"VenuGopal" wrote:
hi,
i have a WELCOME screen. here i have a PICTURE BOX. there are 8 pictures
that go into this Picture Box.

At every 5 seconds i want to RANDOMLY load a new Picture.
this is what i am using but it is not loading the new picture.
Can any one help?
public void Presentation_Lo ad(object sender, System.EventArg s e)
{
Timer timer1= new Timer();
timer1.Interval = 5000;
timer1.Enabled = true;
timer1.Tick += new System.EventHan dler (OnTimerEvent);
}

public static void OnTimerEvent(ob ject source, EventArgs e)
{
// 8 pictures
Random objRandom= new Random();
int num= objRandom.Next( 1,8);

Presentation obj= new Presentation(); /// presentation is the name of
the class
if(num.ToString ()=="1")
{
obj.DisplayCRMI nfo(); ///// this function is as below
obj.Refresh();
return;
}
////// 7 more ifs follow
}

public void DisplayCRMInfo( )
{
string picture = Application.Sta rtupPath +@"\Presentatio n\CRM.jpg";
pictureBox1.Ima ge = Image.FromFile( picture);
}

Nov 17 '05 #3
hi Morten,
thanks for ur help. As u suggested i am using a ARRAY and loading the
images. it is working very well.
thanks once again.
"Morten Wennevik" wrote:
Hi VenuGupal,

It's not terribly clear to me what you are actually doing. Are you running all code inside a WinForm class called Presentation? If so, why are you creating a new Presentation on every tick?

Also, in your tick event, you might benefit from using a switch/case instead of if/else if to find out which random number you got, or even better, store all pictures addresses in an string array and load the picture without checking which number it is.

int num = objRandom.Next( 1,8);
pictureBox1.Pic ture = Image.FromFile( pictureAddresse s[num] );
On Mon, 11 Jul 2005 09:34:01 +0200, VenuGopal <Ve*******@disc ussions.microso ft.com> wrote:
hi,
i have a WELCOME screen. here i have a PICTURE BOX. there are 8 pictures
that go into this Picture Box.

At every 5 seconds i want to RANDOMLY load a new Picture.
this is what i am using but it is not loading the new picture.
Can any one help?
public void Presentation_Lo ad(object sender, System.EventArg s e)
{
Timer timer1= new Timer();
timer1.Interval = 5000;
timer1.Enabled = true;
timer1.Tick += new System.EventHan dler (OnTimerEvent);
}

public static void OnTimerEvent(ob ject source, EventArgs e)
{
// 8 pictures
Random objRandom= new Random();
int num= objRandom.Next( 1,8);
Presentation obj= new Presentation(); /// presentation is the name of
the class
if(num.ToString ()=="1")
{
obj.DisplayCRMI nfo(); ///// this function is as below
obj.Refresh();
return;
}
////// 7 more ifs follow
}

public void DisplayCRMInfo( )
{
string picture = Application.Sta rtupPath +@"\Presentatio n\CRM.jpg";
pictureBox1.Ima ge = Image.FromFile( picture);
}


--
Happy coding!
Morten Wennevik [C# MVP]

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2682
by: Todd | last post by:
I have an ASP.NET application and I would like to have some code run on the server automatically once a day at a specified time. I create a timer thread to call a simple callback in the Application_Start method. It seems to call the callback once or twice while the application starts up but appears to stop once the default page is displayed. Here is the code below (from Global.asax.cs): public static void ProcessAccounts (object state)...
4
336
by: Todd | last post by:
I have an ASP.NET application and I would like to have some code run on the server automatically once a day at a specified time. I create a timer thread to call a simple callback in the Application_Start method. It seems to call the callback once or twice while the application starts up but appears to stop once the default page is displayed. Here is the code below (from Global.asax.cs): public static void ProcessAccounts (object state)...
8
522
by: Todd | last post by:
I have an ASP.NET application and I would like to have some code run on the server automatically once a day at a specified time. I create a timer thread to call a simple callback in the Application_Start method. It seems to call the callback once or twice while the application starts up but appears to stop once the default page is displayed. Here is the code below (from Global.asax.cs): public static void ProcessAccounts (object state)...
7
2152
by: Grahmmer | last post by:
I have a few timers that are added to a form at runtime. I can handle the event fine, but I cannot identify which timer fired. Is there a way to do this? Timer Creation: ------------- ....some code... Dim usersTimers(4) As System.Windows.Forms.Timer For i = 0 To 4
0
9583
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10039
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5297
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3955
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.