Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#键控事件不起作用_C#_Winforms_Visual Studio 2012 - Fatal编程技术网

C#键控事件不起作用

C#键控事件不起作用,c#,winforms,visual-studio-2012,C#,Winforms,Visual Studio 2012,我试图让应用程序在按下ENTER键后导航到web浏览器组件中的某个URL(条形码阅读器将数据输入条形码文本框,并编程为在每次扫描结束时添加“ENTER”)。然后,条形码编号通过URL发送到服务器进行验证,结果显示在web浏览器中 在阅读了关于堆栈溢出的内容后,我得出结论,没有设置this.KeyPreview,但是即使将其设置为True,也不会设置 我希望它所要做的就是,当在Form2上的任意位置按ENTER键时,它应该将WebBrowser组件URL更改为条形码文本框中包含的数据 using

我试图让应用程序在按下ENTER键后导航到web浏览器组件中的某个URL(条形码阅读器将数据输入条形码文本框,并编程为在每次扫描结束时添加“ENTER”)。然后,条形码编号通过URL发送到服务器进行验证,结果显示在web浏览器中

在阅读了关于堆栈溢出的内容后,我得出结论,没有设置
this.KeyPreview
,但是即使将其设置为True,也不会设置

我希望它所要做的就是,当在Form2上的任意位置按ENTER键时,它应该将
WebBrowser
组件URL更改为
条形码
文本框中包含的数据

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SUBWAY_deliverX_2017_POSlink
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            this.ActiveControl = Barcode;
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

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

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void Barcode_TextChanged(object sender, EventArgs e)
        {

        }

        private void Barcode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                webBrowser1.Navigate("https://10.0.0.142/deliverXPOSquery.php?barcode=" + Barcode.Text);
            }
        }
    }
}
和设计器文件:

namespace SUBWAY_deliverX_2017_POSlink
{
    partial class Form2
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form2));
            this.button1 = new System.Windows.Forms.Button();
            this.Barcode = new System.Windows.Forms.TextBox();
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.webBrowser1 = new System.Windows.Forms.WebBrowser();
            this.button2 = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.button1.Location = new System.Drawing.Point(177, 241);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(249, 79);
            this.button1.TabIndex = 0;
            this.button1.Text = "Return to SubShop";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // Barcode
            // 
            this.Barcode.BackColor = System.Drawing.SystemColors.Control;
            this.Barcode.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.Barcode.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Barcode.Location = new System.Drawing.Point(178, 323);
            this.Barcode.Name = "Barcode";
            this.Barcode.Size = new System.Drawing.Size(249, 24);
            this.Barcode.TabIndex = 1;
            this.Barcode.TextChanged += new System.EventHandler(this.Barcode_TextChanged);
            // 
            // pictureBox1
            // 
            this.pictureBox1.Image = global::SUBWAY_deliverX_2017_POSlink.Properties.Resources.delxstoreheader;
            this.pictureBox1.Location = new System.Drawing.Point(0, -2);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(589, 102);
            this.pictureBox1.TabIndex = 3;
            this.pictureBox1.TabStop = false;
            // 
            // webBrowser1
            // 
            this.webBrowser1.Location = new System.Drawing.Point(12, 106);
            this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
            this.webBrowser1.Name = "webBrowser1";
            this.webBrowser1.Size = new System.Drawing.Size(563, 120);
            this.webBrowser1.TabIndex = 4;
            this.webBrowser1.Url = new System.Uri("https://10.0.0.142/deliverXPOSquery.php", System.UriKind.Absolute);
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(471, 256);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(75, 23);
            this.button2.TabIndex = 5;
            this.button2.Text = "button2";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // Form2
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(587, 346);
            this.ControlBox = false;
            this.KeyPreview = true;
            this.Controls.Add(this.button2);
            this.Controls.Add(this.webBrowser1);
            this.Controls.Add(this.pictureBox1);
            this.Controls.Add(this.Barcode);
            this.Controls.Add(this.button1);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximumSize = new System.Drawing.Size(603, 385);
            this.MinimumSize = new System.Drawing.Size(603, 385);
            this.Name = "Form2";
            this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "deliverX 2017 - Order Validation";
            this.TopMost = true;
            this.Load += new System.EventHandler(this.Form2_Load);
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.TextBox Barcode;
        private System.Windows.Forms.PictureBox pictureBox1;
        private System.Windows.Forms.WebBrowser webBrowser1;
        private System.Windows.Forms.Button button2;
    }
}
namespace SUBWAY\u deliverX\u 2017\u POSlink
{
部分类别表格2
{
/// 
///必需的设计器变量。
/// 
private System.ComponentModel.IContainer components=null;
/// 
///清理所有正在使用的资源。
/// 
///如果应释放托管资源,则为true;否则为false。
受保护的覆盖无效处置(布尔处置)
{
if(处理和(组件!=null))
{
组件。Dispose();
}
基地。处置(处置);
}
#区域Windows窗体设计器生成的代码
/// 
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
私有void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager资源=新的System.ComponentModel.ComponentResourceManager(typeof(Form2));
this.button1=new System.Windows.Forms.Button();
this.Barcode=new System.Windows.Forms.TextBox();
this.pictureBox1=新系统.Windows.Forms.PictureBox();
this.webBrowser1=new System.Windows.Forms.WebBrowser();
this.button2=new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
这个.SuspendLayout();
// 
//按钮1
// 
this.button1.Font=new System.Drawing.Font(“Microsoft Sans Serif”,15.75F,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,((字节)(0)));
this.button1.Location=新系统图纸点(177241);
this.button1.Name=“button1”;
this.button1.Size=新系统图纸尺寸(249,79);
this.button1.TabIndex=0;
this.button1.Text=“返回子商店”;
this.button1.UseVisualStyleBackColor=true;
this.button1.Click+=新系统.EventHandler(this.button1\u Click);
// 
//条形码
// 
this.Barcode.BackColor=System.Drawing.SystemColors.Control;
this.Barcode.BorderStyle=System.Windows.Forms.BorderStyle.None;
this.Barcode.Font=new System.Drawing.Font(“Microsoft Sans Serif”,15.75F,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,((字节)(0)));
this.Barcode.Location=新系统图点(178323);
this.Barcode.Name=“Barcode”;
this.Barcode.Size=新系统.图纸.尺寸(249,24);
this.Barcode.TabIndex=1;
this.Barcode.TextChanged+=新系统.EventHandler(this.Barcode\u TextChanged);
// 
//pictureBox1
// 
this.pictureBox1.Image=global::SUBWAY_deliverX_2017_POSlink.Properties.Resources.delxstoreheader;
this.pictureBox1.Location=新系统图点(0,-2);
this.pictureBox1.Name=“pictureBox1”;
this.pictureBox1.Size=新系统图纸尺寸(589102);
this.pictureBox1.TabIndex=3;
this.pictureBox1.TabStop=false;
// 
//webBrowser1
// 
this.webBrowser1.Location=新系统.图纸.点(12,106);
this.webBrowser1.MinimumSize=新系统图纸尺寸(20,20);
this.webBrowser1.Name=“webBrowser1”;
this.webBrowser1.Size=新系统.Drawing.Size(563120);
this.webBrowser1.TabIndex=4;
this.webBrowser1.Url=new System.Uri(“https://10.0.0.142/deliverXPOSquery.php“,System.UriKind.Absolute);
// 
//按钮2
// 
this.button2.Location=新系统.图纸.点(471,256);
this.button2.Name=“button2”;
this.button2.Size=新系统图纸尺寸(75,23);
this.button2.TabIndex=5;
this.button2.Text=“button2”;
this.button2.UseVisualStyleBackColor=true;
this.button2.Click+=新系统.EventHandler(this.button2\u Click);
// 
//表格2
// 
此.AutoScaleDimensions=新系统.Drawing.SizeF(6F,13F);
this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize=新系统.Drawing.Size(587346);
this.ControlBox=false;
this.KeyPreview=true;
this.Controls.Add(this.button2);
this.Controls.Add(this.webBrowser1);
this.Controls.Add(this.pictureBox1);
本.控件.添加(本.条形码);
this.Controls.Add(this.button1);
this.Icon=((System.Drawing.Icon)(resources.GetObject($this.Icon));
this.MaximumSize=新系统图纸尺寸(603385);
此最小尺寸=新系统图纸尺寸(603385);
this.Name=“Form2”;
this.SizeGripStyle=System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition=System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text=“deliverX 2017-订单
 this.Barcode.BackColor = System.Drawing.SystemColors.Control;
            this.Barcode.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.Barcode.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Barcode.Location = new System.Drawing.Point(178, 323);
            this.Barcode.Name = "Barcode";
            this.Barcode.Size = new System.Drawing.Size(249, 24);
            this.Barcode.TabIndex = 1;
            this.Barcode.TextChanged += new System.EventHandler(this.Barcode_TextChanged);