Click here to Skip to main content
15,911,476 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please anybody help how can is how picture in picturebox and store in the database ????

how can i define ""rand"" in these lines it showing the ertor
pictureBox2.Left = rand.Next(Math.Max(0, Bounds.Width - pictureBox.Width))

please see the bold sentances

C#
private void Form_Load(object sender, EventArgs e)
{
    moveTimer.Interval = 1000;
    moveTimer.Tick += new EventHandler(moveTimer_Tick);
    moveTimer.Start();
}
private void moveTimer_Tick(object sender, System.EventArgs e)
{
    string[] images = Directory.GetFiles(@"C:\Dir", "*.jpg");
    image = Image.FromFile(images[counter]);
    pictureBox.Width = image.Width;
    pictureBox.Height = image.Height;
    pictureBox.Image = image;

    // Move Image to new location
    pictureBox2.Left = rand.Next(Math.Max(0, Bounds.Width - pictureBox.Width));//////ERROR ERROR 
    pictureBox2.Top = rand.Next(Math.Max(0, Bounds.Height - pictureBox.Height));////ERROR ERROR 

    if (counter < images.Count - 1)//ERROR OPERATOR - CANnot be applied to operands of type method group and int
    {
        counter = counter + 1;
    }
    else
    {
        counter = 0;
    }
}
Posted
Updated 4-Oct-12 22:19pm
v2

1 solution

Ok, there are a couple of problems here:
The second one is easy:
C#
if (counter < images.Count - 1)//ERROR OPERATOR - CANnot be applied to operands of type method group and int
images is an array of strings, so it doesn't have a Count property - it has a Length instead. The reason you get the error message you do is that all arrays implement IEnumerable, so the Linq extension method Count<type of IEnumerable>() is being assumed.
Change it to images.Length and it should be fine.

Your first I can't sort immediately - you don't tell us what the error is, and it could be anything! :laugh:



"how can i use "rand" in that winform , what should be declare for this "rand " ????????"


Declare it at class level:
C#
private Random rand = new Random();
You could declare it locally, but then it doesn't necessarily provide such random results. Using a single class level instance means that the sequence is normally more random than a local Random definition.
 
Share this answer
 
v2
Comments
Kay Pee Singh 5-Oct-12 4:14am    
how can i use "rand" in that winform , what should be declare for this "rand " ????????
OriginalGriff 5-Oct-12 4:18am    
Answer updated
Kay Pee Singh 5-Oct-12 5:35am    
yeah its working but not on the time interval i want to show on regular interval so tell me what to change in code
OriginalGriff 5-Oct-12 5:43am    
Sorry, I'm not sure what your problem is. Remember I can't see your screen, or access you HDD - I only get what you tell me here!
Try explaining what is happening, and exactly what you want to happen.
Kay Pee Singh 5-Oct-12 6:30am    
yeah i know that i mean to say that when i executing my window application at that time the picture is showing on the picture box but not working on regular interval i want to show my picture on regular interval like an slideshow in picture box but i did not use button i want when my window application then in picture box the image should be updated on regular interval . i made application where taking screenshot on regular interval and i want to show that screenshots in that picture box on regular interval and i also used timer and the interval is 100 i also made the thread

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900