📄 class.txt
字号:
void button1_Click(Object* sender, System::EventArgs* /*e*/) {
/* If the CTRL key is pressed when the
* control is clicked, hide the control. */
if (Control::ModifierKeys == Keys::Control) {
(dynamic_cast<Control*>(sender))->Hide();
}
}
[JScript] 没有可用于 JScript 的示例。若要查看 Visual Basic、C# 或 C++ 示例,请单击页左上角的“语言筛选器”按钮 。
要求
平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列, .NET Framework 精简版
.NET Framework 类库
Control.Show 方法
向用户显示控件。
[Visual Basic]
Public Sub Show()
[C#]
public void Show();
[C++]
public: void Show();
[JScript]
public function Show();
备注
显示控件等效于将 Visible 属性设置为 true。在调用 Show 方法之后,只要不调用 Hide 方法,Visible 属性就返回 true 值。
示例
[Visual Basic, C#, C++] 下面的示例显示了一个关于对话框并在其表面临时绘制了一个蓝色正方形。本示例假定已定义了一个从 Form 派生的、名为 AboutDialog 的类。
[Visual Basic]
Private Sub menuItemHelpAbout_Click(sender As Object, _
e As EventArgs) Handles menuItemHelpAbout.Click
' Create and display a modless about dialog box.
Dim about As New AboutDialog()
about.Show()
' Draw a blue square on the form.
' NOTE: This is not a persistent object, it will no longer be
' visible after the next call to OnPaint. To make it persistent,
' override the OnPaint method and draw the square there
Dim g As Graphics = about.CreateGraphics()
g.FillRectangle(Brushes.Blue, 10, 10, 50, 50)
End Sub
[C#]
private void menuItemHelpAbout_Click(object sender, EventArgs e)
{
// Create and display a modless about dialog box.
AboutDialog about = new AboutDialog();
about.Show();
// Draw a blue square on the form.
/* NOTE: This is not a persistent object, it will no longer be
* visible after the next call to OnPaint. To make it persistent,
* override the OnPaint method and draw the square there */
Graphics g = about.CreateGraphics();
g.FillRectangle(Brushes.Blue, 10, 10, 50, 50);
}
[C++]
private:
void menuItemHelpAbout_Click(Object* /*sender*/, EventArgs* /*e*/) {
// Create and display a modeless about dialog box.
AboutDialog* about = new AboutDialog();
about->Show();
// Draw a blue square on the form.
/* NOTE: This is not a persistent object, it will no longer be
* visible after the next call to OnPaint. To make it persistent,
* override the OnPaint method and draw the square there */
Graphics* g = about->CreateGraphics();
g->FillRectangle(Brushes::Blue, 10, 10, 50, 50);
}
[JScript] 没有可用于 JScript 的示例。若要查看 Visual Basic、C# 或 C++ 示例,请单击页左上角的“语言筛选器”按钮 。
要求
平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列, .NET Framework 精简版
[C#]
// This example demonstrates how to use the KeyDown event with the Help class to display
// pop-up style help to the user of the application. The example filters for all variations
// of pressing the F1 key with a modifier key by using the KeyEventArgs properties passed
// to the event handling method.
// When the user presses any variation of F1 that includes any keyboard modifier, the Help
// class displays a pop-up window, similar to a ToolTip, near the control. If the user presses
// ALT + F2, a different Help pop-up is displayed with additional information. This example assumes
// that a tTextBox control, named textBox1, has been added to the form and its KeyDown
// event has been contected to this event handling method.
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
// Determine whether the key entered is the F1 key. If it is, display Help.
if(e.KeyCode == Keys.F1 && (e.Alt || e.Control || e.Shift))
{
// Display a pop-up Help topic to assist the user.
Help.ShowPopup(textBox1, "Enter your name.", new Point(textBox1.Bottom, textBox1.Right));
}
else if(e.KeyCode == Keys.F2 && e.Modifiers == Keys.Alt)
{
// Display a pop-up Help topic to provide additional assistance to the user.
Help.ShowPopup(textBox1, "Enter your first name followed by your last name. Middle name is optional.",
new Point(textBox1.Top, this.textBox1.Left));
}
}
---------------
KeyPressEventHandler 委托
表示将要处理 Control 的 KeyPress 事件的方法。
[C#]
[Serializable]
public delegate void KeyPressEventHandler(object sender,KeyPressEventArgs e);
参数 [Visual Basic, C#, C++]
事件处理程序的声明必须与 KeyPressEventHandler 委托声明具有相同的参数。
sender
事件源。
e
包含事件数据的 KeyPressEventArgs。
备注
将 KeyPressEventArgs.Handled 设置为 true,以取消 KeyPress 事件。这可防止控件处理按键。
当创建 KeyPressEventHandler 委托时,标识将处理事件的方法。要使该事件与事件处理程序相关联,请将该委托的一个实例添加到事件中。除非移除了该委托,否则每当发生该事件时就调用事件处理程序。有关用委托处理事件的更多信息,请参见事件和委托。
[C#]
using System;
using System.Windows.Forms;
public class Form1: Form
{
public Form1()
{
// Create a TextBox control.
TextBox tb = new TextBox();
this.Controls.Add(tb);
tb.KeyPress += new KeyPressEventHandler(keypressed);
}
void keypressed(Object o, KeyPressEventArgs e)
{
// The keypressed method uses the KeyChar property to check
// whether the ENTER key is pressed.
// If the ENTER key is pressed, the Handled property is set to true,
// to indicate the event is handled.
if(e.KeyChar == (char)13)
e.Handled=true;
}
public static void Main()
{
Application.Run(new Form1());
}
}
--------------------
.NET Framework 类库
KeyPressEventArgs 成员
KeyPressEventArgs 概述
公共构造函数
KeyPressEventArgs 构造函数 初始化 KeyPressEventArgs 类的新实例。
受 .NET Framework 精简版的支持。
公共属性
Handled 获取或设置一个值,该值指示是否处理过 KeyPress 事件。
受 .NET Framework 精简版的支持。
KeyChar 获取与按下的键对应的字符。
受 .NET Framework 精简版的支持。
公共方法
Equals(从 Object 继承)
受 .NET Framework 精简版的支持。
已重载。确定两个 Object 实例是否相等。
GetHashCode(从 Object 继承)
受 .NET Framework 精简版的支持。
用作特定类型的哈希函数,适合在哈希算法和数据结构(如哈希表)中使用。
GetType(从 Object 继承)
受 .NET Framework 精简版的支持。
获取当前实例的 Type。
ToString(从 Object 继承)
受 .NET Framework 精简版的支持。
返回表示当前 Object 的 String。
受保护的方法
Finalize(从 Object 继承)
受 .NET Framework 精简版的支持。
已重写。允许 Object 在“垃圾回收”回收 Object 之前尝试释放资源并执行其他清理操作。
在 C# 和 C++ 中,使用析构函数语法来表示终结程序。
MemberwiseClone(从 Object 继承)
受 .NET Framework 精简版的支持。
创建当前 Object 的浅表副本。
请参见
KeyPressEventArgs 类 | System.Windows.Forms 命名空间
KeyPressEventArgs 构造函数
public KeyPressEventArgs(
char keyChar
);
参数
keyChar
与用户按下的键相对应的 ASCII 字符。
备注
使用 Control.ModifierKeys 属性获取修改键的当前状态。
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -