123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Windows.Forms;
- using System.ComponentModel;
- using System.Drawing;
- using FastReport.Utils;
- namespace FastReport.Controls
- {
- #if !DEBUG
- [DesignTimeVisible(false)]
- #endif
- internal class ToggleLineEventArgs
- {
- private Border border;
- private BorderLines line;
- private bool toggle;
- public Border Border
- {
- get { return border; }
- set { border = value; }
- }
- public BorderLines Line
- {
- get { return line; }
- set { line = value; }
- }
- public bool Toggle
- {
- get { return toggle; }
- set { toggle = value; }
- }
- public ToggleLineEventArgs(Border border, BorderLines line, bool toggle)
- {
- Border = border;
- Line = line;
- Toggle = toggle;
- }
- }
- internal delegate void ToggleLineEventHandler(object sender, ToggleLineEventArgs e);
- #if !DEBUG
- [DesignTimeVisible(false)]
- #endif
- internal class BorderSample : Control
- {
- private Border border;
- public event ToggleLineEventHandler ToggleLine;
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public Border Border
- {
- get { return border; }
- set { border = value; }
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- Graphics g = e.Graphics;
- // draw control frame
- Pen p = new Pen(Color.FromArgb(127, 157, 185));
- g.DrawRectangle(p, 0, 0, Width - 1, Height - 1);
- p.Dispose();
- // draw corners
- p = SystemPens.ControlDark;
- g.DrawLine(p, 10, 10, 10, 5);
- g.DrawLine(p, 10, 10, 5, 10);
- g.DrawLine(p, 10, Height - 11, 10, Height - 6);
- g.DrawLine(p, 10, Height - 11, 5, Height - 11);
- g.DrawLine(p, Width - 11, 10, Width - 11, 5);
- g.DrawLine(p, Width - 11, 10, Width - 6, 10);
- g.DrawLine(p, Width - 11, Height - 11, Width - 11, Height - 6);
- g.DrawLine(p, Width - 11, Height - 11, Width - 6, Height - 11);
- // draw text
- using (StringFormat sf = new StringFormat())
- {
- sf.Alignment = StringAlignment.Center;
- sf.LineAlignment = StringAlignment.Center;
- g.DrawString(Res.Get("Misc,Sample"), Font, SystemBrushes.WindowText, DisplayRectangle, sf);
- }
- // draw border
- if (Border != null)
- {
- using (GraphicCache cache = new GraphicCache())
- {
- Border.Draw(new FRPaintEventArgs(g, 1, 1, cache), new RectangleF(10, 10, Width - 21, Height - 21));
- }
- }
- }
- protected override void OnMouseDown(MouseEventArgs e)
- {
- BorderLines line = BorderLines.None;
- if (e.X > 12 && e.X < Width - 12 && e.Y > 5 && e.Y < 18)
- line = BorderLines.Top;
- else if (e.X > 12 && e.X < Width - 12 && e.Y > Height - 18 && e.Y < Height - 5)
- line = BorderLines.Bottom;
- else if (e.X > 5 && e.X < 18 && e.Y > 12 && e.Y < Height - 12)
- line = BorderLines.Left;
- else if (e.X > Width - 18 && e.X < Width - 5 && e.Y > 12 && e.Y < Height - 12)
- line = BorderLines.Right;
- if (Border != null && ToggleLine != null)
- {
- ToggleLine(this, new ToggleLineEventArgs(Border, line, (Border.Lines & line) == 0));
- Refresh();
- }
- }
- public BorderSample()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint, true);
- SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
- BackColor = SystemColors.Window;
- Size = new Size(160, 94);
- }
- }
- }
|