C
C#13mo ago
Luna

✅Modifying visual elements created in runtime

i'll send a snippet of my code
void x(){
TabPage tp = new TabPage("example");
TextBox tb = new TextBox();
tb.Text = "wasd";
tb.Dock = DockSytle.Fill;
tp.Controls.Add(tb);

tabControl1.TabPages.Add(tp);
}

void y(){
// how can i edit tb in this function
}
void x(){
TabPage tp = new TabPage("example");
TextBox tb = new TextBox();
tb.Text = "wasd";
tb.Dock = DockSytle.Fill;
tp.Controls.Add(tb);

tabControl1.TabPages.Add(tp);
}

void y(){
// how can i edit tb in this function
}
5 Replies
Luna
Luna13mo ago
for example i wanna change the text of this textbox in another function
Arch Leaders
Arch Leaders13mo ago
You need to expose that object to the other function Example:
class YourClass
{
private TextBox _tb = new();

public YourClass()
{
TabPage tp = new("example");
_tb.Text = "wasd";
_tb.Dock = DockSytle.Fill;
tp.Controls.Add(_tb);

tabControl1.TabPages.Add(tp);
}

public void YourFunction()
{
_tb.Text = "new text";
}
}
class YourClass
{
private TextBox _tb = new();

public YourClass()
{
TabPage tp = new("example");
_tb.Text = "wasd";
_tb.Dock = DockSytle.Fill;
tp.Controls.Add(_tb);

tabControl1.TabPages.Add(tp);
}

public void YourFunction()
{
_tb.Text = "new text";
}
}
Luna
Luna13mo ago
i have to declare this visual elements in my class, not inside the function? make sense i think
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Luna
Luna13mo ago
Oh Sorry
Want results from more Discord servers?
Add your server
More Posts