button1 _click event එකට දාලා හරියන්නෙ නෑ. button එකේ තියනව තව event එකක් KeyUp කියලා. එහෙම නැත්නම් KeyPress. එයින් එකකට දාන්න
protected void button1_KeyPress(object sender, EventArgs e)
{
if(e.KeyCode==Keys.Enter)
{
Console.Beep(261,500);
}
}



using System.Windows.Forms; namespace එක තියද ?
ඔයාට වෙන්න ඕන දේ කිව්වොත් sample එකක් කරලා දෙන්නම්![]()





මට ඕන ඔතන තියෙනබට්න් එක මවුස් ක්ලික් කරන්නෑතුව කීබෝඩ් එකේ x අකුරෙන් වැඩේ කරගන්න![]()
private void button1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.X)
{
button1.PerformClick();
}
}

Code:private void button1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.X) { button1.PerformClick(); } }
that's all then![]()
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace testingButton
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
[B][COLOR=Red] this.KeyPreview = true;
[COLOR=SeaGreen]this.button1.KeyDown[/COLOR] += new System.Windows.Forms.KeyEventHandler(this.[COLOR=Purple]button1_Click[/COLOR]);[/COLOR][/B]
}
[COLOR=Red][B] public void [COLOR=Purple]button1_Click[/COLOR](object sender, KeyEventArgs e)
{
if ([COLOR=Orange]e.KeyCode == Keys.A[/COLOR])
{
MessageBox.Show("Hello");
}
}[/B][/COLOR]
}
}
10 Errorsමේක දාන්න ඒක වැඩ කරනවා.
මෙතන හොදට බලාගන්න මේ highlightස් කරලා තියෙන තැන්
this.button1.KeyDown
වෙනුවට KeyUp වගේ යොදන්නත් පුලුවන්
e.KeyCode == Keys.A
මෙතන Keys.A ,Keys.B වගේ දන්න පුලුවන් Multiple දාන කොට
Keys.A && e.Control
AND කියලා දාන්න
Code:using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace testingButton { public partial class Form1 : Form { public Form1() { InitializeComponent(); [B][COLOR=Red] this.KeyPreview = true; [COLOR=SeaGreen]this.button1.KeyDown[/COLOR] += new System.Windows.Forms.KeyEventHandler(this.[COLOR=Purple]button1_Click[/COLOR]);[/COLOR][/B] } [COLOR=Red][B] public void [COLOR=Purple]button1_Click[/COLOR](object sender, KeyEventArgs e) { if ([COLOR=Orange]e.KeyCode == Keys.A[/COLOR]) { MessageBox.Show("Hello"); } }[/B][/COLOR] } }
මට මළ පයිනවාාාාාාාාාාාාාාාාාාාාාාාාා10 Errorsමට මළ පයිනවාාාාාාාාාාාාාාාාාාාාාාාාා
මොකක්? එච්චර එනවද?10 Errorsමට මළ පයිනවාාාාාාාාාාාාාාාාාාාාාාාාා

මොකක්? එච්චර එනවද?
දැන් ඔයා දාලා තියෙන ඔක්කොම delete කරන්න ඊට පස්සේ
this.button1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.button1_Click);
මේ කොටස delete කරන්න constructor එකේ තියෙන අතන thunder symbol එකෙන් දැම්ම නම් නමුත් button1_Click මේ නම සමාන විය යුතුයි.
procedure එකේ නමට.
