EventMethods.cs
Description du code
EventMethods.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
Code c# (EventMethods.cs) (244 lignes)
using System; using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; using be.gaudry.model.drawing; using be.gaudry.view.dialogs; namespace be.gaudry.events { /// <summary> /// more infos on http://www.codeproject.com/cs/media/DIBtoBitmap.asp /// </summary> public static class EventMethods { public static void applicationThreadException(object sender, ThreadExceptionEventArgs e) { /*String msg = String.Format( "Une erreur est survenue dans l'application :\r\n\r\n{0}\r\n\r\nDésirez-vous plus d'informations ?\r\nOui : afficher les erreurs\r\nNon : quitter l'application\r\nAnnuler : ne pas quitter et ne pas afficher l'erreur", e.Exception.Message ); DialogResult dr = MessageBox.Show( msg, "Erreur", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2); switch (dr) { case DialogResult.Yes: new ThreadExceptionDialog(e.Exception).Show(); break; case DialogResult.Cancel: return; default: Application.Exit(); break; }*/ } public static bool imageDragDrop(object sender, DragEventArgs e, PictureBox pictureBox) { bool modified = false; /*System.Diagnostics.Debug.WriteLine(string.Format("Un élément est déposé par {0}",sender)); string[] formats = e.Data.GetFormats(); foreach (string sf in formats) { System.Diagnostics.Debug.WriteLine(string.Format("Type : {0}", sf)); ; } */ /* if (e.Data.GetDataPresent(typeof(UniformResourceLocator))) { //editSpImgRTB.AppendText("\r\nType : image web"); }*/ if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] dropFiles = (string[])e.Data.GetData(DataFormats.FileDrop); if (ImageHelper.isImg(dropFiles[0])) { pictureBox.ImageLocation = dropFiles[0]; //modified = true; return true; } else { Form form = sender as Form; MessageBox.Show( form, string.Format( "Le fichier déposé n'est pas une image valide : {0}", System.IO.Path.GetFileName(dropFiles[0]) ), "Modification d'image", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1 ); } /*StringBuilder str = new StringBuilder(); foreach (string s in dropFiles) { str.Append("\r\n"); str.Append(s); } editSpImgRTB.AppendText(str.ToString());*/ } { //System.Diagnostics.Debug.WriteLine("Type2 : texte"); string url = e.Data.GetData("UniformResourceLocator") as string; if (url == null) url = e.Data.GetData("UniformResourceLocatorW") as string; if(url!=null) { pictureBox.ImageLocation = url; return true; //System.Diagnostics.Debug.WriteLine("Type2 : url => "+url); } } { //modified = true; return true; /*editSpImgPictureBox.Image = Image.FromStream( System.Net.HttpWebRequest.Create( "http://www.zeetelevision.com/images/today.jpg" ).GetResponse().GetResponseStream() ); */ } { //System.Diagnostics.Debug.WriteLine("Type3 : " + str); pictureBox.Image = System.Drawing.Image.FromStream( System.Net.HttpWebRequest.Create( str ).GetResponse().GetResponseStream() ); //modified = true; return true; } else if (e.Data.GetDataPresent(DataFormats.Dib))//DeviceIndependentBitmap { /*System.Drawing.Bitmap bmp = (System.Drawing.Bitmap)e.Data.GetData(DataFormats.Bitmap, true); System.Diagnostics.Debug.WriteLine("DeviceIndependentBitmap bmp test"); try { if (bmp != null) { System.Diagnostics.Debug.WriteLine("DeviceIndependentBitmap bmp ok"); pictureBox.Image = bmp; modified = true; } } catch (Exception exept) { System.Diagnostics.Debug.WriteLine("DeviceIndependentBitmap error : " + exept.StackTrace); } object obj = e.Data.GetData(DataFormats.Dib); //System.Diagnostics.Debug.WriteLine("DeviceIndependentBitmap bmp test"); System.IO.MemoryStream stream = obj as System.IO.MemoryStream; if (stream != null) { //System.Diagnostics.Debug.WriteLine("DeviceIndependentBitmap bmp ok"); byte[] img = stream.ToArray(); IntPtr p = Marshal.AllocCoTaskMem(Marshal.SizeOf(img[0]) * img.Length); Marshal.Copy(img, 0, p, img.Length); try { pictureBox.Image = TwainGui.DibToImage.WithStream(p); } catch (Exception exept) { System.Diagnostics.Debug.WriteLine("DeviceIndependentBitmap error : " + exept.StackTrace); } finally { Marshal.FreeCoTaskMem(p); } }*/ System.IO.MemoryStream stream = e.Data.GetData(DataFormats.Dib) as System.IO.MemoryStream; if (stream != null) { byte[] img = stream.ToArray(); Marshal.Copy(img, 0, p, img.Length); try { pictureBox.Image = DibToImage.WithStream(p); return true; } catch (Exception exept) { System.Diagnostics.Debug.WriteLine("DeviceIndependentBitmap error : " + exept.StackTrace); } finally { Marshal.FreeCoTaskMem(p); } } } #region from the URL of the image file /*string hyperLinkUrl = null; string hyperLinkText = null; // try { hyperLinkUrl = e.Data.GetData(typeof(string)) as string; // some browser deliver url and text // in UniformResourceLocator (Firebird) string[] tokens = hyperLinkUrl.Split('\\'); if(tokens.Length>1) { hyperLinkUrl = tokens[0]; hyperLinkText = tokens[1]; } // we have to read FILEGROUPDESCRIPTOR to get the text (IE) else { System.IO.Stream ioStream= (System.IO.Stream)e.Data.GetData("FileGroupDescriptor"); byte[] contents = new Byte[512]; ioStream.Read(contents,0,512); ioStream.Close(); System.Text.StringBuilder sb = new System.Text.StringBuilder(); //The magic number 76 is the size of that part of the //FILEGROUPDESCRIPTOR structure before // the filename starts - cribbed //from another usenet post. for (int i=76; contents[i] != 0; i++) { sb.Append((char)contents[i]); } if (!sb.ToString(sb.Length-4,4).ToLower().Equals(".url")) { System.Diagnostics.Debug.WriteLine("filename does not end in '.url'"); } hyperLinkText = sb.ToString(0,sb.Length-4); } // do what ever you wanna do with the hyperlink //this.BeginInvoke(.....) pictureBox.ImageLocation = hyperLinkText; System.Diagnostics.Debug.WriteLine("url : " + hyperLinkText); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } */ #endregion return modified; } } }
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 | 1739023502 08/02/2025 15:05:02 |
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-events/EventMethods.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.