I am creating a login form in windows phone app , I want to trigger login button event on pressing enter button from finishing the form.
Requirement: While clicking enter button from last text field in login page should trigger login button event..
Code sample
I know how to move from one text field to another on clicking enter button as below
private void passkeydown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
nextfield .Focus();
}
}
But I don't know how to trigger button click event here.
Try This:
if (e.Key == Key.Enter)
{
LoginButton_Click(sender,e); //here LoginButton_Click is click eventhandler
}
Related
I have a form which navigates records through prev and next buttons. We can add a new entry by clicking new button. Prev,Next and new all are redirected to same form, prev and next populates form whereas new keep all entries empty and we can enter data. I have kept keypreview =true for this form and handled keydown().
if (e.KeyCode == Keys.Enter)
{
ProcessTabKey(true);
}
It works for prev and next key navigated form. But on pressing new and trying to press enter, its not working. Please suggest how to make this work.
use form keydown and type the textbox you want to write
Form_KeyDown(object sender, KeyEventArgs e) if (e.KeyCode == Keys.Enter) { ProcessTabKey(true); console.write(e.Key) }
I'm using C# windows form application, and i'm facing a problem resetting a button's back Color.
By clicking a button I need it to change its back color and reset the back color of previously pressed button.
Please note that i have lots of buttons in the form and i'm using "sender" to apply same clicking event to all buttons.
You'll need to keep track of the last button that was clicked. Add a private field and then manipulate it in the on click event handler:
class Form1 : Form
{
private Button _lastButtonClicked;
protected void ClickHandler(object sender, EventArgs e)
{
if (_lastButtonClicked != null)
_lastButtonClicked.BackColor = Color.whatever;
_lastButtonClicked = sender as Button;
_lastButtonClicked = Color.newcolor;
}
}
I have a TaskBar with buttons. at the TaskBar there is a lot of events, but there is only one event at the click of a button.
TaskBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.TaskBarButtonClick);
I need an event to a button press TaskBar middle mouse button.
something like
if (e.Button == MouseButtons.Middle)
{
MessageBox.Show("Middle");
}
only taskbar
I know this example. I did that. the problem is that the event for the Taskbar. I need an event to the button provided on this TaskBar
e.Button is not of type MouseButtons. It is of type ToolBarButton. So it references the location on the toolbar that is clicked, not the location on the mouse used to make the click.
Toolbar Button
If you need to handle which toolbar button is clicked then reference this example for using the ToolBarButtonClickEventHandler works.
//add some buttons.
TaskBar.Buttons.Add(new ToolBarButton()); //index 0
TaskBar.Buttons.Add(new ToolBarButton()); //index 1
//add the handler
TaskBar.ButtonClick += new ToolBarButtonClickEventHandler (
this.taskbar_ButtonClick);
private void taskbar_ButtonClick (Object sender, ToolBarButtonClickEventArgs e)
{
// Evaluate the Button property to determine which button was clicked.
switch(TaskBar.Buttons.IndexOf(e.Button))
{
case 0:
//Whatever you want to do when the 1st toolbar button is clicked
break;
case 1:
//Whatever you want to do when the 2nd toolbar button is clicked
break;
}
}
Mouse Button
You could add an event handler for the MouseDown event to trap the Mouse button that was clicked.
TaskBar.MouseDown += new MouseEventHandler(this.taskbar_MouseDown);
private void taskbar_MouseDown(object sender, MouseEventArgs e)
{
// Determine which mouse button is clicked.
if(e.Button == MouseButtons.Middle)
{
MessageBox.Show("Middle");
}
}
i have a WPF tab control with two tabs(A, B). Since there is no Clicked Event on the TabItem,therefore i add an previewMouseDown event on the Tab B and a messageBox will show up. However, after i close the messageBox, my application will not navigate to the Tab B. Anyone can help me?
C# code snippet :
private void MyTabB_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("Please login");
}
You can use the TabControlSelectionChanged event.
Since you know the selected tab for login say index 0, change selected tab after the MessageBox ie something like this
MyTabB_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
TabControl tc= ((TabControl)sender;
if(tc.SelectedIndex == tc.Items.IndexOf(A/*Login tab*/))
{
MessageBox.Show("Login")
tc.SelectedIndex = tc.Items.IndexOf(B);
}
}
This means whenever you select A you will MessageBox will pop up then you login.
Alternatively why not put a button or any control with ClickedEvent in A then when clicked tc.SelectedIndex is changed.
My login form has 4 controls. The user can input name, password and enter on button for login.
I'd like the Enter key to trigger the Login action after the Name and Password textboxes are filled out.
How can this be done? Trying to avoid btnLogin.Focus() under the TextBox event.
On your form you can set the AcceptButton property to the login button.
Set the form's AcceptButton property to be the Login button. When the user hits Enter, the Click event for that button will be triggered. The CancelButton property is the one you want for your Cancel button.
Again, these are properties of the Form, not the buttons.
private void txtCost_KeyUp(object sender, KeyEventArgs e)
{
//MessageBox.Show(Convert.ToString(e.KeyValue));
if (e.KeyValue == 13)
{
command;
}
}
Just Move your code to panel and set panel property DefaultButton="btnLogIn" Like
`<asp:Panel ID="pnlLogin" runat="server" DefaultButton="btnLogIn">
yOU CAN USE KEY PRESS event like this so whenever user press enter the event will fire.
private void txtMessage_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar.Equals(Convert.ToChar(13)))
{
btnLogin_Click(sender, e);
}
}