Пример #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     //if (additionalTextTextBox.Text == String.Empty)
     //    return;
     //else
     //{
     //    pictureBox.Cursor = Cursors.Cross;
     //    selectedtext = additionalTextTextBox.Text;
     //}
     using (AddTextDialog textDialog = new AddTextDialog())
     {
         textDialog.ShowDialog(this);
         if (textDialog.DialogResult == DialogResult.OK)
         {
             TextContext       = textDialog.DialogData;
             pictureBox.Cursor = Cursors.Cross;
         }
     }
 }
Пример #2
0
        private void pictureBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if ((e.Button & MouseButtons.Left) != 0)
            {
                DialogResult   result   = DialogResult.Cancel;
                StringGraphics toadd    = new StringGraphics();
                StringGraphics toremove = new StringGraphics();
                foreach (var item in BookCover.TextList)
                {
                    using (Graphics g = pictureBox.CreateGraphics())
                    {
                        Rectangle stringRect = new Rectangle();
                        switch (item.Alignment)
                        {
                        case StringAlignment.Center:
                            stringRect = new Rectangle
                            {
                                Height = (int)g.MeasureString(item.Text, item.Font).Height,
                                Width  = (int)g.MeasureString(item.Text, item.Font).Width,
                                X      = item.Position.X + BookCover.Position.X - (int)g.MeasureString(item.Text, item.Font).Width / 2,
                                Y      = item.Position.Y + BookCover.Position.Y
                            };
                            break;

                        case StringAlignment.Near:
                            stringRect = new Rectangle
                            {
                                Height = (int)g.MeasureString(item.Text, item.Font).Height,
                                Width  = (int)g.MeasureString(item.Text, item.Font).Width,
                                X      = item.Position.X + BookCover.Position.X,
                                Y      = item.Position.Y + BookCover.Position.Y
                            };
                            break;

                        case StringAlignment.Far:
                            stringRect = new Rectangle
                            {
                                Height = (int)g.MeasureString(item.Text, item.Font).Height,
                                Width  = (int)g.MeasureString(item.Text, item.Font).Width,
                                X      = item.Position.X + BookCover.Position.X - (int)g.MeasureString(item.Text, item.Font).Width,
                                Y      = item.Position.Y + BookCover.Position.Y
                            };
                            break;
                        }


                        if (stringRect.Contains(e.Location)) //check if mouse point is inside the rectangle
                        {
                            //g.DrawRectangle(new Pen(Color.FromArgb(255, 255 - BookCover.Color.R, 255 - BookCover.Color.G, 255 - BookCover.Color.B)), stringRect);
                            toremove = item;
                            using (AddTextDialog textDialog = new AddTextDialog())
                            {
                                textDialog.DialogData = new AddTextDialogData
                                {
                                    FontSize = (int)item.Font.Size, Text = item.Text, TextAlignment = item.Alignment
                                };
                                textDialog.ShowDialog(this);
                                if (textDialog.DialogResult == DialogResult.OK)
                                {
                                    result      = textDialog.DialogResult;
                                    TextContext = textDialog.DialogData;
                                    Font fn = new Font("Arial", TextContext.FontSize, FontStyle.Bold);
                                    switch (TextContext.TextAlignment)
                                    {
                                    //when text is changed it is a little of off center
                                    case StringAlignment.Center:
                                        var stringMeasuresC = (g.MeasureString(toremove.Text, fn));
                                        //could be better
                                        toadd = new StringGraphics {
                                            Font = fn, Text = TextContext.Text, Position = new Point(stringRect.X + (int)stringMeasuresC.Width / 2 - BookCover.Position.X, stringRect.Y + stringRect.Height / 2 - (int)(g.MeasureString(TextContext.Text, fn).Height) / 2 - BookCover.Position.Y), Color = currentTextColor, Alignment = TextContext.TextAlignment
                                        };
                                        break;

                                    case StringAlignment.Near:
                                        toadd = new StringGraphics {
                                            Font = fn, Text = TextContext.Text, Position = new Point((stringRect.X + stringRect.Width / 2 - (int)(g.MeasureString(TextContext.Text, fn).Width) / 2) - BookCover.Position.X, stringRect.Y + stringRect.Height / 2 - (int)(g.MeasureString(TextContext.Text, fn).Height) / 2 - BookCover.Position.Y), Color = currentTextColor, Alignment = TextContext.TextAlignment
                                        }; break;

                                    case StringAlignment.Far:

                                        toadd = new StringGraphics
                                        {
                                            Font = fn,
                                            Text = TextContext.Text,

                                            Position = new Point(
                                                stringRect.X + stringRect.Width / 2 + g.MeasureString(TextContext.Text, fn).ToSize().Width / 2 -
                                                BookCover.Position.X, stringRect.Y + stringRect.Height / 2 - (int)(g.MeasureString(TextContext.Text, fn).Height) / 2 - BookCover.Position.Y),
                                            Color     = currentTextColor,
                                            Alignment = TextContext.TextAlignment
                                        };
                                        break;
                                    }
                                    //BookCover.TextList.Remove(item);
                                }
                            }
                        }
                    }
                }

                if (result == DialogResult.OK)
                {
                    BookCover.TextList.Remove(toremove);
                    BookCover.TextList.Add(toadd);
                    if (ContextRectangle != Rectangle.Empty)
                    {
                        ContextRectangle = GetStringRectangle(toadd);
                        toModify         = toadd;
                    }

                    pictureBox.Refresh();
                }
            }
        }