简体   繁体   中英

Calling A Tool From Another Form to Another?

im working on a code-editor(winforms) and Im just wondering if its possible to call a specific box from a form to another?

sample for this set of codes:

int line = 1 + richTextBox1.GetLineFromCharIndex(richTextBox1.GetFirstCharIndexOfCurrentLine());
int column = 1 + richTextBox1.SelectionStart - richTextBox1.GetFirstCharIndexOfCurrentLine();
label1.Text = "line: " + line.ToString() + ", column: " + column.ToString();

***code above was inside a timer which calls the count of line and column in a richtextbox like in lower rightpart of actual code editor .

now im just wondering if its possible to call the label that displays to the main form and will display to another but will still run .

like in mainform theres the code for richtextbox and on other form it should have the code of label that connects to the mainform .

my question is it possible to call a tool function from another form to another?

hope you could help me, really in need and thanks a lot!

As long as you have a reference to that form toolbox, just expose that Label / TextBox or whatever you want to change via a public property and set it from your context.

public class ToolBox : ToolBoxBase
{
   public CustomLabel
   {
      get
      {
         return label1.Text;
      }
      set
      {
         label1.Text = value;
      }
   }
}

private ToolBox toolbox;
void ShowToolBox()
{
   InitToolBox();
   toolbox.CustomLabel = "New label";
}

As I'm not even sure what technology the question refers to I added a poor pseudo example to get you the idea. The InitToolBox method initializes the toolbox and displays it, and sets the field toolbox with a reference to it.

If the other form runs on another thread, then you'll have to invoke the label setter asynchronously. See this question for more instructions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM