c# ගැන දන්න අය ඉන්න වනම් පොඩි උදව්වක් දෙන්න!

SLIP_KNOT

Member
Nov 9, 2010
652
37
0
Hidden Behind The Closet
Capture.jpg


KeyCode වැඩ කරන්නේ නැත්නම් ඔය විදියට KeyChar use කරපන්.
 

mcwolfe

Well-known member
  • Jul 24, 2011
    6,919
    838
    113
    button1 _click event එකට දාලා හරියන්නෙ නෑ. button එකේ තියනව තව event එකක් KeyUp කියලා. එහෙම නැත්නම් KeyPress. එයින් එකකට දාන්න :yes:

    protected void button1_KeyPress(object sender, EventArgs e)
    {
    if(e.KeyCode==Keys.Enter)
    {
    Console.Beep(261,500);
    }
    }



    Uploaded with ImageShack.us:baffled:
     

    nadun07

    Member
    Mar 17, 2008
    10,852
    686
    0
    http://
    inside the KeyDown event call the button's perform click method ;)

    private void button1_KeyDown(object sender, KeyEventArgs e)
    {
    if (e.KeyCode == Keys.Enter)
    {
    button1.PerformClick();
    }
    }


    and inside the click event of button1 write the code for what u wanna do when it's clicked ( OR when the enter key is pressed )
     
    • Like
    Reactions: mcwolfe

    mcwolfe

    Well-known member
  • Jul 24, 2011
    6,919
    838
    113
    using System.Windows.Forms; namespace එක තියද ?

    ඔයාට වෙන්න ඕන දේ කිව්වොත් sample එකක් කරලා දෙන්නම් ;)

    මට ඕන ඔතන තියෙනබට්න් එක මවුස් ක්ලික් කරන්නෑතුව කීබෝඩ් එකේ x අකුරෙන් වැඩේ කරගන්න :yes::D:P:rofl:
     

    nadun07

    Member
    Mar 17, 2008
    10,852
    686
    0
    http://
    මට ඕන ඔතන තියෙනබට්න් එක මවුස් ක්ලික් කරන්නෑතුව කීබෝඩ් එකේ x අකුරෙන් වැඩේ කරගන්න :yes::D:P:rofl:

    Code:
    private void button1_KeyDown(object sender, KeyEventArgs e)
    {
    if (e.KeyCode == Keys.X)
    {
    button1.PerformClick();
    }
    }

    that's all then :P
     

    Snowl

    Member
    Oct 1, 2011
    1,016
    137
    0
    Virtual Realm
    මේක දාන්න ඒක වැඩ කරනවා.
    මෙතන හොදට බලාගන්න මේ 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]
        }
    }
     

    mcwolfe

    Well-known member
  • Jul 24, 2011
    6,919
    838
    113
    මේක දාන්න ඒක වැඩ කරනවා.
    මෙතන හොදට බලාගන්න මේ 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:dull: මට මළ පයිනවාාාාාාාාාාාාාාාාාාාාාාාාා
     

    Snowl

    Member
    Oct 1, 2011
    1,016
    137
    0
    Virtual Realm
    10 Errors:dull: මට මළ පයිනවාාාාාාාාාාාාාාාාාාාාාාාාා
    :rofl: මොකක්? එච්චර එනවද?

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

    SLIP_KNOT

    Member
    Nov 9, 2010
    652
    37
    0
    Hidden Behind The Closet
    10 Errors:dull: මට මළ පයිනවාාාාාාාාාාාාාාාාාාාාාාාාා

    කලින් තිබිච්ච විදිය හරි බන්..
    unledmx.png


    ඔතන button1.PerformClick(); එක වෙනුවට

    MessageBox.Show("Hello"); දාල බලපන් වැඩ නැද්ද කියල.. ඕක තව complex කරගන්න එපා.:yes:
     

    mcwolfe

    Well-known member
  • Jul 24, 2011
    6,919
    838
    113
    :rofl: මොකක්? එච්චර එනවද?

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

    Error 1 No overload for 'button1_Click' matches delegate 'System.EventHandler' C:\Documents and Settings\****\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Form1.Designer.cs 42 35 WindowsFormsApplication1
    :sorry:
     
    Last edited: