Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm coding a Skype Tool.
I'm trying to get it to be black listed so they can spam people they won't from a checked list box but I set up everything right that I know of and I receive this on skype. system.windows.forms.checkedlistbox+checkeditemcollection it spams to that instead of the selected people I've chosen? Here's the code:
private void metroButton6_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(checkedListBox1.CheckedItems.ToString()) && !string.IsNullOrEmpty(metroTextBox5.Text))
{
timer3.Start();
}
}
private void timer3_Tick(object sender, EventArgs e)
{
skype.SendMessage(checkedListBox1.CheckedItems.ToString(), metroTextBox5.Text);
}
private void metroButton9_Click(object sender, EventArgs e)
{
timer3.Stop();
}
The SelectedItem of ComboBox is always a object which cannot be compared with a string. that's why you are getting such exception, so i suggest you to use:
metroComboBox1.SelectedItem.ToSting();
Hence your if will be like the following:
if (!string.IsNullOrEmpty(metroComboBox1.SelectedItem.ToString()) && !string.IsNullOrEmpty(metroTextBox1.Text))
{
// code here
}
and the sending message will be like this:
skype.SendMessage(metroComboBox1.SelectedItem.ToString, metroTextBox1.Text);
The reason for this error is metroComboBox1.SelectedItem is of type object. The method string.IsNullOrEmpty expects a string as parameter. So you can try this
if (!string.IsNullOrEmpty(metroComboBox1.SelectedItem as string) && ...
The as operator returns a string or null if metroComboBox1.SelectedItem is null or not a string.
But if SelectedItem is not a string you may rather use this:
if (!(metroComboBox1.SelectedItem == null ||
string.IsNullOrEmpty(metroComboBox1.SelectedItem.ToString())) && ...
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Good morning everyone!
So, I have 8 textboxes and under those are checkboxes. To those textboxes I'am always receiving data from a serialport and I need to do an average from those values. But I only want to do the average from the textboxes from which I checked the checkbox under them.
How can I add those values to the average formula when selected by checking the checkbox?
If anyone could help, I would really apreciate.
Thanks,
Jonathan
I think you should write something like this :
bool[] CheckBoxList { get; set; } = new bool[8];
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBoxList[0] = checkBox1.Checked;
CalcAverage();
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
CheckBoxList[1] = checkBox2.Checked;
CalcAverage();
}
in CalcAverage method , Textboxes with a true value in the list are computed.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
protected void btnsubmit_Click(object sender, EventArgs e)
{
int result;
result=Convert.ToInt32(lblresult.Text);
}
this is all I have so far (just the variable)
Convert lblStart.Text value to int every time and assign it to i. Then increase i.
protected void btnsubmit_Click(object sender, EventArgs e)
{
i = Int32.Parse(lblStart.Text);
i++;
lblStart.Text = i.ToString();
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
How can I make a TextArea that accepts only the words I have already set
with C# on Visual studio.
I'm a beginner in programming.
update:
what (-3) about?
like I said I'm a beginner, trying to build android game with c#.
until now just do some mistakes.
this website little complex to handle with but I will get used to it :) and my english poor
thank you all.
Use TextBox and add TextChanged event on your tool
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (!System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text, "^[a-zA-Z]"))
{
MessageBox.Show("This textbox accepts only alphabetical characters");
textBox1.Text.Remove(textBox1.Text.Length - 1);
}
}
More Info
textBox1.TextChanged += new TextChangedEventHandler(textBox1_TextChanged);
private void textBox1_TextChanged(object sender, EventArgs e)
{
Regex regex = new Regex(#"[^0-9^+^\-^\/^\*^\(^\)]");
MatchCollection matches = regex.Matches(textBox1.Text);
if (matches.Count > 0) {
//tell the user
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
string yourWord = "mouse";
if (textBox1_Text.Text.Contains(yourWord))
{
textBox1_Text.Text.Replace(yourWord, "");
}
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have problem with ListBox.
I made a method that does some work and returns a ListBox type. I tried to get this Listbox instance from the method, but the ListBox doesn't show any items.
I hope to know how I can replace the existing ListBox with the returned Listbox from the method.
public ListBox GetProduct()
{
ListBox MyListBox = new ListBox();
MyListBox.Sorted = true;
MyListBox.Items.Add("aaaaa");
return MyListBox;
}
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
listBox1 = GetProduct();
}
try this:
public void GetProduct(ListBox MyListBox)
{
MyListBox.Sorted = true;
MyListBox.Items.Add("aaaaa");
}
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
GetProduct(listBox1);
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I made a timer, but when I press a button nothing happens.
My code is:
private void button3_Click(object sender, EventArgs e)
{
Instellingen form = new Instellingen();
form.Show();
}
Instellingen.cs code:
public partial class Instellingen : Form
{
public Instellingen()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
MessageBox.Show("text", "text");
}
}
}
The button3 event doesn't even fire (confirmed by adding a breakpoint, it doesn't get there)
Check if the button's event realy connected to the method button3_Click.
Put a breakpoint in the first line of button3_Click and check if the code get there.
Make sure your button's click event is button3_Click. Probably your button's click event is empty.