private void SentencesListBox_KeyDown(object sender, KeyEventArgs e)
 {
     switch (e.KeyCode)
     {
     case Keys.Delete:
     {
         var index = sentencesListBox.SelectedIndex;
         if (index < 0)
         {
             return;
         }
         SentenceGraphics sentence = (SentenceGraphics)sentencesListBox.SelectedItem;
         _sentences.Remove(sentence);
         RefreshSentencesListBox();
         if (sentencesListBox.Items.Count <= index)
         {
             index--;
         }
         if (sentencesListBox.Items.Count > 0)
         {
             sentencesListBox.SelectedIndex = index;
         }
     }
     break;
     }
 }
        public void PreviewPictureBox_MouseWheel(object sender, MouseEventArgs e)
        {
            SentenceGraphics sentence = (SentenceGraphics)sentencesListBox.SelectedItem;

            if (sentence == null)
            {
                return;
            }

            float numberOfScrolls = e.Delta * SystemInformation.MouseWheelScrollLines / 120f;

            previewZoom *= numberOfScrolls > 0 ? 1.25f : 0.8f;

            if (previewZoom > MAX_PREVIEW_ZOOM)
            {
                previewZoom = MAX_PREVIEW_ZOOM;
                return;
            }
            if (previewZoom < MIN_PREVIEW_ZOOM)
            {
                previewZoom = MIN_PREVIEW_ZOOM;
                return;
            }

            ZoomLabel.Text = String.Format("x{0:F2}", previewZoom);

            PreviewSentence();
        }
        private void CurrentHoriAlignComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            SentenceGraphics sentence = (SentenceGraphics)sentencesListBox.SelectedItem;

            if (sentence == null)
            {
                return;
            }
            sentence.SetHorizontalAlignment((HorizontalAlignment)CurrentHoriAlignComboBox.SelectedItem);
            PreviewSentence();
        }
        private void CurrentImageHeightTrackBar_Scroll(object sender, EventArgs e)
        {
            SentenceGraphics sentence = (SentenceGraphics)sentencesListBox.SelectedItem;

            if (sentence == null)
            {
                return;
            }
            int imageHeight = CurrentImageHeightTrackBar.Value;

            if (sentence.GetImageSize().Height == imageHeight)
            {
                return;
            }
            sentence.SetImageSize(new Size(sentence.GetImageSize().Width, imageHeight));
            CurrentImageHeightLabel.Text = imageHeight.ToString();
            sentence.AutoReLine();
            PreviewSentence();
        }
        private void CurrentFontSizeTrackBar_Scroll(object sender, EventArgs e)
        {
            SentenceGraphics sentence = (SentenceGraphics)sentencesListBox.SelectedItem;

            if (sentence == null)
            {
                return;
            }
            int fontSize = CurrentFontSizeTrackBar.Value;

            if (sentence.GetFont().Size == fontSize)
            {
                return;
            }
            sentence.SetFont(new Font(family: FontFamily.GenericSansSerif, fontSize, FontStyle.Regular));
            CurrentFontSizeLabel.Text = fontSize.ToString();
            sentence.AutoReLine();
            PreviewSentence();
        }
        private void SetDefaultStyleToCurrentButton_Click(object sender, EventArgs e)
        {
            SentenceGraphics sentence = (SentenceGraphics)sentencesListBox.SelectedItem;

            if (sentence == null)
            {
                return;
            }
            CurrentFontSizeTrackBar.Value = defaultFontSizeTrackBar.Value;
            CurrentFontSizeTrackBar_Scroll(sender, e);
            CurrentImageWidthTrackBar.Value  = DefaultImageWidthTrackBar.Value;
            CurrentImageHeightTrackBar.Value = DefaultImageHeightTrackBar.Value;
            CurrentImageWidthTrackBar_Scroll(sender, e);
            CurrentImageHeightTrackBar_Scroll(sender, e);
            CurrentVertAlignComboBox.SelectedItem = DefaultVertAlignComboBox.SelectedItem;
            CurrentHoriAlignComboBox.SelectedItem = DefaultHoriAlignComboBox.SelectedItem;
            sentence.SetBackColor(DefaultBackColorBox.BackColor);
            SentencesListBox_SelectedIndexChanged(sender, e);
        }
        private void AddSensFileButton_Click(object sender, EventArgs e)
        {
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                var reader = new StreamReader(fileDialog.FileName);

                Font                font      = new Font(family: FontFamily.GenericSansSerif, defaultFontSizeTrackBar.Value, FontStyle.Regular);
                Size                size      = new Size(DefaultImageWidthTrackBar.Value, DefaultImageHeightTrackBar.Value);
                Color               backColor = DefaultBackColorBox.BackColor;
                VerticalAlignment   vert      = (VerticalAlignment)DefaultVertAlignComboBox.SelectedItem;
                HorizontalAlignment hori      = (HorizontalAlignment)DefaultHoriAlignComboBox.SelectedItem;

                while (reader.EndOfStream == false)
                {
                    var sentence = new SentenceGraphics(font, size, backColor, vert, hori, reader.ReadLine());
                    sentence.AutoReLine();
                    _sentences.Add(sentence);
                }
                reader.Close();
            }
            RefreshSentencesListBox();
        }
        public void PreviewSentence()
        {
            SentenceGraphics sentence = (SentenceGraphics)sentencesListBox.SelectedItem;

            if (sentence == null)
            {
                return;
            }
            Image    originalImage = sentence.MakeBitmap();
            Image    newPreview    = new Bitmap((int)(originalImage.Width * previewZoom), (int)(originalImage.Height * previewZoom));
            Graphics graphics      = Graphics.FromImage(newPreview);

            graphics.ScaleTransform(previewZoom, previewZoom);
            graphics.Clear(sentence.GetBackColor());
            graphics.DrawImage(originalImage, new Point(0, 0));
            graphics.Flush();
            graphics.Dispose();
            originalImage.Dispose();
            previewPictureBox.Image?.Dispose();

            previewPictureBox.Image = newPreview;
        }