Jump to content

utilizar o enter


Senior
 Share

Recommended Posts

Deduzi que fosse algo do género... mas... a partir de onde? Uma textbox?

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Chr(Keys.Enter) Then Button1_Click(Nothing, Nothing)
    End Sub

Onde o Button1_Click é o handler do Button1.Click (o que é automáticamente gerado quando dás 2 cliques no botão, em "design time")

Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Link to comment
Share on other sites

Eu prefiro chamar o sub.

Já tive uma má experiência com o PerformClick. Não a consegui reproduzir desde então, mas fiquei escaldado

Se fizeres PerformClick() a um botão numa ToolStrip, por exemplo, ele faz o efeito de pressionar o botão, o que não fica muito agradável visualmente. Tirando isso funciona bem 🙂

Link to comment
Share on other sites

Senior, se estiveres a trabalhar em Windows Forms, tens uma propriedade na form, que é o AcceptButton, associas o botão que terá a acção que queres, e está feito. Eu acho que é isto que queres.

Oracle Certified Professional - AdministraçãoOracle Certified Professional - Pl/sqlMCPD - Microsoft Certified Professional DeveloperMCTS - Microsoft Certified Technology Specialist

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.