using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace JJMediSys { public partial class ReadBarcode : Form { [DllImport("user32.dll")]//*********************拖动无窗体的控件 public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); public const int WM_SYSCOMMAND = 0x0112; public const int SC_MOVE = 0xF010; public const int HTCAPTION = 0x0002; public ReadBarcode() { InitializeComponent(); } private void ReadBarcode_Load(object sender, EventArgs e) { int x = (Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2; int y = (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2; this.Location = new Point(x, y); TextInput.Focus(); } private void ReadBarcode_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } private void PicClose_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; this.Close(); } private void TextInput_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { string currentInput = TextInput.Text.Trim(); if (string.IsNullOrWhiteSpace(currentInput)) { return; } DialogResult = DialogResult.OK; this.Close(); } } private void BYes_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; this.Close(); } // 定义一个属性来获取用户输入的字符串 public string InputString { get { return TextInput.Text; } // 假设你的TextBox名字是textBoxInput } private void timer1_Tick(object sender, EventArgs e) { TextInput.Focus(); } } }