cloudflight
2023-12-02 1a5ef6b2bf25de50b685b44299d9a049a2feac80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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 ConfigApp
{
    public partial class InputBox : Form
    {
        DialogResult _DialogResult;
 
        void initPosition()
        {
            this.StartPosition = FormStartPosition.Manual;
            int offsetX = -1 * this.Width / 2; // 距离鼠标左侧的间距
            int offsetY = -1 * this.Height / 2; // 距离鼠标顶部的间距
            int newWindowWidth = this.Width; // 新窗口的宽度
            int newWindowHeight = this.Height; // 新窗口的高度
            Point mousePosition = MousePosition; // 获取鼠标位置
 
            this.Location = new Point(mousePosition.X + offsetX, mousePosition.Y + offsetY); // 计算新窗口的位置
        }
        public InputBox()
        {
            InitializeComponent();
            initPosition();
 
        }
        public InputBox(string txt,string content="")
        {
            
            InitializeComponent();
            initPosition();
            this.Text = txt;
            this.textBox1.Text = content;
 
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            _DialogResult = DialogResult.OK;
            this.Close();
 
        }
        private void button2_Click(object sender, EventArgs e)
        {
            _DialogResult = DialogResult.Cancel;
            this.Close();
        }
        public new string ShowDialog()
        {
 
            base.ShowDialog();
            if (_DialogResult == DialogResult.OK)
                return textBox1.Text;
            else
                return null;
            
        }
 
        
    }
}