UserControls/SearchBoxControl.cs

using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace ChatworkBulkSender.UserControls
{
    [DesignerCategory("UserControl")]
    public partial class SearchBoxControl : BaseSearchControl
    {
        public Button BtnSearch => _btnSearch;
        public CheckBox CHkUnusedData => _chkUnusedData;

        public TextBox MgmtNumber => _searchTextBoxes.ContainsKey("ManagementNumber") ? _searchTextBoxes["ManagementNumber"] : null;

        public TextBox CustomerNameTextBox => _searchTextBoxes.ContainsKey("CustomerName") ? _searchTextBoxes["CustomerName"] : null;

        public SearchBoxControl()
        {
            InitializeComponent();
            InitializeControls();
            base._panel = this.panel;
            base._lblSearchBox = this.lblSearchBox;
            base._panelSearchBox = this.panelSearchBox;
            base._btnSearch = this.btnSearch;
            base._chkUnusedData = this.chkUnusedData;

            base._searchTextBoxes["ManagementNumber"] = this.mgmtNumberTxtBox;
            base._searchTextBoxes["CustomerName"] = this.customerNameTxtBox;

            this._btnSearch.Click += base.BtnSearch_Click;

            this.ActiveControl = null;
        }
        protected override void InitializeControls()
        {
            if (_btnSearch != null)
            {
                _btnSearch.Click += base.BtnSearch_Click;
            }
        }

        protected override Panel CreateSearchFIeldsPanel()
        {
            // 既存デザイナーで作成済みのレイアウトを使用するため、nullを返す
            return null; 
        }

        protected override void AdjustLayout()
        {
            if (IsInDesignMode()) { return; }

            // Null チェック
            if (_panelSearchBox == null || _btnSearch == null || _chkUnusedData == null)
                return;

            // サイズが0の場合もスキップ
            if (_panelSearchBox.Width <= 0 || _panelSearchBox.Height <= 0)
                return;

            // リサイズ時の位置は要調整。
            base.AdjustLayout();
            
        }

        protected override void BtnSearch_Click(object sender, EventArgs e)
        {
            base.BtnSearch_Click(sender, e);
        }

    }
}