FaceInputBox.cs 1.7 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Asa.FaceControl
{
    public partial class FaceInputBox : FormBase
    {
        public FaceInputBox(string title, string text, string defaultValue = "")
        {
            InitializeComponent();
            ctlClose.Click += CtlClose_Click;
            CanResize = false;

            Text = title;
            faceLabel1.Text = text;
            faceTextBox1.Text = defaultValue;
           
        }

        public string InputValue { private set; get; }

        protected override void CalcSize()
        {
            base.CalcSize();
            int n = 1;
            if (ctlClose != null)
            {
                ctlClose.Size = new Size(60, TitleHeight - 5);
                n += ctlClose.Width;
                ctlClose.Location = new Point(Width - BorderWidth - n, BorderWidth + 1);
                ctlClose.Anchor = AnchorStyles.Top | AnchorStyles.Right;
            }
        }

        private void CtlClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void BtnOK_Click(object sender, EventArgs e)
        {
            InputValue = faceTextBox1.Text;
            DialogResult = DialogResult.OK;
        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            InputValue = "";
            DialogResult = DialogResult.Cancel;
        }

        private void FaceInputBox_Load(object sender, EventArgs e)
        {
            faceTextBox1.Focus();
        }
    }
}