gRussell
gRussell

Reputation: 3

Connect textbox text from a c# winForm to variable in static method

I'm new to C# and am working on this project

My code:

    private static void Anonymize(ElementList elementList)
    {
        string name = textBox3.Text;
        Anonimize(elementList.Get(DicomTag.PatientsName), PatientNames, "Patient Name " + name);
    }

when Anonimize method parameters are:

private static void Anonimize(Element element, Dictionary<string, string> dic, string pattern)

I would like to know how to be able to type in the patients name into a text box and have the program use it in the static method. The program needs to stay static and I can't add a textbox parameter because that will mess with my other code. Any help would be greatly appreciated.

Upvotes: 0

Views: 207

Answers (1)

Idle_Mind
Idle_Mind

Reputation: 39132

Create a static variable in your Form to reference textBox3 and assign it in the Load() event of the Form. Then change your method to use that static variable instead:

private static TextBox tb;

private void Form1_Load(object sender, EventArgs e)
{
    tb = this.textBox3;
}

private static void Anonymize(ElementList elementList)
{
    string name = tb.Text;
    Anonimize(elementList.Get(DicomTag.PatientsName), PatientNames, "Patient Name " + name);
}

Upvotes: 1

Related Questions