Geen cache-versie.

Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

ImageCombo.cs

Description du code

ImageCombo.cs est un fichier du projet BrolDev.
Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/broldev/src/.

Projet BrolDev : Librairie de composants réutilisables pour les applications BrolDev en CSharp.

Code source ou contenu du fichier

  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using be.gaudry.model.drawing;
  6.  
  7. namespace be.gaudry.view.controls
  8. {
  9. public class ImageComboBox : ComboBox
  10. {
  11. #region constructors and declarations
  12. private ImageList imageList;
  13. private ContentAlignment textAlignment;
  14. private ContentAlignment imageAlignment;
  15. private StringFormat stringFormat;
  16. private SolidBrush solidBrush;
  17. private bool allowDuplicates, allowTextEdition;
  18.  
  19. public ImageComboBox()
  20. {
  21. this.DrawMode = DrawMode.OwnerDrawFixed;
  22. textAlignment = ContentAlignment.MiddleLeft;
  23. imageAlignment = ContentAlignment.MiddleLeft;
  24. solidBrush = new SolidBrush(this.ForeColor);
  25. stringFormat = new StringFormat();
  26. //this.DropDownStyle = ComboBoxStyle.DropDown;
  27. setAlignment();
  28. }
  29.  
  30. #endregion
  31.  
  32. #region Attributes
  33. /// <summary>
  34. /// Specifies alignment of text on the drawing surface.
  35. /// </summary>
  36. [
  37. Category("ImageComboBox"),
  38. Browsable(true),
  39. Description("Specifies alignment of text on the drawing surface."),
  40. DefaultValue(ContentAlignment.MiddleLeft)
  41. ]
  42. public ContentAlignment TextAlignment
  43. {
  44. get{return textAlignment;}
  45. set{textAlignment = value;}
  46. }
  47. /// <summary>
  48. /// Specifies alignment of the image on the drawing surface.
  49. /// </summary>
  50. [
  51. Category("ImageComboBox"),
  52. Browsable(true),
  53. Description("Specifies alignment of the image on the drawing surface."),
  54. DefaultValue(ContentAlignment.MiddleLeft)
  55. ]
  56. public ContentAlignment ImageAlignment
  57. {
  58. get{return imageAlignment;}
  59. set{imageAlignment = value;}
  60. }
  61. /// <summary>
  62. /// Gets or sets the <code>ImageList</code> to use.
  63. /// </summary>
  64. [
  65. Category("ImageComboBox"),
  66. Browsable(true),
  67. Description("Provides methods to manage a collection of System.Drawing.Image objects."),
  68. DefaultValue(null)
  69. ]
  70. public ImageList ImageList
  71. {
  72. get{return imageList;}
  73. set{imageList = value;}
  74. }
  75. /// <summary>
  76. /// Allows duplicates in the collection of values
  77. /// Default value is true(quickest).
  78. /// </summary>
  79. [
  80. Category("ImageComboBox"),
  81. Browsable(true),
  82. Description("Allows duplicates in the collection of values (quickest)."),
  83. DefaultValue(true)
  84. ]
  85. public bool AllowDuplicates
  86. {
  87. get { return allowDuplicates; }
  88. set { allowDuplicates = value; }
  89. }
  90. /// <summary>
  91. /// Allows text edition.
  92. /// Default value is false.
  93. /// </summary>
  94. [
  95. Category("ImageComboBox"),
  96. Browsable(true),
  97. Description("Allows text edition."),
  98. DefaultValue(false)
  99. ]
  100. public bool AllowTextEdition
  101. {
  102. get { return allowTextEdition; }
  103. set { allowTextEdition = value; }
  104. }
  105. /// <summary>
  106. /// Gets or sets the text that is selected in the editable portion of a <code>be.gaudry.view.controls.ImageComboBox</code>.
  107. /// </summary>
  108. [
  109. Category("ImageComboBox"),
  110. Browsable(false),
  111. Description("Gets or sets the text that is selected in the editable portion of a be.gaudry.view.controls.ImageComboBox."),
  112. DefaultValue(null)
  113. ]
  114. public String SelectedInnerText
  115. {
  116. get { return (SelectedItem!=null)?SelectedItem.ToString():null; }
  117. set
  118. {
  119. if (string.Empty.Equals(value))
  120. return;
  121. int j = Items.Count;
  122. for (int i = 0; i > j; i++)
  123. {
  124. if ((value).Equals(((ImageComboBoxItem)Items[i]).Text))
  125. {
  126. SelectedIndex = i;
  127. return;
  128. }
  129. }
  130. }
  131. }
  132. #endregion
  133.  
  134. #region private methods
  135. private void setAlignment()
  136. {
  137. //Horizontal align
  138. if (this.TextAlignment == ContentAlignment.BottomLeft ||
  139. this.TextAlignment == ContentAlignment.MiddleLeft ||
  140. this.TextAlignment == ContentAlignment.TopLeft
  141. )
  142. stringFormat.Alignment = StringAlignment.Near;
  143.  
  144. if (this.TextAlignment == ContentAlignment.BottomCenter ||
  145. this.TextAlignment == ContentAlignment.MiddleCenter ||
  146. this.TextAlignment == ContentAlignment.TopCenter
  147. )
  148. stringFormat.Alignment = StringAlignment.Center;
  149.  
  150. if (this.TextAlignment == ContentAlignment.BottomRight ||
  151. this.TextAlignment == ContentAlignment.MiddleRight ||
  152. this.TextAlignment == ContentAlignment.TopRight
  153. )
  154. stringFormat.Alignment = StringAlignment.Far;
  155.  
  156. //Vertical align
  157. if (this.TextAlignment == ContentAlignment.BottomCenter ||
  158. this.TextAlignment == ContentAlignment.BottomLeft ||
  159. this.TextAlignment == ContentAlignment.BottomRight
  160. )
  161. stringFormat.LineAlignment = StringAlignment.Far;
  162.  
  163. if (this.TextAlignment == ContentAlignment.TopCenter ||
  164. this.TextAlignment == ContentAlignment.TopLeft ||
  165. this.TextAlignment == ContentAlignment.TopRight
  166. )
  167. stringFormat.LineAlignment = StringAlignment.Near;
  168.  
  169. if (this.TextAlignment == ContentAlignment.MiddleCenter ||
  170. this.TextAlignment == ContentAlignment.MiddleLeft ||
  171. this.TextAlignment == ContentAlignment.MiddleRight
  172. )
  173. stringFormat.LineAlignment = StringAlignment.Center;
  174. }
  175. #endregion
  176.  
  177. #region public methods
  178. /// <summary>
  179. /// todo
  180. /// </summary>
  181. /// <param name="text"></param>
  182. public void addItem(String text)
  183. {
  184. //create a new item
  185. throw new NotImplementedException();
  186. }
  187. /// <summary>
  188. /// Add a new item, and select an image from the imagelist
  189. /// </summary>
  190. /// <param name="text"></param>
  191. /// <param name="imageId"></param>
  192. public void addItem(String text, int imageId)
  193. {
  194. ImageComboBoxItem iCBI = new ImageComboBoxItem(text, imageId);
  195. if (!allowDuplicates && Items.Contains(iCBI))
  196. return;
  197. Items.Add(iCBI);
  198. }
  199. /// <summary>
  200. /// todo
  201. /// </summary>
  202. /// <param name="text"></param>
  203. /// <param name="image"></param>
  204. public void addItem(String text, Image image)
  205. {
  206. //add image in the imagelist
  207. //create a new item
  208. if (imageList == null)
  209. {
  210. imageList = new ImageList();
  211. }
  212. image = ImageHelper.getResized(image, ImageList.ImageSize.Width, ImageList.ImageSize.Height);
  213. int i = imageList.Images.AddStrip(image);
  214. addItem(text, i);
  215. }
  216. /// <summary>
  217. /// todo
  218. /// </summary>
  219. /// <param name="text"></param>
  220. public void pushItem(String text)
  221. {
  222. //create a new item
  223. throw new NotImplementedException();
  224. }
  225. public void pushItem(String text, int imageId)
  226. {
  227. ImageComboBoxItem iCBI = new ImageComboBoxItem(text, imageId);
  228. if (!allowDuplicates && Items.Contains(iCBI))
  229. Items.Remove(iCBI);
  230. Items.Insert(0, iCBI);
  231. }
  232.  
  233. public void pushItem(String text, Image image)
  234. {
  235. //add image in the imagelist
  236. //create a new item
  237. throw new NotImplementedException();
  238. }
  239. /// <summary>
  240. /// Add the current text as first item, set the image index,
  241. /// and set this item as selected
  242. /// </summary>
  243. /// <param name="imageId"></param>
  244. public void pushAndSelect(int imageId)
  245. {
  246. ImageComboBoxItem iCBI = new ImageComboBoxItem(Text, imageId);
  247. if (!allowDuplicates && Items.Contains(iCBI))
  248. Items.Remove(iCBI);
  249. Items.Insert(0, iCBI);
  250. SelectedIndex = 0;
  251. }
  252. /// <summary>
  253. /// Add the current text as first item, set the image index,
  254. /// and set this item as selected
  255. /// </summary>
  256. /// <param name="imageId"></param>
  257. public void pushAndSelect(String text, int imageId)
  258. {
  259. ImageComboBoxItem iCBI = new ImageComboBoxItem(text, imageId);
  260. if (!allowDuplicates && Items.Contains(iCBI))
  261. {
  262. Items.Remove(iCBI);
  263. }
  264. Items.Insert(0, iCBI);
  265. SelectedIndex = 0;
  266. }
  267.  
  268. public void cleanDuplicates()
  269. {
  270. for (int i = 0; i < Items.Count - 1; i++)
  271. {
  272. for (int j = Items.Count - 1; j > i; j--)
  273. {
  274. if ((Items[i]).Equals(Items[j]))
  275. {
  276. Items.RemoveAt(j);
  277. }
  278. }
  279. }
  280. }
  281. #endregion
  282.  
  283. #region overrided methods
  284. protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
  285. {
  286. //this.DropDownStyle = ComboBoxStyle.DropDown;
  287.  
  288. base.OnDrawItem(e);
  289.  
  290. if (e.Index == -1)
  291. return;
  292.  
  293. if (this.ImageList != null)
  294. {
  295. ImageComboBoxItem imageCBI = (ImageComboBoxItem)this.Items[e.Index];
  296. Image imgToDisplay = this.ImageList.Images[imageCBI.ImageIndex];
  297.  
  298. Rectangle oRect = new Rectangle(
  299. e.Bounds.Left,
  300. e.Bounds.Top,
  301. e.Bounds.Width - this.ImageList.ImageSize.Width,
  302. e.Bounds.Height
  303. );
  304.  
  305. int iX = 0, iY = 0;
  306.  
  307. switch (this.ImageAlignment)
  308. {
  309.  
  310. case ContentAlignment.TopLeft:
  311. iX = e.Bounds.Left;
  312. iY = e.Bounds.Top;
  313. oRect.X = this.ImageList.ImageSize.Width;
  314. break;
  315. case ContentAlignment.MiddleLeft:
  316. iX = e.Bounds.Left;
  317. iY = e.Bounds.Top + (this.ItemHeight - this.ImageList.ImageSize.Height) / 2;
  318. oRect.X = this.ImageList.ImageSize.Width;
  319. break;
  320. case ContentAlignment.BottomLeft:
  321. iX = e.Bounds.Left;
  322. iY = e.Bounds.Top + this.ItemHeight - this.ImageList.ImageSize.Height;
  323. oRect.X = this.ImageList.ImageSize.Width;
  324. break;
  325.  
  326. case ContentAlignment.TopRight:
  327. iX = e.Bounds.Right - this.ImageList.ImageSize.Width;
  328. iY = e.Bounds.Top;
  329. break;
  330. case ContentAlignment.MiddleRight:
  331. iX = e.Bounds.Right - this.ImageList.ImageSize.Width;
  332. iY = e.Bounds.Top + (this.ItemHeight - this.ImageList.ImageSize.Height) / 2;
  333. break;
  334. case ContentAlignment.BottomRight:
  335. iX = e.Bounds.Right - this.ImageList.ImageSize.Width;
  336. iY = e.Bounds.Top + this.ItemHeight - this.ImageList.ImageSize.Height;
  337. break;
  338.  
  339. case ContentAlignment.TopCenter:
  340. iX = e.Bounds.Left + (e.Bounds.Width - this.ImageList.ImageSize.Width) / 2;
  341. iY = e.Bounds.Top;
  342. oRect.Width = e.Bounds.Width;
  343. break;
  344. case ContentAlignment.MiddleCenter:
  345. iX = e.Bounds.Left + (e.Bounds.Width - this.ImageList.ImageSize.Width) / 2;
  346. iY = e.Bounds.Top + (this.ItemHeight - this.ImageList.ImageSize.Height) / 2;
  347. oRect.Width = e.Bounds.Width;
  348. break;
  349. case ContentAlignment.BottomCenter:
  350. iX = e.Bounds.Left + (e.Bounds.Width - this.ImageList.ImageSize.Width) / 2;
  351. iY = e.Bounds.Top + this.ItemHeight - this.ImageList.ImageSize.Height;
  352. oRect.Width = e.Bounds.Width;
  353. break;
  354. }
  355.  
  356. e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds);
  357. if ((e.State & DrawItemState.Focus) != 0)
  358. e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
  359.  
  360. e.Graphics.DrawImage(imgToDisplay, iX, iY);
  361.  
  362. e.Graphics.DrawString(this.Items[e.Index].ToString(), this.Font, solidBrush, oRect, stringFormat);
  363. return;
  364. }
  365. e.Graphics.DrawString(this.Items[e.Index].ToString(), this.Font, solidBrush, e.Bounds);
  366. }
  367. #endregion
  368.  
  369. #region innerClass
  370. private class ImageComboBoxItem
  371. {
  372.  
  373. #region declarations and constructors
  374.  
  375. private object iCBiValue;
  376. private int imageIndex;
  377.  
  378. public ImageComboBoxItem()
  379. {
  380. this.imageIndex = 0;
  381. }
  382.  
  383. public ImageComboBoxItem(Object iCBiValue, Int32 imageIndex)
  384. {
  385. this.iCBiValue = iCBiValue;
  386. this.imageIndex = imageIndex;
  387. }
  388. #endregion
  389.  
  390. #region properties
  391. public String Text
  392. {
  393. get { return iCBiValue.ToString(); }
  394. }
  395. public Object Value
  396. {
  397. get{return iCBiValue;}
  398. set{iCBiValue = value;}
  399. }
  400.  
  401. public Int32 ImageIndex
  402. {
  403. get{return imageIndex;}
  404. set{imageIndex = value;}
  405. }
  406. #endregion
  407.  
  408. #region overrides methods
  409. public override string ToString()
  410. {
  411. return iCBiValue.ToString();
  412. }
  413. public override int GetHashCode()
  414. {
  415. return string.Concat(imageIndex.ToString(),iCBiValue.ToString()).GetHashCode();
  416. }
  417. public override bool Equals(object obj)
  418. {
  419. ImageComboBoxItem icbi = obj as ImageComboBoxItem;
  420. if (icbi == null)
  421. {
  422. return false;
  423. }
  424. if (imageIndex != icbi.imageIndex)
  425. {
  426. return false;
  427. }
  428. if (iCBiValue == null && icbi.iCBiValue == null)
  429. {
  430. return true;
  431. }
  432. if (icbi.iCBiValue == null)
  433. {
  434. return false;
  435. }
  436. //icbi.iCBiValue.GetType()
  437. return icbi.iCBiValue.Equals(iCBiValue);
  438. }
  439. #endregion
  440. }
  441. #endregion
  442. }
  443. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/view/controls/ 
IcôneNomTailleModification
Pas de sous-répertoires.
IcôneNomTailleModification
| _ Répertoire parent0 octets1719358380 26/06/2024 01:33:00
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/view/controls/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csToolBarHomeControl.Designer.cs7.41 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csWizardUserControl.Designer.cs6.79 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csHeaderPanel.Designer.cs1.19 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csDGVLayoutOptionsControl.cs7.55 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csXPGroupBox.cs15.83 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csWizardXpUserControl.Designer.cs7.85 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csToolBarHomeControl.cs2.32 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csVersionControl.Designer.cs4.09 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csWizardUserControl.cs2.01 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .resx|.resxWizardXpUserControl.resx5.68 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csBrolBoxUserControl.Designer.cs5.92 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .resx|.resxChartControl.resx6.58 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csHeaderPanel.cs35.93 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csIWizardUC.cs2.35 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .resx|.resxAboutUserControl.resx5.68 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .cs|.csTextBoxDragDrop.cs8.59 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csSystemInfoControl.cs5.46 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .resx|.resxXPGroupBox.resx17.7 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csHeaderPanelNativeMethods.cs21.09 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csToolBarManagerControl.cs6.99 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csTextBoxDragDrop.Designer.cs1.11 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .resx|.resxSystemInfoControl.resx6.22 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csSystemInfoControl.Designer.cs4.79 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .resx|.resxHeaderPanel.resx5.85 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csScrollablePictureBoxUserControl.cs5.55 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csBrolBoxUserControl.cs4.7 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .resx|.resxDGVLayoutOptionsControl.resx5.68 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .resx|.resxWizardUserControl.resx5.68 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csUpdateControl.cs7.55 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csIconList.cs2.68 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csVersionControl.cs463 octets31/10/2018 18:33:12-refusé-
Afficher le fichier .resx|.resxBrolBoxUserControl.resx5.68 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .cs|.csAboutUserControl.cs6.75 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .resx|.resxToolBarManagerControl.resx5.88 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csToolBarManagerControl.Designer.cs10.66 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csIToolBarControl.cs1.07 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csWizardXpUserControl.cs8.11 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csImageCombo.cs15.49 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csAboutUserControl.Designer.cs12.31 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .resx|.resxScrollablePictureBoxUserControl.resx5.68 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csScrollablePictureBoxUserControl.Designer.cs5.64 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .resx|.resxVersionControl.resx5.68 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csChartControl.Designer.cs18.45 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .cs|.csUpdateControl.Designer.cs3.92 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .resx|.resxUpdateControl.resx5.68 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csChartControl.cs15.11 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .cs|.csDGVLayoutOptionsControl.Designer.cs17.39 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csToolStrip.cs1.06 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csIconList.Designer.cs1.1 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .resx|.resxToolBarHomeControl.resx48.51 Ko31/10/2018 18:33:12-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.

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 16/10/2009 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/cs-broldev-source-rf-view/controls//ImageCombo.cs.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.