using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using FastReport.Utils;
namespace FastReport.Controls
{
///
/// Represents the control that combines a textbox and a button.
///
[ToolboxItem(false)]
public class TextBoxButton : UserControl
{
private TextBox textBox;
private Button button;
///
/// Occurs when the button is clicked.
///
public event EventHandler ButtonClick;
///
/// Occurs when the text is changed.
///
public new event EventHandler TextChanged;
///
public override string Text
{
get { return textBox.Text; }
set { textBox.Text = value; }
}
///
/// Gets or sets the button's image.
///
public Image Image
{
get { return button.Image; }
set { button.Image = value; }
}
///
/// Gets or sets the button's text.
///
public string ButtonText
{
get { return button.Text; }
set { button.Text = value; }
}
private void FTextBox_TextChanged(object sender, EventArgs e)
{
if (TextChanged != null)
TextChanged(this, EventArgs.Empty);
}
private void FButton_Click(object sender, EventArgs e)
{
if (ButtonClick != null)
ButtonClick(this, EventArgs.Empty);
}
private void LayoutControls()
{
if (button != null)
button.SetBounds(RightToLeft == RightToLeft.Yes ? 1 : Width - Height + 1, 1, Height - 2, Height - 2);
if (textBox != null)
textBox.SetBounds(RightToLeft == RightToLeft.Yes ? Height : 3, (Height - textBox.PreferredHeight) / 2 - 1, Width - Height - 3, textBox.PreferredHeight);
}
///
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.FillRectangle(Enabled ? SystemBrushes.Window : SystemBrushes.Control, DisplayRectangle);
if (Enabled)
ControlPaint.DrawVisualStyleBorder(g, new Rectangle(0, 0, Width - 1, Height - 1));
else
g.DrawRectangle(SystemPens.InactiveBorder, new Rectangle(0, 0, Width - 1, Height - 1));
}
///
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
LayoutControls();
}
///
protected override void OnLayout(LayoutEventArgs e)
{
base.OnLayout(e);
LayoutControls();
}
///
/// Set focus on text box.
///
public void FocusTextBox()
{
textBox.Focus();
}
///
///
/// Initializes a new instance of the class.
///
public TextBoxButton()
{
button = new Button();
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderSize = 0;
button.Click += new EventHandler(FButton_Click);
button.TabIndex = 1;
Controls.Add(button);
textBox = new TextBox();
textBox.BorderStyle = BorderStyle.None;
textBox.TextChanged += new EventHandler(FTextBox_TextChanged);
textBox.TabIndex = 0;
Controls.Add(textBox);
// prevent autoscale of child controls
AutoScaleMode = AutoScaleMode.None;
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
}
}
}