FrmSubstring.cs 2.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 CodeSplice
{
    public partial class FrmSubstring : Asa.Theme.FlatForm
    {
        private bool change;
        public string Code { set; get; }
        public string Mode { set; get; }
        public int Start { set; get; }
        public int Length { set; get; }

        public FrmSubstring()
        {
            InitializeComponent();
        }

        private void ShowStr()
        {
            label1.Text = Code.Substring(0, Start);
            label2.Text = Code.Substring(Start, Length);
            label3.Text = Code.Substring(Start + Length);
        }

        private void FrmSubstring_Load(object sender, EventArgs e)
        {
            change = true;
            TxtType.Text = Mode;
            flatNumberBox1.Value = Start;
            flatNumberBox1.Minimum = 0;
            flatNumberBox1.Maximum = Code.Length - 1;
            flatNumberBox2.Maximum = 1;
            flatNumberBox2.Value = Length;
            flatNumberBox2.Maximum = Code.Length;
            ShowStr();
            change = false;
        }

        private void FlatNumberBox1_ValueChanged(object sender)
        {
            if (change) return;
            change = true;
            int n = Convert.ToInt32(flatNumberBox1.Value);
            if (n + Length > Code.Length)
            {
                if (flatNumberBox2.Value > 1)
                {
                    flatNumberBox2.Value--;
                    Length = Convert.ToInt32(flatNumberBox2.Value);
                }
            }
            Start = n;
            change = false;
            ShowStr();
        }

        private void FlatNumberBox2_ValueChanged(object sender)
        {
            if (change) return;
            int n = Convert.ToInt32(flatNumberBox2.Value);
            if (n + Start > Code.Length)
                flatNumberBox2.Value--;
            Length = Convert.ToInt32(flatNumberBox2.Value);
            ShowStr();
        }

        private void BtnAllShow_Click(object sender, EventArgs e)
        {
            change = true;
            flatNumberBox1.Value = 0;
            flatNumberBox2.Value = Code.Length;
            Start = 0;
            Length = Code.Length;
            ShowStr();
            change = false;
        }

        private void BtnNo_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.No;
            Close();
        }

        private void BtnYes_Click(object sender, EventArgs e)
        {
            Mode = TxtType.Text;
            DialogResult = DialogResult.Yes;
            Close();
        }
    }
}