Ejemplo n.º 1
0
        public void DisposeCleansUpDataOnlyOnceTest()
        {
            var data = Substitute.For <Stream>();

            using (var sut = new Photo())
            {
                sut.Data = data;

                sut.Dispose();
                sut.Dispose();

                data.Received(1).Dispose();
            }
        }
Ejemplo n.º 2
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    Photo.Dispose();
                }

                Photo         = null;
                disposedValue = true;
            }
        }
Ejemplo n.º 3
0
        private void lstPhotos_DrawItem(object sender, DrawItemEventArgs e)
        {
            Graphics g = e.Graphics;

            if (e.Index < 0 || e.Index > Manager.Album.Count - 1)
            {
                return;
            }
            Photo p = Manager.Album[e.Index];

            // Determine image rectangle
            Rectangle imageRect = ImageUtility.ScaleToFit(p.Image, DrawRect);

            imageRect.X = e.Bounds.X + 2;
            imageRect.Y = e.Bounds.Y + 1;

            // Draw text image
            g.DrawImage(p.Image, imageRect);
            g.DrawRectangle(Pens.Black, imageRect);
            //p.ReleaseImage();
            p.Dispose();

            // Determine text rectangle
            Rectangle textRect = new Rectangle();

            textRect.X      = imageRect.Right + 2;
            textRect.Y      = imageRect.Y + ((imageRect.Height - e.Font.Height) / 2);
            textRect.Width  = e.Bounds.Width - imageRect.Width - 4;
            textRect.Height = e.Font.Height;

            // Determine text brush (handle selection)
            Brush textBrush;

            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                g.FillRectangle(SystemBrushes.Highlight, textRect);
                textBrush = SystemBrushes.HighlightText;
            }
            else
            {
                g.FillRectangle(SystemBrushes.Window, textRect);
                textBrush = SystemBrushes.WindowText;
            }
            // Draw the text
            g.DrawString(lstPhotos.GetItemText(p), e.Font, textBrush, textRect);
        }
        void ReleaseDesignerOutlets()
        {
            if (CancelButton != null)
            {
                CancelButton.Dispose();
                CancelButton = null;
            }

            if (DoneSwitch != null)
            {
                DoneSwitch.Dispose();
                DoneSwitch = null;
            }

            if (ForText != null)
            {
                ForText.Dispose();
                ForText = null;
            }

            if (NameText != null)
            {
                NameText.Dispose();
                NameText = null;
            }

            if (NotesText != null)
            {
                NotesText.Dispose();
                NotesText = null;
            }

            if (SaveButton != null)
            {
                SaveButton.Dispose();
                SaveButton = null;
            }

            if (Photo != null)
            {
                Photo.Dispose();
                Photo = null;
            }
        }
Ejemplo n.º 5
0
        private void mnuEditAdd_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title       = "Add Photos";
            dlg.Multiselect = true;
            dlg.Filter      = "Image Files (JPEG, GIF, BMP, etc.)|"
                              + "*.jpg;*.jpeg;*.gif;*.bmp;"
                              + "*.tif;*.tiff;*.png|"
                              + "JPEG files (*.jpg;*.jpeg)|*.jpg;*.jpeg|"
                              + "GIF files (*.gif)|*.gif|"
                              + "BMP files (*.bmp)|*.bmp|"
                              + "TIFF files (*.tif;*.tiff)|*.tif;*.tiff|"
                              + "PNG files (*.png)|*.png|"
                              + "All files (*.*)|*.*";
            dlg.InitialDirectory = Environment.CurrentDirectory;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string[] files = dlg.FileNames;
                int      index = 0;
                foreach (string s in files)
                {
                    Photo photo = new Photo(s);
                    // Add the file (if not already present)
                    index = Manager.Album.IndexOf(photo);
                    if (index < 0)
                    {
                        Manager.Album.Add(photo);
                    }
                    else
                    {
                        photo.Dispose(); // photoalready there
                    }
                }
                Manager.Index = Manager.Album.Count - 1;
            }
            dlg.Dispose();
            DisplayAlbum();
        }
Ejemplo n.º 6
0
 private void ClearSelectedImage()
 {
     _selectedImage?.Dispose();
     GC.Collect();
 }
Ejemplo n.º 7
0
 protected override void DisposeManagedResources()
 {
     base.DisposeManagedResources();
     Photo?.Dispose();
 }