怎么在text的KeyPress中截取回车键??

wangchong 2003-10-17 04:16:50
如题?
...全文
122 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
良朋 2003-10-18
  • 打赏
  • 举报
回复
.net 2003 中有些改动
e.KeyCode=13
e.KeyDate=Keys.Enter
都行,但没了KeyChar

lz305 2003-10-18
  • 打赏
  • 举报
回复
Private Sub txtserver_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtserver.KeyPress
If (e.KeyChar = Chr(13)) Then MsgBox("Enter is press!")
End Sub

已试过,可行!
kuangren 2003-10-17
  • 打赏
  • 举报
回复
其实就这么一句话:
if(e.KeyChar==13)
MessageBox.Show("Enter is press!");
kuangren 2003-10-17
  • 打赏
  • 举报
回复
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(48, 120);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(160, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==13)
MessageBox.Show("Enter is press!");
}
}
}
southdoor 2003-10-17
  • 打赏
  • 举报
回复
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
If e.KeyChar = Chr(13) Then'---------enter执行Tab功能

If TypeOf sender Is TextBox Then
CType(sender, TextBox).Focus()
CType(sender, TextBox).SelectAll()
End If

SendKeys.Send("{TAB}")
End If

If e.KeyChar = Chr(27) Then'escape-------------执行^Tab功能
If (TypeOf sender Is DateTimePicker) Then
sender.Focus()
Exit Sub

End If

SendKeys.Send("+{TAB}")

If TypeOf sender Is TextBox Then'''''选中文本

CType(sender, TextBox).Focus()
CType(sender, TextBox).SelectAll()

End If
End If

End Sub
kuangsha007 2003-10-17
  • 打赏
  • 举报
回复
js
if (event.keyCode == 13)
{
}
haoliqi 2003-10-17
  • 打赏
  • 举报
回复
webform下行吗
zwq78 2003-10-17
  • 打赏
  • 举报
回复
if e.keychar=chr(keys.enter) then
.....

16,553

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧