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

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.IO;
  9. using be.gaudry.explorer.model;
  10. using be.gaudry.photobrol.view.controls;
  11. using be.gaudry.events;
  12. using be.gaudry.model.enums;
  13. using be.gaudry.model.drawing;
  14.  
  15. namespace be.gaudry.explorer.view.controls
  16. {
  17. public partial class ImagesBrowserUserControl : UserControl
  18. {
  19. #region constructor and declarations
  20. private DirectoryInfo dirInfo;
  21. private bool imageFilterModeOn;
  22. private BrolImage img;
  23. //private ImageEditorUserControl imageEditor;
  24.  
  25. public ImagesBrowserUserControl()
  26. {
  27. imageFilterModeOn = false;
  28. img = new BrolImage();
  29. InitializeComponent();
  30. /*SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw |
  31.   ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true);*/
  32. }
  33. #endregion
  34.  
  35. #region properties
  36.  
  37.  
  38. [
  39. Category("Action"),
  40. Browsable(true),
  41. Description("An event called on image selected on the bottom panel")
  42. ]
  43. public event FileSelectedEventHandler FileSelected;
  44.  
  45. /// <summary>
  46. /// Show Desktop node
  47. /// </summary>
  48. [
  49. Category("Image filter options"),
  50. Description("Show the image filter tools")
  51. ]
  52. public bool ImageFilterModeOn
  53. {
  54. get
  55. {
  56. return imageFilterModeOn;
  57. }
  58. set
  59. {
  60. imageFilterModeOn = !value;//toogle will set a not conversion
  61. toggleImageFilterMode();
  62. //this.Invalidate();
  63. }
  64. }
  65. #endregion
  66.  
  67. #region public methods
  68. public void setContextMenuStrip(ContextMenuStrip cms)
  69. {
  70. if (cms != null)
  71. {
  72. mainPBPanel.ContextMenuStrip = cms;
  73. }
  74. }
  75. public void setThumbsForDirectory(String dirPath)
  76. {
  77. if (!Directory.Exists(dirPath))
  78. return;
  79. /*foreach (Control oldThumb in previewFLP.Controls)
  80.   {
  81.   oldThumb.Dispose();
  82.   }*/
  83. initThumbPreviews();
  84. dirInfo = new DirectoryInfo(dirPath);
  85.  
  86. showProgressPanel(true);
  87. previewFLP.SuspendLayout();
  88. thumbBGW.RunWorkerAsync();
  89. }
  90.  
  91. private void initThumbPreviews()
  92. {
  93. mainTLP.Controls.Remove(previewFLP);
  94. previewFLP = new System.Windows.Forms.FlowLayoutPanel();
  95. mainTLP.Controls.Add(previewFLP, 0, 3);
  96.  
  97. previewFLP.AutoScroll = true;
  98. previewFLP.AutoSize = true;
  99. previewFLP.BackColor = System.Drawing.SystemColors.Window;
  100.  
  101. mainTLP.SetColumnSpan(previewFLP, 2);
  102.  
  103. previewFLP.Dock = System.Windows.Forms.DockStyle.Fill;
  104. previewFLP.WrapContents = false;
  105. }
  106. private void toggleImageFilterMode()
  107. {
  108. imageFilterModeOn = !imageFilterModeOn;
  109. if (imageFilterModeOn)
  110. {
  111. mainTLP.ColumnStyles[0].Width = 0F;
  112. mainTLP.ColumnStyles[1].Width = 100F;
  113. imageEditorUC.BrolImage = img;
  114. }
  115. else
  116. {
  117. mainTLP.ColumnStyles[0].Width = 100F;
  118. mainTLP.ColumnStyles[1].Width = 0F;
  119. }
  120. this.Invalidate();
  121. }
  122. #endregion
  123.  
  124. #region private browse image methods
  125. private void loadImage(String imgPath)
  126. {
  127. if (mainPB.Image != null)
  128. {
  129. mainPB.Image.Dispose();
  130. //GC.Collect();
  131. }
  132. mainPB.ImageLocation = imgPath;//must do this to set image infos
  133. img.FullPath = imgPath;
  134. mainPB.Image = img.Image;
  135. if (FileSelected != null)
  136. FileSelected(this, imgPath);
  137. if (img.Width > mainPB.Width || img.Height > mainPB.Height)
  138. {
  139. mainPB.SizeMode = PictureBoxSizeMode.Zoom;
  140. }
  141. else
  142. {
  143. mainPB.SizeMode = PictureBoxSizeMode.CenterImage;
  144. }
  145. if (imageFilterModeOn)
  146. {
  147. imageEditorUC.BrolImage = img;
  148. }
  149. }
  150.  
  151. private void image_Click(object sender, String path)
  152. {
  153. if (!String.Empty.Equals(path))
  154. {
  155. loadImage(path);
  156. }
  157. }
  158. #endregion
  159.  
  160. #region thumb generation
  161. private void thumbBGW_DoWork(object sender, DoWorkEventArgs e)
  162. {
  163. BackgroundWorker bgw = sender as BackgroundWorker;
  164. addThumbs(bgw, e);
  165. }
  166.  
  167. private void addThumbs(BackgroundWorker bgw, DoWorkEventArgs e)
  168. {
  169. try
  170. {
  171. FileInfo[] fi = dirInfo.GetFiles();
  172. int filesCount = 0;
  173. int imagesCount = 0;
  174. int max = fi.Length;
  175. bgw.ReportProgress((int)BGWORKER.dirSizeInfo, new object[] { (Int32)fi.Length });
  176. //ThumbDBLib.ThumbDB t = new ThumbDBLib.ThumbDB(Path.Combine(dirInfo.FullName,"thumbs.db"));
  177. //Image i;
  178. ThumbUserControl pb = null;
  179. foreach (FileInfo f in fi)
  180. {
  181. if (bgw.CancellationPending)
  182. {
  183. e.Result = String.Format("Affichage incomplet... {0} images sur un total de {1} fichiers, dont {2} fichiers analysés", imagesCount, max, filesCount);
  184. e.Cancel = true;
  185. return;
  186. }
  187.  
  188. if (ImageHelper.isImg(f.Name))
  189. {
  190. imagesCount++;
  191. pb = new ThumbUserControl(imagesCount);
  192. pb.MouseOutBackgroundColor = previewFLP.BackColor;
  193.  
  194. /*i = t.GetThumbnailImage(f.FullName);
  195.   if (i != null)
  196.   {
  197.   pb.setImage(i, f.FullName);
  198.   }
  199.   else
  200.   {*/
  201. pb.ImageLocation = f.FullName;
  202. //i = Image.FromFile(f.FullName);
  203. //pb.setImage(ImageUtils.toThumbnailHighQuality(i, 134, 78), f.FullName);
  204. //i.Dispose();
  205. //}
  206. pb.thumbClick += new ThumbUserControl.OnThumbClickHandler(this.image_Click);
  207. }
  208. else
  209. {
  210. //insert default icon ???
  211. //result = new object[] { f.Name, null };
  212. pb = null;
  213.  
  214. }
  215. bgw.ReportProgress(++filesCount, new object[] { imagesCount, pb });
  216. }
  217. e.Result = String.Format("{0} images sur un total de {1} fichiers analysés, et {2} répertoires", imagesCount, filesCount, dirInfo.GetDirectories().Length);
  218. }
  219. catch (UnauthorizedAccessException)
  220. {
  221. e.Result = "Impossible de lire le répertoire : Accès refusé";
  222. }
  223. catch (Exception ex)
  224. {
  225. e.Result = String.Format("Erreur de lecture du répertoire : {0}", ex.Message); ;
  226. }
  227. }
  228.  
  229. private void thumbBGW_ProgressChanged(object sender, ProgressChangedEventArgs e)
  230. {
  231. if (e.ProgressPercentage > 0)
  232. {
  233. thumbGeneratorPB.Value = e.ProgressPercentage;
  234. if (e.UserState != null)
  235. {
  236. Object[] results = e.UserState as object[];
  237. //if (results != null)
  238. //{
  239. thumbFileNameLbl.Text = e.ProgressPercentage.ToString();
  240. if (results.Length > 1)
  241. {
  242. previewFLP.Controls.Add((ThumbUserControl)results[1]);
  243. }
  244. //}
  245. }
  246. }
  247. else if (e.ProgressPercentage == (int)BGWORKER.dirSizeInfo)
  248. {
  249.  
  250. if (e.UserState != null)
  251. {
  252. Object[] results = e.UserState as object[];
  253. if (results != null)
  254. {
  255. thumbGeneratorPB.Maximum = (Int32)results[0];
  256. }
  257. }
  258. }
  259. }
  260.  
  261. private void thumbBGW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  262. {
  263. thumbFileNameLbl.Text = e.Result.ToString();
  264. showProgressPanel(false);
  265. previewFLP.ResumeLayout();
  266. }
  267.  
  268. private void showProgressPanel(bool show)
  269. {
  270. /*foreach (Control c in progressThumbPanel.Controls)
  271.   {
  272.   c.Visible = show;
  273.   }*/
  274. //progressThumbPanel.Visible = show;
  275. cancelThumbGeneratorBtn.Visible = show;
  276. thumbGeneratorPB.Value = 0;
  277. thumbGeneratorPB.Visible = show;
  278. //mainTLP.RowStyles[1].Height = 0F;
  279. //mainTLP.RowStyles[1].Height = 30F;
  280. }
  281.  
  282. private void cancelThumbGeneratorBtn_Click(object sender, EventArgs e)
  283. {
  284. thumbBGW.CancelAsync();
  285. }
  286. #endregion
  287. }
  288. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/brolexplorer/view/controls/ 
IcôneNomTailleModification
Pas de sous-répertoires.
IcôneNomTailleModification
| _ Répertoire parent0 octets1718711299 18/06/2024 13:48:19
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/brolexplorer/view/controls/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .resx|.resxThumbUserControl.resx5.68 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .cs|.csSearchMediaUserControl.Designer.cs52.01 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .cs|.csImagesBrowserUserControl.cs9.69 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .cs|.csExplorerUserControl.cs38.67 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .cs|.csExplorerUserControl.Designer.cs44.73 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .resx|.resxExplorerUserControl.resx15.83 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .resx|.resxImagesBrowserUserControl.resx6.06 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .cs|.csImagesBrowserUserControl.Designer.cs10.53 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .cs|.csThumbUserControl.Designer.cs3.29 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .resx|.resxSearchMediaUserControl.resx7.72 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .cs|.csSearchMediaUserControl.cs25.76 Ko31/10/2018 18:32:50-refusé-
Afficher le fichier .cs|.csThumbUserControl.cs4.7 Ko31/10/2018 18:32:50-refusé-

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.

Document créé le 30/10/2009, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/cs-brolexplorer-source-rf-view/controls/ImagesBrowserUserControl.cs.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.