123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- using System;
- using System.Windows.Forms;
- using System.Drawing;
- using FastReport.Utils;
- using System.ComponentModel;
- namespace FastReport.Controls
- {
- internal class ParametersComboBox : UserControl
- {
- private TextBox textBox;
- private Button comboButton;
- private Report report;
- private DataColumnDropDown dropDown;
- private Timer timer;
- private int closedTicks;
- private int dpi;
- public event EventHandler DropDownOpening;
- public new event EventHandler TextChanged;
- /// <inheritdoc/>
- public override string Text
- {
- get { return textBox.Text; }
- set { textBox.Text = value; }
- }
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public Report Report
- {
- get { return report; }
- set
- {
- report = value;
- dropDown.CreateNodes(value);
- }
- }
- private void FTextBox_TextChanged(object sender, EventArgs e)
- {
- if (TextChanged != null)
- TextChanged(this, EventArgs.Empty);
- }
- private void FDropDown_ColumnSelected(object sender, EventArgs e)
- {
- Text = String.IsNullOrEmpty(dropDown.Column) ? "" : dropDown.Column;
- timer.Start();
- }
- private void FDropDown_Closed(object sender, ToolStripDropDownClosedEventArgs e)
- {
- closedTicks = Environment.TickCount;
- }
- private void FComboButton_Click(object sender, EventArgs e)
- {
- if (Math.Abs(Environment.TickCount - closedTicks) < 100)
- return;
- DropDownOpening?.Invoke(this, EventArgs.Empty);
- dropDown.Column = Text;
- dropDown.SetSize(Width, 250);
- dropDown.Owner = this;
- dropDown.Show(this, new Point(RightToLeft == RightToLeft.Yes ? Width : 0, Height));
- }
- private void FTimer_Tick(object sender, EventArgs e)
- {
- FindForm().BringToFront();
- textBox.Focus();
- textBox.Select(Text.Length, 0);
- timer.Stop();
- }
- private void LayoutControls()
- {
- int _1 = (int)Math.Round(this.LogicalToDevice(1f));
- int _2 = _1 + _1;
- int btnWidth = Height - _2;
- if (comboButton != null)
- comboButton.SetBounds(RightToLeft == RightToLeft.Yes ? _1 : Width - btnWidth - _1, _1, btnWidth, btnWidth);
- if (textBox != null)
- textBox.SetBounds(RightToLeft == RightToLeft.Yes ? Height : 3, (Height - textBox.PreferredHeight) / 2, Width - Height - 3, textBox.PreferredHeight);
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- if (dpi != this.Dpi())
- {
- UpdateImages();
- dpi = this.Dpi();
- }
- Graphics g = e.Graphics;
- g.FillRectangle(Enabled ? SystemBrushes.Window : SystemBrushes.Control, DisplayRectangle);
- if (Enabled)
- this.DrawVisualStyleBorder(g, new Rectangle(0, 0, Width - 1, Height - 1));
- else
- g.DrawRectangle(SystemPens.InactiveBorder, new Rectangle(0, 0, Width - 1, Height - 1));
- }
- private void UpdateImages()
- {
- #if AVALONIA
- // doing this in the render code will result in InvalidOp exception
- Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
- {
- comboButton.Image = this.GetImage(182);
- });
- #else
- comboButton.Image = this.GetImage(182);
- #endif
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- if (timer != null)
- timer.Dispose();
- timer = null;
- }
- base.Dispose(disposing);
- }
- /// <inheritdoc/>
- protected override void OnResize(EventArgs e)
- {
- base.OnResize(e);
- LayoutControls();
- }
- /// <inheritdoc/>
- protected override void OnLayout(LayoutEventArgs e)
- {
- base.OnLayout(e);
- LayoutControls();
- }
- public ParametersComboBox()
- {
- comboButton = new Button();
- comboButton.FlatStyle = FlatStyle.Flat;
- comboButton.FlatAppearance.BorderSize = 0;
- comboButton.Click += new EventHandler(FComboButton_Click);
- Controls.Add(comboButton);
- textBox = new TextBox();
- textBox.BorderStyle = BorderStyle.None;
- textBox.TextChanged += new EventHandler(FTextBox_TextChanged);
- Controls.Add(textBox);
- dropDown = new DataColumnDropDown();
- dropDown.DataTree.ShowColumns = false;
- dropDown.DataTree.ShowDataSources = false;
- dropDown.DataTree.ShowRelations = false;
- dropDown.DataTree.ShowParameters = true;
- dropDown.ColumnSelected += new EventHandler(FDropDown_ColumnSelected);
- dropDown.Closed += new ToolStripDropDownClosedEventHandler(FDropDown_Closed);
- timer = new Timer();
- timer.Interval = 50;
- timer.Tick += new EventHandler(FTimer_Tick);
- // prevent autoscale of child controls
- AutoScaleMode = AutoScaleMode.None;
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
- }
- }
- }
|