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

mcwolfe

Well-known member
  • Jul 24, 2011
    6,919
    838
    113
    c# ගැන දන්න අය ඉන්න වනම් පොඩි උදව්වක් දෙන්න!

    මචන් c# වල බට්න් එකක් මව්ස් එකෙන් ක්ලික් කරන්නැතුව කීබෝඩ් එකේ කී එකක් ප්‍රෙස් කරල ඔබන්න පුලුවන් නේද ඒකට පාවිච්චි කරන කොඩ් එක මොකද්ද?:)
     

    Snowl

    Member
    Oct 1, 2011
    1,016
    137
    0
    Virtual Realm
    ඔහොම දැම්මට පෙස් කළාම වැඩනැතෝ :no:

    yeah you asked for the code
    so I gave you just try it.

    go to the designer.css
    and copy paste this code
    somewhere close to attributes of the button
    this.button.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.button_KeyPress)
    then in the form.css use this code
    private void button_KeyPress(object sender, KeyPressEventArgs e)
    {
    if(e.KeyCode()== Keys)
    {
    }
    }

    you may use Keys like this
    Keys.F8
    or
    Keys.F7 etc..
     

    Jolly_Roger

    Well-known member
  • May 2, 2009
    10,600
    1,606
    113
    Colombo XOR Matara
    KeyUp කියල event එකක් තියනවා.. ඒකෙ මෙහෙම පුලුවන්

    if (e.KeyCode == Keys.Enter)
    {

    bla bla......... :P

    }

    code එක තියනම් උදව්වක් කරන්න පුලුවන් :yes:
     

    SLIP_KNOT

    Member
    Nov 9, 2010
    652
    37
    0
    Hidden Behind The Closet
    ඔහොම දැම්මට පෙස් කළාම වැඩනැතෝ :no:
    එහෙම විතරක් දැම්මට වැඩක නෑ බන්, ඒ event එක ඇතුලට උබේ logic එක දාපන්..
    උබ button click event එකට දාපු code එකම.

    uda kattiya examples dala tiyenne.:)
     

    mcwolfe

    Well-known member
  • Jul 24, 2011
    6,919
    838
    113
    yeah you asked for the code
    so I gave you just try it.

    go to the designer.css
    and copy paste this code
    somewhere close to attributes of the button
    this.button.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.button_KeyPress)
    then in the form.css use this code
    private void button_KeyPress(object sender, KeyPressEventArgs e)
    {
    if(e.KeyCode()== Keys)
    {
    }
    }

    you may use Keys like this
    Keys.F8
    or
    Keys.F7 etc..

    key code කියන්නේ මොකද්ද?:rolleyes:
     

    Snowl

    Member
    Oct 1, 2011
    1,016
    137
    0
    Virtual Realm
    key code කියන්නේ මොකද්ද?:rolleyes:

    :rofl:
    ඒක method නෙවෙයි sorry () අයින් කරලා දාන්න
    එතකොට වැඩ කරනවා. මේකෙන් තමයි Capture කරගන්නේ
    ඔයා press කරන button එක ඒක predefine button විදියට හදාගෙන තියෙන
    button වලට සමාන නම් condition එක true වෙනවා ඊට පස්සේ ඊට
    අදාළ statements ටික ඇතුලේ දාන්න

    if(e.KeyCode== Keys.F8)
    {
    }

    ගොඩක් දාන්න ඕන නම්
    && use කරන්න

    Keys.F1 && e.ALT
     

    mcwolfe

    Well-known member
  • Jul 24, 2011
    6,919
    838
    113
    if(e.KeyCode== Keys.F8)
    {
    }
    }



    i

    මෙතනට දාන්නේ මොකද්ද?ඔයකෝඩ් එක දාපුවාම මේ කෑල්ල වැරදී කියනවනේ:rolleyes::rolleyes::rolleyes:


    :confused::P
     

    Jolly_Roger

    Well-known member
  • May 2, 2009
    10,600
    1,606
    113
    Colombo XOR Matara
    ඕක තමයි මචන් වැරදී කියන්නේ මෙන්න මෙහෙම තියෙන්නේ:yes::rofl:


    Uploaded with ImageShack.us

    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);
    }
    }
     
    Last edited:

    Snowl

    Member
    Oct 1, 2011
    1,016
    137
    0
    Virtual Realm
    directive එක use කරන්න කියලා කියන්නේ
    using System.Windows.Forms;
    මේක උඩින්ම දැම්මද?
    ඒ වගේම Solution Explorer එකේ තියෙන Reference වලට Add reference කියලා දාලා
    System.Windows.Forms මේක add කරගන්න
     

    Snowl

    Member
    Oct 1, 2011
    1,016
    137
    0
    Virtual Realm
    මෙතන ඔයා වැරදියිනේ
    Code:
    this.button.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.[COLOR=Red]button_KeyPress[/COLOR])

    මෙතන නම
    button_KeyPress

    සමාන වෙන්න ඕනේ procedure එකේ නමට
    private void button_KeyPress(object sender, KeyPressEventArgs e)
    {
    if(e.KeyCode()== Keys)
    {
    }
    }
     
    Last edited: