如何以固定的间隔在图片框中显示图片并存储在数据库中? [英] how can i show picture in picturebox on regular interval and store in database ?

查看:55
本文介绍了如何以固定的间隔在图片框中显示图片并存储在数据库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请大家帮忙,如何将图片框中的图片和存储到数据库中????

我如何在这些行中定义显示"ertor"的"rand"?
pictureBox2.Left = rand.Next(Math.Max(0,Bounds.Width-pictureBox.Width))

请看粗体字

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

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;
    }
}

推荐答案

好,这里有两个问题:
第二个很简单:
Ok, there are a couple of problems here:
The second one is easy:
if (counter < images.Count - 1)//ERROR OPERATOR - CANnot be applied to operands of type method group and int

images 是一个字符串数组,因此它没有Count属性-而是有一个Length.收到错误消息的原因是所有数组都实现了IEnumerable,因此假定使用Linq扩展方法Count<type of IEnumerable>().
将其更改为images.Length,应该没问题.

您的第一个我无法立即进行排序-您没有告诉我们错误是什么,可能是 任何事情 ! :laugh:



我如何在该Winform中使用" rand,应为此" rand"????????"声明什么


在课堂上声明:

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:

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.


这篇关于如何以固定的间隔在图片框中显示图片并存储在数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆