I am working with Visual Studio 2013 in Windows store app.
I have a two ToggleButtons.
They are working like switch:
I can check only one of them at a time.
When i check 1. toogle button then 2. toggle button unchecks.
When i check 2. toggle button then 1. toggle button unchecks.
My problem is when i check 1. toogle button and then click again 1. toogle button then it unchecks and then i have two unchecked toggle buttons.
My question is:
How to make the event that will know, when i clicked one toggle button that is already checked, it cannot be unchecked until i check the second toggle button. I need to disable the uncheked event for toggle button or something like that?
Something like this:
togglebutton1_CheckedChanged(...)
{
if(!togglebutton1.Checked && !togglebutton2.Checked)
togglebutton1.Checked=True;
}
togglebutton2_CheckedChanged(...)
{
if(!togglebutton2.Checked && !togglebutton1.Checked)
togglebutton2.Checked=True;
}
A radio button may suit your needs better, but..
private void Form1_Load(object sender, EventArgs e)
{
checkBox1.Appearance = Appearance.Button;
checkBox2.Appearance = Appearance.Button;
checkBox1.Checked = true;
checkBox2.Checked = false;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
if (checkBox2.Checked == true)
{
checkBox2.Checked = false;
}
}
else
{
if (checkBox2.Checked != true)
{
checkBox2.Checked = true;
}
}
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if (checkBox2.Checked == true)
{
if (checkBox1.Checked == true)
{
checkBox1.Checked = false;
}
}
else
{
if (checkBox1.Checked != true)
{
checkBox1.Checked = true;
}
}
}
Related
I have registed ctrl+` as a hotkey,and I want to display a window when I press the hotkey and not release the leftctrl key and toggle ` key to do something else just like alt+tab switch the application.Here is the code.
private void ListOnKeyDown(object sender, KeyEventArgs e)
{
if (e.SystemKey==Key.LeftCtrl && e.Key == Key.Oem3)
{
m_host.SelectNext();
}
}
But I found this way only fired one key.So what's the right way to fire the key event?
And here is the debug information.
debug information
Just change your keydown event to detect the modifier this way
private void ListOnKeyDown(object sender, KeyEventArgs e)
{
if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.Oem3)
{
m_host.SelectNext();
e.Handled = true;
}
}
Because onKeyDown event works for ONE key only, in order to use two keys at same time you need little improvise:
bool firstkeyisOn = false;
private void ListOnKeyDown(object sender, KeyEventArgs e)
{
if (e.SystemKey==Key.LeftCtrl/*Or other key by choice*/)
{
firstkeyisOn = true;
e.Handled = true;
return;
}
if(firstkeyisOn && (e.Key == Key.Oem3/*Or other key by choice*/))
{
m_host.SelectNext();
}
}
private void ListOnKeyUp(object sender, KeyEventArgs e)
{
if (e.SystemKey==Key.LeftCtrl/*Key must be same as holding one*/)
{
firstkeyisOn = false;
}
//or
//firstkeyisOn = false;
}
To cancel hotkey mode you just add firstkeyisOn = false under OnKeyUp event and you good to go.
i'm just new to c# and visual studio
so i figured how to mask the password in my datagridview with this
private void dataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 5 && e.Value != null)
{
dataGridView.Rows[e.RowIndex].Tag = e.Value;
e.Value = new String('\u25CF', e.Value.ToString().Length);
}
}
Now i wanted to show the password again when i click on the cell, i figured it would be on dataGridView_CellClick event but i can't figure how to make it show up again. do i assign it to e.Value again?
use a textbox by design in that column of gridview and from source add a checkbox too !
then use this code
private void FromSourceAddedCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (FromSourceAddedCheckBox.Checked == true)
{
GridviewTextboxID.UseSystemPasswordChar = true;
}
else
{
GridviewTextboxID.UseSystemPasswordChar = false;
}
}
I wanna do like agreement page and the visitor must check in the checkbox then he can click on button ( so the button should be disable unless he check ).
I typed this and nothing happened
protected void Checkbox1_CheckStatus(object sender, EventArgs e)
{
if (CheckBox1.Checked == true)
{
Button_login.Enabled = true;
}
if (CheckBox1.Checked == false)
{
Button_login.Enabled = false;
}
You should use the Checkbox CheckChanged property in order for this to work:
protected void checkBox1_CheckedChanged(object sender, EventArgs e){
Button_login.Enabled = CheckBox1.Checked; // Do not need any ifs
}
Hello I just started in Xamarin with an Android project and I encountered a problem on the keypress of an edittext. When the Enter is fired on my first Edittext and it gives focus to the Edittext (txtArtikel), but then the keypress of this Edittext is triggered and jumps to the third Edittext. So it skips my second Edittext with just one Enter press. Can anyone help me?
txtArtikel.KeyPress += txtArtikelPress;
private void txtArtikelPress(object sender, View.KeyEventArgs e)
{
e.Handled = false;
if (e.KeyCode == Keycode.Enter)
{
txtAantal.RequestFocus();
}
}
EDIT
I'm still working with the Keypress and now looking for an Enter and Escape. When the txtWerf is empty it jumps to txtArtikel, but when it contains text it goes to txtAantal.
private void txtWerfPress(object sender, View.KeyEventArgs e)
{
if (e.KeyCode == Keycode.Enter && e.Event.Action == KeyEventActions.Down)
{
if (txtWerf.Text.Trim() != "")
{
if (txtArtikel.RequestFocus())
e.Handled = true;
}
}
else
e.Handled = false;
}
private void txtArtikelPress(object sender, View.KeyEventArgs e)
{
if (e.KeyCode == Keycode.Enter && e.Event.Action == KeyEventActions.Down)
{
if (txtArtikel.Text.Trim() != "")
{
if (txtAantal.RequestFocus())
e.Handled = true;
}
}
else if (e.KeyCode == Keycode.Escape && e.Event.Action == KeyEventActions.Down)
{
if (txtWerf.RequestFocus())
e.Handled = true;
}
else
Scanner.CheckForScannedData(sender, ref e);
e.Handled = false;
}
private void txtAantalPress(object sender, View.KeyEventArgs e)
{
if (e.KeyCode == Keycode.Escape && e.Event.Action == KeyEventActions.Down)
{
if (txtArtikel.RequestFocus())
e.Handled = true;
}
else
e.Handled = false;
}
You don't need to handle the KeyPress event in order to set the focus to the next EditText.
Android has a good algorithm that handles the focus when editing is done.
How does the app behave on pressing enter when you remove the event handler? Does it set the focus to the correct EditText? If it focuses he wrong view then you should take a look on how to
Move to another EditText when Soft Keyboard Next is clicked on Android.
If the focus doesn't change at all then you should tell Android what to do when the user has completed his input by using android:imeOptions: http://developer.android.com/guide/topics/ui/controls/text.html#Actions.
I need to implement a check box to switch between two methods enabling/disabling some control. I am using the following code, I tried also in other ways but no luck.
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)//this is working
{
trackBar2.Enabled = false;
button3.PerformClick();
textBox8.Enabled = true;
}
else// this is supposed to work if checkbox is unchecked but doesn't work
{
trackBar2.Enabled = true;
textBox8.Enabled = false;
}
}
The result I get is always the same. If I check the checkbox the first condition is meet and it is fine. If I uncheck the text box, nothing happen and does not go back to the first condition either.
How can I detect the checked/unchecked condition?
You could also write that as:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
trackBar2.Enabled = !checkBox1.Checked;
textBox8.Enabled = checkBox1.Checked;
if (checkBox1.Checked)
{
button3.PerformClick();
}
}
I think you should add if(checkBox1.Checked == false) to the else :
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)//this is working
{
trackBar2.Enabled = false;
button3.PerformClick();
textBox8.Enabled = true;
}
else if(checkBox1.Checked == false)
{
trackBar2.Enabled = true;
textBox8.Enabled = false;
}
}