ImagesBrowserUserControl.cs
Description du code
ImagesBrowserUserControl.cs est un fichier du projet BrolExplorer.Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/brolexplorer/.
Projet BrolExplorer :
Explorateur de media en CSharp.
Code source ou contenu du fichier
Code c# (ImagesBrowserUserControl.cs) (288 lignes)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using System.IO; using be.gaudry.explorer.model; using be.gaudry.photobrol.view.controls; using be.gaudry.events; using be.gaudry.model.enums; using be.gaudry.model.drawing; namespace be.gaudry.explorer.view.controls { public partial class ImagesBrowserUserControl : UserControl { #region constructor and declarations private DirectoryInfo dirInfo; private bool imageFilterModeOn; private BrolImage img; //private ImageEditorUserControl imageEditor; public ImagesBrowserUserControl() { imageFilterModeOn = false; InitializeComponent(); /*SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true);*/ } #endregion #region properties [ Category("Action"), Browsable(true), Description("An event called on image selected on the bottom panel") ] public event FileSelectedEventHandler FileSelected; /// <summary> /// Show Desktop node /// </summary> [ Category("Image filter options"), Description("Show the image filter tools") ] public bool ImageFilterModeOn { get { return imageFilterModeOn; } set { imageFilterModeOn = !value;//toogle will set a not conversion toggleImageFilterMode(); //this.Invalidate(); } } #endregion #region public methods public void setContextMenuStrip(ContextMenuStrip cms) { if (cms != null) { mainPBPanel.ContextMenuStrip = cms; } } public void setThumbsForDirectory(String dirPath) { if (!Directory.Exists(dirPath)) return; /*foreach (Control oldThumb in previewFLP.Controls) { oldThumb.Dispose(); }*/ initThumbPreviews(); showProgressPanel(true); previewFLP.SuspendLayout(); thumbBGW.RunWorkerAsync(); } private void initThumbPreviews() { mainTLP.Controls.Remove(previewFLP); mainTLP.Controls.Add(previewFLP, 0, 3); previewFLP.AutoScroll = true; previewFLP.AutoSize = true; previewFLP.BackColor = System.Drawing.SystemColors.Window; mainTLP.SetColumnSpan(previewFLP, 2); previewFLP.Dock = System.Windows.Forms.DockStyle.Fill; previewFLP.WrapContents = false; } private void toggleImageFilterMode() { imageFilterModeOn = !imageFilterModeOn; if (imageFilterModeOn) { mainTLP.ColumnStyles[0].Width = 0F; mainTLP.ColumnStyles[1].Width = 100F; imageEditorUC.BrolImage = img; } else { mainTLP.ColumnStyles[0].Width = 100F; mainTLP.ColumnStyles[1].Width = 0F; } this.Invalidate(); } #endregion #region private browse image methods private void loadImage(String imgPath) { if (mainPB.Image != null) { mainPB.Image.Dispose(); //GC.Collect(); } mainPB.ImageLocation = imgPath;//must do this to set image infos img.FullPath = imgPath; mainPB.Image = img.Image; if (FileSelected != null) FileSelected(this, imgPath); if (img.Width > mainPB.Width || img.Height > mainPB.Height) { mainPB.SizeMode = PictureBoxSizeMode.Zoom; } else { mainPB.SizeMode = PictureBoxSizeMode.CenterImage; } if (imageFilterModeOn) { imageEditorUC.BrolImage = img; } } private void image_Click(object sender, String path) { if (!String.Empty.Equals(path)) { loadImage(path); } } #endregion #region thumb generation private void thumbBGW_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker bgw = sender as BackgroundWorker; addThumbs(bgw, e); } private void addThumbs(BackgroundWorker bgw, DoWorkEventArgs e) { try { FileInfo[] fi = dirInfo.GetFiles(); int filesCount = 0; int imagesCount = 0; int max = fi.Length; //ThumbDBLib.ThumbDB t = new ThumbDBLib.ThumbDB(Path.Combine(dirInfo.FullName,"thumbs.db")); //Image i; ThumbUserControl pb = null; foreach (FileInfo f in fi) { if (bgw.CancellationPending) { e.Result = String.Format("Affichage incomplet... {0} images sur un total de {1} fichiers, dont {2} fichiers analysés", imagesCount, max, filesCount); e.Cancel = true; return; } if (ImageHelper.isImg(f.Name)) { imagesCount++; pb.MouseOutBackgroundColor = previewFLP.BackColor; /*i = t.GetThumbnailImage(f.FullName); if (i != null) { pb.setImage(i, f.FullName); } else {*/ pb.ImageLocation = f.FullName; //i = Image.FromFile(f.FullName); //pb.setImage(ImageUtils.toThumbnailHighQuality(i, 134, 78), f.FullName); //i.Dispose(); //} } else { //insert default icon ??? //result = new object[] { f.Name, null }; pb = null; } } e.Result = String.Format("{0} images sur un total de {1} fichiers analysés, et {2} répertoires", imagesCount, filesCount, dirInfo.GetDirectories().Length); } catch (UnauthorizedAccessException) { e.Result = "Impossible de lire le répertoire : Accès refusé"; } catch (Exception ex) { e.Result = String.Format("Erreur de lecture du répertoire : {0}", ex.Message); ; } } private void thumbBGW_ProgressChanged(object sender, ProgressChangedEventArgs e) { if (e.ProgressPercentage > 0) { thumbGeneratorPB.Value = e.ProgressPercentage; if (e.UserState != null) { Object[] results = e.UserState as object[]; //if (results != null) //{ thumbFileNameLbl.Text = e.ProgressPercentage.ToString(); if (results.Length > 1) { previewFLP.Controls.Add((ThumbUserControl)results[1]); } //} } } else if (e.ProgressPercentage == (int)BGWORKER.dirSizeInfo) { if (e.UserState != null) { Object[] results = e.UserState as object[]; if (results != null) { thumbGeneratorPB.Maximum = (Int32)results[0]; } } } } private void thumbBGW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { thumbFileNameLbl.Text = e.Result.ToString(); showProgressPanel(false); previewFLP.ResumeLayout(); } private void showProgressPanel(bool show) { /*foreach (Control c in progressThumbPanel.Controls) { c.Visible = show; }*/ //progressThumbPanel.Visible = show; cancelThumbGeneratorBtn.Visible = show; thumbGeneratorPB.Value = 0; thumbGeneratorPB.Visible = show; //mainTLP.RowStyles[1].Height = 0F; //mainTLP.RowStyles[1].Height = 30F; } private void cancelThumbGeneratorBtn_Click(object sender, EventArgs e) { thumbBGW.CancelAsync(); } #endregion } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Pas de sous-répertoires. | |||
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1732385535 23/11/2024 19:12:15 |
Utilisation de l'explorateur de code
- Navigation :
- Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
- Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
- La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
- Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
- Affichage :
- Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
- Actions :
- Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/10/2009, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/cs-brolexplorer-source-rf-view/controls/ImagesBrowserUserControl.cs.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.