123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using FastReport.Utils;
- using System.ComponentModel;
- using System.Drawing;
- using System.Windows.Forms;
- namespace FastReport.Controls
- {
- 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);
- 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;
- int _5 = this.LogicalToDevice(5);
- int _6 = this.LogicalToDevice(6);
- int _10 = this.LogicalToDevice(10);
- int _11 = this.LogicalToDevice(11);
- // draw control frame
- this.DrawVisualStyleBorder(g, new Rectangle(0, 0, Width - 1, Height - 1));
- // draw corners
- Pen 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 (var 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 (var cache = new GraphicCache())
- {
- float scale = this.DpiMultiplier();
- Border.Draw(new FRPaintEventArgs(g, scale, scale, cache), new RectangleF(10, 10, Width / scale - 21, Height / scale - 21));
- }
- }
- }
- protected override void OnMouseDown(MouseEventArgs e)
- {
- int _5 = this.LogicalToDevice(5);
- int _12 = this.LogicalToDevice(12);
- int _18 = this.LogicalToDevice(18);
- 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 void UpdateDpiDependencies(Control owner)
- {
- #if MONO
- // WPF: fix issues with multi-monitor dpi. Dropdown will be scaled automatically
- owner = this;
- #endif
- if (owner == null)
- return;
- Size = owner.LogicalToDevice(new Size(160, 94));
- }
- public BorderSample()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint, true);
- SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
- BackColor = SystemColors.Window;
- Size = new Size(160, 94);
- }
- }
- }
|