Take some beautiful pictures with a new digital camera and download them to the computer, what can you do next? Oh, you can use the dexterous "virtual album" to manage your collections. You can drag the pictures directly from the Explorer to the photo album, you can also edit the picture title in the text box below the picture. The data of the album is stored in an XML file. "Virtual Album" allows you to print the current page in the album. The lower side is a UML description of the virtual album form.
This article covers two-way "virtual album" use .NET technology.
1. How to implement the trail from the resource manager to the form
2. How to use XML characteristics correctly, read, write, filter, and update data.
It is easy to achieve drag and drop on the resource manager. When dragging the content to the form, you just care about the dragging before you are in progress. First, you need to set the form of the allowDrop property to true so that the form can receive the drag object, and then we change the style of the mouse to "Copy Drop" through the DrageNter event. PRIVATE VOID FORM1_DRAGENTER (Object sender, system.windows e) {e.effect = DragDropeffects.copy; // set the cursor to show a drop copy}
Next, you need to use the DragDrop event to handle the mouse drag to the object on the form. This event detects whether drag DataFormat is fileDrop, if yes, remove the file name. Then use this file name to load the picture and display it to the corresponding PictureBox. private void Form1_DragDrop (object sender, System.Windows.Forms.DragEventArgs e) {string theFile; try {if (e.Data.GetDataPresent (DataFormats.FileDrop)) {object filename = e.Data.GetData (DataFormats.FileDrop); Thefile = (STRING) ((STRING) ((STRING) ((STRING) .GetValue (0); LoadPictureBox (Thefile, EX, EY); // Load the image using the path name →}}} catch (exception ex) {MessageBox. Show (ex.Message.toString ());}} The use of XML XML is the database existing in memory, and its work and data set is very similar. Easy contacts between XML and .NET objects, you can almost perform all necessary data operations in the DataSet. The code below reads the data into a page of the data to the virtual album. First, use the READXML function to read the data from the XML file to the data object, then read from the data object and display them in the form. Void readpage () {ds.clear (); if (file.exists ("albumdata.xml")) {ds.readxml ("albumdata.xml"); readpageFromDataSet ();} Pagenumberlabel.text = (CurrentPage 1) .Tostring (); currentlabel = null; currentLabelIndex = -1; textBox1.visible = false;} In the readpageFromDataSet method, a length of four can be performed. Each data is filtered each time you follow the selection criteria. And display them into the form.
Void readpageFromDataSet () {dataable dt = ds.tables ["album"]; dataView DV = New DataView (DT); for (int i = 0; i <4; i ) {// set up a filter to filter out A SINGLE ROW Using The position of the image and the page number dv.rowfilter = "Page =" "and position =" i.toString (); if (DV.count> 0) // Check To see if a row exists {data; "]fename"]. TOSTRING ()); labels [i] .text = DRV ["" ] .Tostring ();} else {// clear out image pictures [i] .image = null; labels [i] .text = "";}}} Insert a picture is equally simple in the XML database. The following code will check the data set to see if there is a picture that needs to be inserted. If there is, an existing image data file will be updated, otherwise, you will insert a new image data into the XML data file using the powerful classes included in the data set.
void InsertTheImage (string theFile) {// try to find the image row from the Position and Page we are inserting the image into DataTable dt = ds.Tables [ "Album"]; DataView dv = new DataView (dt); dv.RowFilter = "Page =" CurrentPage.toString () "and position =" currentPosition.tostring (); // check to see reason the row exists if (DV.count> 0) {// Image Row EXISTS, UPDATE IT . DATAROWVIEW DRV = DV [0]; Object Primarykey = DRV ["ID"]; // update the dataset using the primary key to find the particular row contact the Image Datarow drfound = dt.rows.find (new object [] { PrimaryKey}; drfound ["imagename"] = thefile; drfound ["caption"] = labels [currentposition] .text;} else {// its a new page and position, Insert It Into the Dataset DataRow Dr = DT.NEWROW (); DR ["ID"] = DR ["imagename"] = thefile; DR ["position"] = currentposition; DR ["page"] = currentpage; DR ["CAPTION"] = Labels [currentPosition] .Text; dt.rows.ad D (DR);} // Write out the new data to the XML Database DS.WriteXML ("AlbumData.xml");} Conclusion Using .NET, it is very convenient to perform data operation, you can use XML and data sets from Select specific information, classify XML data files, or even calculate the data in the XML file. When there is a lot of data in memory, if you want to use the data to use the data to use data, use XML perhaps the most efficient method. This article covers two-way "virtual album" use .NET technology.
1. How to implement the trail from the resource manager to the form
2. How to use XML characteristics correctly, read, write, filter, and update data.
It is easy to achieve drag and drop on the resource manager. When dragging the content to the form, you just care about the dragging before you are in progress. First, you need to set the form of the allowDrop property to true so that the form can receive the drag object, and then we change the style of the mouse to "Copy Drop" through the DrageNter event. private void Form1_DragEnter (object sender, System.Windows.Forms.DragEventArgs e) {e.Effect = DragDropEffects.Copy; // set the cursor to show a drop copy} below, need to process the event DragDrop drag the mouse to form The object is on. This event detects whether drag DataFormat is fileDrop, if yes, remove the file name. Then use this file name to load the picture and display it to the corresponding PictureBox. private void Form1_DragDrop (object sender, System.Windows.Forms.DragEventArgs e) {string theFile; try {if (e.Data.GetDataPresent (DataFormats.FileDrop)) {object filename = e.Data.GetData (DataFormats.FileDrop); Thefile = (STRING) ((STRING) ((STRING) ((STRING) .GetValue (0); LoadPictureBox (Thefile, EX, EY); // Load the image using the path name →}}} catch (exception ex) {MessageBox. Show (ex.Message.toString ());}} The use of XML XML is the database existing in memory, and its work and data set is very similar. Easy contacts between XML and .NET objects, you can almost perform all necessary data operations in the DataSet. The code below reads the data into a page of the data to the virtual album. First, use the READXML function to read the data from the XML file to the data object, then read from the data object and display them in the form. Void readpage () {ds.clear (); if (file.exists ("albumdata.xml")) {ds.readxml ("albumdata.xml"); readpageFromDataSet ();} Pagenumberlabel.text = (CurrentPage 1) .Tostring (); currentlabel = null; currentLabelIndex = -1; textBox1.visible = false;} In the readpageFromDataSet method, a length of four can be performed. Each data is filtered each time you follow the selection criteria. And display them into the form.
Void readpageFromDataSet () {dataable dt = ds.tables ["album"]; dataView DV = New DataView (DT); for (int i = 0; i <4; i ) {// set up a filter to filter out A SINGLE ROW Using The position of the image and the page number dv.rowfilter = "Page =" "and position =" i.toString (); if (DV.count> 0) // Check To see if a row exists {data; "]fename"]. TOSTRING ()); labels [i] .text = DRV ["" ] .Tostring ();} else {// clear out image pictures [i] .image = null; labels [i] .text = "";}}} Insert a picture is equally simple in the XML database. The following code will check the data set to see if there is a picture that needs to be inserted. If there is, an existing image data file will be updated, otherwise, you will insert a new image data into the XML data file using the powerful classes included in the data set.