Question how do i delete or remove comments inside the button programatically?

poringgunner

Active member
Joined
Feb 23, 2014
Messages
42
Programming Experience
Beginner
hi. someone can give help? i need to finish my project this month :(
my problem is how can i delete comments (/*) inside of this button
        private void button3_Click(object sender, EventArgs e)
        {
            /*
            if (richbox1.Text.Equals(richbox2.Text))
            {
                MessageBox.Show("Equal");
            }
            else
            { 
                MessageBox.Show("Not Equal"):
            }
             */
        }

i want to delete it when i click the checkedbox. someone can help?
thanks in advance
 
Last edited by a moderator:
do you mean that i will put that in the other buttons? like this
private void button3_Click(object sender, EventArgs e)
{
var rtb = (RichTextBox) myTabPage.Controls[0]
}


what is the meaning of [0]? im confused to use it.. :(
 
do you mean that i will put that in the other buttons? like this
private void button3_Click(object sender, EventArgs e)
{
var rtb = (RichTextBox) myTabPage.Controls[0]
}


what is the meaning of [0]? im confused to use it.. :(

I don't know what button3 does. It if it had a name that actually gave a clue to what its purpose is then maybe I would. You put that code where you want to use tyhe RichTextBox in code. If you want to use the RichTextBox when the user clicks button3 then that's where you put it. Of course, you need more code after that to actually use the RichTextBox you just referenced to make it useful.

Controls is a collection and it contains all the children of a parent control. The TabPage is the parent and the RichTextBox is the child, so the RichTextBox is in the TabPage's Controls collection. You access items in a collection by index, so Controls[0] is the item at index zero, i.e. the first item.
 
ok i understand.. i use that button3 for comparing the contents of each richtextbox. i.e
the one richtextbox contains "how to compare"
and the other richtextbox constaisn different.. how i should do that? that is possible? and give the result?
 
I'm afraid that I'm not going to keep repeating myself. I've told you how to get a reference to one of your RichTextBoxes. Once you have a reference then you use it exactly as you usually would.
 
var rtb = (RichTextBox) myTabPage.Controls[0]
so this is all i need to put in button3? to access all the contents of richtextboxes.
example i compare 2 richtextboxes like this
if(rich.line[0].length.Equals(rich.line[0].length))
{
MessageBox.Show("Equal");
}

i think it will only give a Equals. whenever the richtextboxes are not equal?
 
For a start, that's not valid code. Secondly, that doesn't compare two RichTextBoxes. You seem determined to make this harder than it is. Let's say that you added two RichTextBoxes to the form in the designer and you named them richTextBox1 and richTextBox2. You'd be able to use those two RichTextBoxes in code to compare them no problem, right? If you now add two RichTextBoxes to your form at run time using the code you have, you can get access to those RichTextBoxes in code like so:
 var richTextBox1 = (RichTextBox) tabControl1.TabPages[0].Controls[0]
var richTextBox2 = (RichTextBox) tabControl1.TabPages[1].Controls[0]
Look at that! You've now got two variables name richTextBox1 and richTextBox2 that each refer to a RichTextBox control. As I have now said several times, you use those variables in EXACTLY the same way as you would if you'd added the RichTextBoxes at design time. A RichTextBox is a RichTextBox. How you reference it is completely irrelevant to how you use it. You don't kick a ball in a different way depending on whether you bought it yourself or someone gave it to you; it's still the same ball regardless.
 
so if i want many.. i will declare it like u did? where did i put this code
var richTextBox1 = (RichTextBox) tabControl1.TabPages[0].Controls[0]
var richTextBox2 = (RichTextBox) tabControl1.TabPages[1].Controls[0]
in the button for browse or button for comparing?
if i put this code to mine. i will look like this
var richTextBox1 = (rich) tabControl1.TabPages[0].Controls[0]
var richTextBox2 = (rich) tabControl1.TabPages[1].Controls[0]
because i create richtextbox like this
Richtextbox rich = new Richtextbox { Parent = tab, Dock = Dockstyle.fill }
this is right?

 
No that's not right. That 'rich' is just a local variable and no longer exists when you're trying to use the RichTextBoxes to compare their contents. This:
C#:
var richTextBox1 = [B][U](RichTextBox) [/U][/B]tabControl1.TabPages[0].Controls[0]
is a cast. It's specifying that the Control reference that you get from the Controls collection is a RichTextBox and not just a Control, so the 'richTextBox1' variable type RichTextBox rather than type Control.
 
it is ok whenever i use rich as new richtextbox in button for browse?
then i use var richTextBox1 = (RichTextBox) tabControl1.TabPages[0].Controls[0] in button for comparing? i am right? the rich is no concern for the Richtextbox anymore when i use this in button for comparing?
or i will change the rich. into Richtexbox = new Richtextbox();?
 
Back
Top Bottom