problem with contextmenustrip

Posted by Sravanthi.seeta under C# on 11/13/2010 | Points: 10 | Views : 2364 | Status : [Member] | Replies : 6
i have placed 2 textboxes and one contextmenustrip with color and font sub menus in windows application.. when i am trying to apply the fore color for textbox1 the coloring applying for the both textboxes,i dont want that to happen.. how can i fix it only for selected textbox

Reply me soon..its very urgent




Responses

Posted by: Dora743 on: 11/13/2010 [Member] Starter | Points: 25

Up
0
Down
Can u provide the code you have written

Dorababu

Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sravanthi.seeta on: 11/13/2010 [Member] Starter | Points: 25

Up
0
Down
i have placed two text boxes and one context menu strip for font,color(color is having two sub menu's i.e Fore color,back color)..
i assigned contextmenu property for both the text boxes.What i want is when i right click on the textbox1 r textbox2 for changing the fore color of the text, the respective textbox fore color should be change..
i had written like this but whether this is write or not i dn't know

private void foreColorToolStripMenuItem_Click(object sender, EventArgs e)
{

foreach (Control x in this.Controls)
{
if (x is TextBox)// here am checking for textboxes
{
TextBox t = (TextBox)x;
if (t.Focused==false)
{
colorDialog1.ShowDialog();
textBox1.ForeColor = colorDialog1.Color;
return;
}
else
{
colorDialog1.ShowDialog();
textBox2.ForeColor = colorDialog1.Color;
return;
}

}


}





}

Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dora743 on: 11/13/2010 [Member] Starter | Points: 25

Up
0
Down
Try this
private void textBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
contextMenuStrip1.Show(textBox1, e.Location);
}

and also the same for textbox2

Dorababu

Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sravanthi.seeta on: 11/13/2010 [Member] Starter | Points: 25

Up
0
Down
I didnt get u... can i write the code like that r not.. but am getting the result ..

Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dora743 on: 11/15/2010 [Member] Starter | Points: 25

Up
0
Down
Does the problem resolved

Dorababu

Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijay_07672 on: 9/28/2011 [Member] Starter | Points: 25

Up
0
Down
Here i am going to give you a very simple solution

private void foreColorToolStripMenuItem_Click(object sender, EventArgs e)
{
colorDialog1.ShowDialog();
if (textBox1.Focused == true)
{
textBox1.ForeColor = colorDialog1.Color;
}
if (textBox2.Focused == true)
{
textBox2.ForeColor = colorDialog1.Color;
}

if it helps you please reply........

Sravanthi.seeta, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response