C# textbox waarde geven vanuit script...
ik heb dit als soort van textbox
De vraag,
hoe krijg ik textInput.setVal() , textInput.getVal() en textInput.reset() werkend als ik ze in de main aanroep.
ik heb dit als soort van textbox
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
| // waarschijnlijk teveel, maar ik heb nog nooit met c# geknoeit, weet nog niet wat voor wat is, en mij
// progammaatje is ook iets uigebreider
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Reflection;
using System.Collections;
using System.Data;
using System.IO;
using System.Diagnostics;
using System.Threading;
public class textInput : GroupBox
{
private string initVal;
public TextBox TIVal = new TextBox();
public textInput()
{}
public textInput(string text , string value)
{
Label label1= new Label();
label1.Text = text+":";
label1.Location = new Point(10,17);
label1.Size = new Size (label1.PreferredWidth, label1.PreferredHeight);
TIVal = new TextBox();
TIVal.Location = new Point(100, 15);
TIVal.Size = new Size(200, 50);
TIVal.Text = value;
this.Controls.Add(label1);
this.Controls.Add(TIVal);
this.FlatStyle = FlatStyle.System;
this.Size = new Size(310 , 44);
}
public string getVal()
{
return TIVal.Text;
}
public void setVal(string aap)
{
TIVal.Text = aap;
initVal = aap;
Console.WriteLine("Debug shit from TBOX: "+getVal());
Console.WriteLine("SETVAL from TBOX: "+TIVal.Text);
}
public void reset(string value)
{
TIVal.Text = initVal;
}
}
public class TestForm : Form
{
public textInput textServer = new textInput();
public TestForm ()
{
InitializeComponent();
}
/*
private void InitializeComponent()
{
textInput textServer = new textInput("Server" , "jhjhggj");
textServer.Location = new Point(0 , 0);
this.Controls.Add(textServer);
}
*/
private void InitializeComponent()
{
textInput textServer = new textInput("Server" , "jhjhggj");
textServer.Location = new Point(0 , 0);
this.Controls.Add(textServer);
// nu mij setVal gebruiken, dit gaat prima
textServer.setVal("een waarde door setVal");
}
}
class main
{
public static void Main(string[] args)
{
TestForm tf = new TestForm();
// nu mij setVal gebruiken, dit gaat fout
tf.textServer.setVal("En dit werkt niet");
// ook rechtstreeks aanroepen wordt niet weergegeven
tf.textServer.TIVal.Text = "hjhjgfjgf";
Application.Run(tf);
// nu getval.. en help, het is de waarde van de vorige setval..
// dit moet dus de waarde van die textbox wezen...
// doe ik bovestaande setVal niet, dan is dit leeg.. niet goed dus
Console.WriteLine(tf.textServer.TIVal.Text);
}
} |
De vraag,
hoe krijg ik textInput.setVal() , textInput.getVal() en textInput.reset() werkend als ik ze in de main aanroep.