Small white C # form Series-03. Picture Viewer

Source: Internet
Author: User
Tags bmp image

New drag-and-drop function if there is no visible situation tomorrow will be good, OK, we go to the point, as a hanging wire, if you use your girlfriend/goddess photos made a picture browser, then every time you use to look at the picture of the first look at her, when you see the second picture you want to see, is there a sharp contrast? Is the gap or what, it is different from each other ~ ~ began to fantasize about it? Haha, no nonsense, continue: 4 Walk ~ ~ ~ Software Download (. NET 4.0 framework) http://pan.baidu.com/s/1i387wJ7 "source see below" Inverse Day picture viewer 1.0.1 Download HTTP://PAN.BAIDU.COM/S/1 o6hlrx4 "New drag function" one, design drawings:
Second, Code Analysis: (In a hurry to write, wrote a quick 50 minutes, if there is no detailed explanation can ask)
1, open the specified picture Openfilediaog control, first set the filter, and then open the picture, displayed on the PictureBox      OpenFileDialog  Openfile = new openfiledialog ();         openfile.filter  =  jpg image (*.jpg) |*.jpg|png image (*.png) |*.png|bmp image (*.bmp) |*.bmp| all formats (*. *) |*.* ";         openFile.Title =  "Inverse day only allows you to open a picture";         if  (Openfile.showdialog ()  == dialogresult.ok)     {         string filePath = openFile.FileName;                 showphoto (filePath,  Pictureboxsizemode.zoom);//Call the method that displays the picture---method see below                  int lastindex = filepath.lastindexof (@ "\");                  paths = directory.getfiles (Filepath.substring (0, lastIndex );//really get the directory of all the files in the path     } 2, cross-border smart alert put a lable above, do not visible=false, with the set to true, and then set the Next button to automatically hide the display      private void mainform_load (Object sender, eventargs e)     {        lbl1. visible = false;//Smart Tips Default not visible     }      #region   button display and hide         public void visiblefalse ()          {             pbtnleft.visible = false;                         pbtnRight.Visible = false;         }  &Nbsp;      public void visibletrue ()          {            pbtnleft.visible  = true;                         pbtnRight.Visible = true;         }         private void  Pbtnleft_mouseleave (object sender, eventargs e)          {            visiblefalse ();         }        private void  Pbtnright_mouseleave (object sender, eventargs e)          {     &nbsP;      visiblefalse ();        }         private void picturebox1_mouseleave (Object sender,  eventargs e)         {             visibletrue ();        }       #endregion   3, top display pictures   pinned is topmost, display pictures because it is very common to encapsulate a method       //  pinned     if  (topmost1. Checked == false)     {        this. Topmost = false;        topmost1. text =  "      windows   body   set   Top";    }     else    {        this. topmost = true;        topmost1. text =  "      pick   eliminate   reset   top";     }  / /Show Picture     public void showphoto (String filepath, pictureboxsizemode  mode)//pictureboxsizemode  Enumeration type (how to display)     {         pictureBox1.ImageLocation = filePath;          picturebox1.sizemode = mode;    } 4, keyboard control switch This is on the mainform_. KeyDown event, if you want to put it in PictureBox then remember to focus on      private void mainform_keydown ( OBJECT SENDER, KEYEVENTARGS E)//Trigger button     {         if  (e.keycode == keys.left | |  E.KEYCODE == KEYS.UP)//prev         {             getleft ();        }          if  (e.keycode == keys.right | |  e.keycode == keys.down)//Next         {             getright ();         }         if  (e.control == true  && E.KEYCODE == KEYS.S)         {             savephoto ();         }    }  
5, the mode of the slide is the timer control +random, produce a random array (subscript), according to the random number to display, the timer control, every 1 seconds to call the next method "?? Note that the timer is turned on and off, do not cast resources will become more and more card!!! "     //Sequential play _________________________________________________________________________ _______________    if  (sequence. Checked == true)     {        timer2. enabled = true;                         timer2. Start ();                         sequence. text =  "      fetch   eliminate   broadcast   put";    }     else    {        sequence. text =  "      Shun   order   broadcast   put";                          timer2. Stop ();     }  private void timer2_tick (object sender,  EVENTARGS E)//Sequential play {    getright ();}     public void getright ()   //next {    try     {        i++;                         if  (I >= paths. Length)         {             i = 0;                                  lbl1. Visible = true;                                  Timer1. enabled = true;//Saving Resources                          timer1. Start ();        }                 showphoto (paths[i], pictureboxsizemode.zoom);     }    catch    {         timer2. Stop ();                         sequence. text =  "      Shun   order   broadcast   put";                          messagebox.show ("Pro, you haven't right-click to open the picture!") ", " "counter-day Friendship Reminder");     }}      //Reverse play ________________________ ________________________________________________________________    try     {        if  (random. Checked == true)         {             timer3. enabled = true;                                  Timer3. Start ();                              &nbSp;  random. text =  "      fetch   eliminate   broadcast   put";         }        else         {            timer3. Stop ();                                random. text =  "      with     broadcast   release";         }     }    catch    {             messagebox.show ("Pro, are you sure you've opened the picture?") ", ", "anti-day Friendship Reminder");     }      private void timer3_ Tick (object sender, eventargs e)//Random play  &Nbsp;  {        try         {            random r = new  random ();                             int n = r.next (0,  paths. Length);                             picturebox1.imagelocation = paths[ N];        }        catch         {             timer3. Stop ();                              random. text =  "      with     broadcast   release";                              messagebox.show ("Pro, you haven't opened the picture yet!") ");        }    }   6, the picture can be saved using the Savafile control , set the filter, get the saved picture name, create an object for image to receive the picture on the PictureBox, Image.sava () on the [if you want to save the image after the rotation, right-click Save or Ctrl+s]           savefiledialog savafile = new savefiledialog ();                      savaFile.Filter =  jpg image (*.jpg) |*.jpg|png image (*.png) |*.png|bmp image (*.bmp) |*.bmp| all formats (*. *) |*. *";  //Filter                     savaFile.Title =  "loved this picture";                     if  ( Savafile.showdialog ()  == dialogresult.ok)         {             string name =  savafile.filename;                             Image image =  picturebox1.image;                            image. Save (name);        }  7, Picture full screen The idea is this, set the form border style to none, and then make the form maximized       this. Formborderstyle = system.windows.forms.formborderStyle.none;               this. windowstate = formwindowstate.maximized;              8, picture rotation function system comes with Image.rotateflip (RotateFlipType) method, after use, remember Picturebox1.refresh ()       //counter-clockwise turn      picturebox1.image.rotateflip (ROTATEFLIPTYPE.ROTATE90FLIPXY);                  Picturebox1.refresh ()        //clockwise turn          picturebox1.image.rotateflip (Rotatefliptype.rotate90flipnone);                 picturebox1.refresh ();  9, shallow description           pictures deleted and rotated after you save the rotated image just next time.          I was going to get a pull-out. The optimization of the hidden, time problem next time to do it (after 8 period)  10, the exception must be in place              a program big bug can not have!          It's not a program, it's not a bug, but you didn't find bug!          in the process of opening more attention, to consider each if else, the instantiation of the object when the object is not instantiated into account, you can save a lot of things           Many enumerated types of things do not need to remember, you can not remember the time to play a "space" he came out automatically 11, ★ added: Drag function           Add this sentence when the form loads: This.pictureBox1.AllowDrop = true;           picturebox two events: DragEnter (occurs when dragging)  dragdrop (occurs when dragging is complete)      #region  picturebox Support drag-and-drop     private void picturebox1_dragenter (object  sender, drageventargs e)     {         if  (E.data.getdatapresent (dataformats.filedrop))         {              e.Effect =  dragdropeffects.link;         }         else         {              e.Effect = DragDropEffects.None;          }    }         Private void picturebox1_dragdrop (object sender, drageventargs e)      {        string filename =  ((System.Array) e.Data.GetData (DataFormats.FileDrop)). GetValue (0). ToString ();                 Showphoto (filename, pictureboxsizemode.zoom);//Call the method of displaying the picture                  int lastindex = filename.lastindexof (@ "\");                 paths =  directory.getfiles (filename.substring (0, lastindex));//really get the path to all files in this directory                  this.pictureBox1.Image =  Image.FromFile (fileName);    &nbsp. #endregion   Third, source sharing: Http://pan.baidu.com/s/13vSXC
Iv. video sharing: etc ~ ~ This issue recommended: 23 Design Patterns (pdf+ source) {supplement} Next issue: The small system of the name series (Jane Single

Small white C # form Series-03. Picture Viewer

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.