如何在VB.NET 14中为numericupdown控件指定备用规则? [英] How do I specify alternate rules for numericupdown control in VB.NET 14?

查看:71
本文介绍了如何在VB.NET 14中为numericupdown控件指定备用规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个需要几个NumericUpDown控件的项目。其中一些根据其他人的价值观而改变。例如,当nud1值增加时,nud2值也会增加。但是,如果nud2增加,nud1保持不变。我会添加代码,但我根本无法弄清楚如何做到这一点!有人可以帮帮我吗?



所以,我在页面上有8个NumericUpDown控件。 nud1和nud5连接,nud3和nud6和nud7连接,nud4和nud8连接。当这些NUD中的第一个增加或减少时,它们的对应物也会增加或减少。但是,如果第二个NUD增加/减少,第一个NUD不应该改变。



我需要知道如何将UpButton方法与DownButton方法分开。但是,我无法弄清楚如何利用它。帮助?



Kat



我的尝试:



我还没能尝试任何东西。每当我选择或输入单词UpButton或DownButton时,我会得到红色波浪线和一个错误,表明未声明UpButton。由于其保护级别,它可能无法访问。我试图用nudST.UpButton()来调用它...这就是我能想到的所有事情,除了给我那个小消息之外什么都不做。

I am working on a project that requires several NumericUpDown controls. Some of them change according to the values of others. For example, when nud1 value increases, nud2 value increases as well. But, if nud2 increases, nud1 stays the same. I would add code, but I cannot figure out how to do it at all! Can someone help me?

So, I have 8 NumericUpDown controls on the page. nud1 and nud5 are connected, nud3 and nud6 and nud7 are connected, and nud4 and nud8 are connected. When the first of these NUDs increases or decreases, their counterpart also increases or decreases. However, if the second NUD is increased/decreased, the first one should not change.

I need to know how to separate the UpButton method from the DownButton method. However, I cannot figure out how to utilize it. Help?

Kat

What I have tried:

I haven't been able to try anything. Every time I select or type the words "UpButton" or "DownButton", I get red squiggly lines and an error that states "UpButton is not declared. It may be inaccessible due to its protection level." I have tried to invoke it with "nudST.UpButton()"...that's about all I can think to do and it doesn't do anything except give me that little message.

推荐答案

继上面我的建议创建一个简单的应用程序。使用两个updown控件和一个文本框创建一个表单。确保名称与以下代码示例中使用的名称相匹配。将方法名称 numericUpDown_ValueChanged 添加到两个控件的ValueChanged事件和下面的代码到主窗体代码。

Further to my suggestion above to create a simple application. Create a form with two updown controls and a text box. Make sure the names match those used in the following code sample. Add the method name numericUpDown_ValueChanged to the ValueChanged event of both controls and the code below to your main form code.
private void numericUpDown_ValueChanged(object sender, EventArgs e)
{
    if (sender == numericUpDown1)
    {
        // if control 1 changes then copy its value to control 2
        numericUpDown2.Value = numericUpDown1.Value;
    }

    // write a message to the textbox showing both values
    StringBuilder sb = new StringBuilder();
    sb.Append("NUD1: ");
    sb.Append(numericUpDown1.Value.ToString());
    sb.Append(", NUD2: ");
    sb.Append(numericUpDown2.Value.ToString());
    textBox1.Text = sb.ToString();
}



根据需要使用代码和值。


Play around with the code and the values as necessary.


这篇关于如何在VB.NET 14中为numericupdown控件指定备用规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆