Click here to Skip to main content
16,019,349 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, i am new to c# programming
but whenever i type Adam in the textbox the messagebox shows up even though i did not click button1, But the checkbox works normally with button1 please help me.





C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace C_tutorials
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int i=0;

            if (textBox1.Text == "Adam" || checkBox1.Checked)

                MessageBox.Show("hello");


        }


    }
}
Posted
Comments
Kenneth Haugland 8-Feb-15 17:40pm    
https://msdn.microsoft.com/en-us/library/6373h346.aspx
fun Tertain 8-Feb-15 17:45pm    
lol i figure that the events of the textbox and checkbox were wired to the button1 function if you know what i mean. So checkChanged and textChanged both ran the button1 function
Kenneth Haugland 8-Feb-15 17:49pm    
From your question I guess you want this one instead;
https://msdn.microsoft.com/en-us/library/2a723cdk.aspx
&&
:)
fun Tertain 8-Feb-15 17:53pm    
i guess the link answers my question partially as of why checkbox1 did not run right away until i clicked button1. but it seemed to work fine after i erased the fact that textbox1 and checkbox1 were connected to the button 1 function
Kenneth Haugland 8-Feb-15 18:04pm    
Sounds like you are a little confused. The || operator will, given that the function Button1_Click() is started, check if either the Text is Adam or the checkbox is checked. It just needs one of them to be true in order to proceed to show the message. What else you are saying dosnt relly make any sence to me, but the again, I don't see all your code either.

1 solution

button1 event was wired to textbox1 and checkbox1
 
Share this answer
 
Comments
[no name] 8-Feb-15 23:36pm    
As per your question posted here if the checkbox is checked or the textbox is having the text as "Adam" then only your messagebox should pop out. There is another scenario where you can face the same situation. That is if you are having the same method name refered in the textbox text changed event your messagebox is going to display.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900