如何从 C# 中的控制数组读取数据
我有以下轨迹栏控件,已添加到选项卡页“tab1”中:
TrackBar[] tbs = new TrackBar[nooftbsneeded];
// Add TrackBars
TrackBar tbx = new TrackBar();
tbx.Location = new Point(28, 150 + (i * 200));
tbx.Size = new Size(686, 45);
tbx.Minimum = 0;
tbx.Maximum = 16;
tbx.SmallChange = 1;
tbx.LargeChange = 2;
tbx.Value = 8;
// create events (using a lambda expression) for each trackbar to change values.
tbx.Scroll += (o, a) =>
{
// Update text values
if (tbx.Value == 0)
{
label3x.Text = "Extremely Better";
label4x.Text = "";
}
if (tbx.Value == 1)
{
label3x.Text = "Extremely Better";
label4x.Text = "";
}
if (tbx.Value == 2)
{
label3x.Text = "Very Strongly Better";
label4x.Text = "";
}
if (tbx.Value == 3)
{
label3x.Text = "Very Strongly Better";
label4x.Text = "";
}
if (tbx.Value == 4)
{
label3x.Text = "Strongly Better";
label4x.Text = "";
}
if (tbx.Value == 5)
{
label3x.Text = "Strongly Better";
label4x.Text = "";
}
if (tbx.Value == 6)
{
label3x.Text = "Moderately Better";
label4x.Text = "";
}
if (tbx.Value == 7)
{
label3x.Text = "Moderately Better";
label4x.Text = "";
}
if (tbx.Value == 8)
{
label3x.Text = "Equal";
label4x.Text = "Equal";
}
if (tbx.Value == 9)
{
label3x.Text = "";
label4x.Text = "Moderately Better";
}
if (tbx.Value == 10)
{
label3x.Text = "";
label4x.Text = "Moderately Better";
}
if (tbx.Value == 11)
{
label3x.Text = "";
label4x.Text = "Strongly Better";
}
if (tbx.Value == 12)
{
label3x.Text = "";
label4x.Text = "Strongly Better";
}
if (tbx.Value == 13)
{
label3x.Text = "";
label4x.Text = "Very Strongly Better";
}
if (tbx.Value == 14)
{
label3x.Text = "";
label4x.Text = "Very Strongly Better";
}
if (tbx.Value == 15)
{
label3x.Text = "";
label4x.Text = "Extremely Better";
}
if (tbx.Value == 16)
{
label3x.Text = "";
label4x.Text = "Extremely Better";
}
};
tbs[i] = tbx;
tab1.Controls.Add(tbs[i]);
现在如何获取轨迹栏的各个值?
我已经尝试了我能想到的所有调用组合。我只是不知道如何引用单独的轨迹栏控件。
I have the following trackbar controls which I have added to a tabpage 'tab1':
TrackBar[] tbs = new TrackBar[nooftbsneeded];
// Add TrackBars
TrackBar tbx = new TrackBar();
tbx.Location = new Point(28, 150 + (i * 200));
tbx.Size = new Size(686, 45);
tbx.Minimum = 0;
tbx.Maximum = 16;
tbx.SmallChange = 1;
tbx.LargeChange = 2;
tbx.Value = 8;
// create events (using a lambda expression) for each trackbar to change values.
tbx.Scroll += (o, a) =>
{
// Update text values
if (tbx.Value == 0)
{
label3x.Text = "Extremely Better";
label4x.Text = "";
}
if (tbx.Value == 1)
{
label3x.Text = "Extremely Better";
label4x.Text = "";
}
if (tbx.Value == 2)
{
label3x.Text = "Very Strongly Better";
label4x.Text = "";
}
if (tbx.Value == 3)
{
label3x.Text = "Very Strongly Better";
label4x.Text = "";
}
if (tbx.Value == 4)
{
label3x.Text = "Strongly Better";
label4x.Text = "";
}
if (tbx.Value == 5)
{
label3x.Text = "Strongly Better";
label4x.Text = "";
}
if (tbx.Value == 6)
{
label3x.Text = "Moderately Better";
label4x.Text = "";
}
if (tbx.Value == 7)
{
label3x.Text = "Moderately Better";
label4x.Text = "";
}
if (tbx.Value == 8)
{
label3x.Text = "Equal";
label4x.Text = "Equal";
}
if (tbx.Value == 9)
{
label3x.Text = "";
label4x.Text = "Moderately Better";
}
if (tbx.Value == 10)
{
label3x.Text = "";
label4x.Text = "Moderately Better";
}
if (tbx.Value == 11)
{
label3x.Text = "";
label4x.Text = "Strongly Better";
}
if (tbx.Value == 12)
{
label3x.Text = "";
label4x.Text = "Strongly Better";
}
if (tbx.Value == 13)
{
label3x.Text = "";
label4x.Text = "Very Strongly Better";
}
if (tbx.Value == 14)
{
label3x.Text = "";
label4x.Text = "Very Strongly Better";
}
if (tbx.Value == 15)
{
label3x.Text = "";
label4x.Text = "Extremely Better";
}
if (tbx.Value == 16)
{
label3x.Text = "";
label4x.Text = "Extremely Better";
}
};
tbs[i] = tbx;
tab1.Controls.Add(tbs[i]);
How do I now get the individual values of the trackbars?
I have tried every combination of call I can think of.. I just don't know how to reference the separate trackbar controls.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保这是在您的类级别声明的:
然后,在您的方法中,只需初始化它(无需重新声明):
此时,您稍后可以通过以下方式读取值:
Make sure that this is declared at your class level:
Then, in your method, just initialize it (without redeclaring it):
At that point, you can later read values via: