Setting .Text property of a group of textboxes from another control

  • Thread starter Thread starter eljainc
  • Start date Start date
E

eljainc

Hello,

I am trying to figure out how to efficiently do the following:

Say I have 10 TextBox fields on a form. From each of those, I would
like to have
a right click context menu. There are 10 menu items on the context
menu. Once
one of those items are selected, I would like the text to be copied
into the text field
of the appropriate textbox.

In the click Handler, I have something like:

private void myToolStripMenuItem_Click(object sender, EventArgs e)

{
ToolStripMenuItem m = (ToolStripMenuItem)sender;
string mystr = m.Text;
// set the text field


}

Can someone tell me the c# construct to set the Text property of the
"calling" object, in this case a textbox?

Thanks
Mike
 
Hello,

I am trying to figure out how to efficiently do the following:

Say I have 10 TextBox fields on a form. From each of those, I would
like to have
a right click context menu. There are 10 menu items on the context
menu. Once
one of those items are selected, I would like the text to be copied
into the text field
of the appropriate textbox.

In the click Handler, I have something like:

private void myToolStripMenuItem_Click(object sender, EventArgs e)

        {
            ToolStripMenuItem m = (ToolStripMenuItem)sender;
            string mystr = m.Text;
            // set the text field

        }

Can someone tell me the c# construct to set the Text property of the
"calling" object, in this case a textbox?

I'm sure there are probably more "elegant" ways to do it, but you
might want to consider some creative use of the ToolStripMenuItem's
Tag property.
 
Pete, thanks! The ContextMenu.SourceControl property is just what I
needed.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top