Winfrom Loop to play a picture

Source: Internet
Author: User

Nothing new, just traverse and match the file name and get the object, and put it in PictureBox.

Select the picture you want to see in the ListView and click the View button to make the ↓ code.

if (ListView1.SelectedItems.Count > 0)            {                string name = Listview1.items[listview1.selectedindices[0]]. text;//selected file name                string dpath = fname.substring (0, fname.lastindexof ("\ \"));//Remove filename                DirectoryInfo dti = new  DirectoryInfo (Dpath);                fileinfo[] File = dti. GetFiles (name);//Find a picture with the same name as                Bitmap bmp = new Bitmap (file[0]. FullName);                pictureBox1.Image = bmp;                Picturebox1.refresh ();                GETGRIDV (name);            }            else {MessageBox.Show ("Please select a picture to view first"       
Loop playback

Loop play is performed by the thread, because with the process execution, he will always execute the loop of the picture and cannot do anything else.

To start the thread execution method in the method, you need to add Control.checkforillegalcrossthreadcalls = False in the construct;

Then just click on the button to create and open the thread

if (run==null)
{
Thread td = New Thread (Xunhuan);
Td. Start ();
}

       inti =0; BOOLBF =true;//Determine if playback is pausedstringRun =NULL;//used to determine if a thread is running Public  voidXunhuan () {Run="Run"; if(ListView1.SelectedItems.Count >0)//If the ListView has a check, start the loop from the selected item            {                                 while(true)                {                    if(!BF) {                         Break; }                    if(I >=listView1.Items.Count) {i=0;  Break; }                    if(I >= listview1.selectedindices[0]) {cycle (i);//Loading PicturesSystem.Threading.Thread.Sleep ( -); } I++; }            }            if(i = =0)            {                intj =0;  while(true)                {                    if(!BF) {                         Break; }                    if(J >=listView1.Items.Count) {J=0; }                    //Listview1.items[j]. Focused = true;cycle (LISTVIEW1.ITEMS[J).                    Text); System.Threading.Thread.Sleep ( -); J++; }            }        }

There is also a flashback loop, which is basically the same as above, and is executed by the thread to determine if bool is paused.

private void Daoxu ()
{
Run = "Daorun";
int dx = ListView1.Items.Count;
if (ListView1.SelectedItems.Count > 0)//If the ListView has a check, start looping from the selected item
{
while (true)
{
if (!BF)
{
Break
}
if (DX < 0)
{
Break
}
if (dx <= listview1.selectedindices[0])
{
cycle (dx);//Load Picture
System.Threading.Thread.Sleep (300);
}
dx--;
}
}
if (dx = = ListView1.Items.Count)
{
int j = listview1.items.count-1;
while (true)
{
if (!BF)
{
Break
}
if (J < 0)
{
Break
}
LISTVIEW1.ITEMS[J]. Focused = true;
Cycle (LISTVIEW1.ITEMS[J). Text);
System.Threading.Thread.Sleep (300);
j--;
}
}
}

Click Change BF Properties to change playback status

if (BF)
{
BF = false;//Stop
Btn_pause. Text = "Stop";
}
Else
{
BF = true;//Playback
Btn_pause. Text = "Play";
Run = null;
}

Winfrom Loop to play a picture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.