我想在 NumericUpDown 控制元件上交換向上和向下箭頭(僅功能,而不是實際箭頭)。例如,單擊向上箭頭時,值應減小,類似地,單擊向下箭頭時,值應增大。
我試圖從NumericUpDown類繼承并覆寫UpButton()和DownButton()。我認為只需在這兩種方法之間交換代碼就可以了。但是在將DownButton()代碼粘貼到覆寫的UpButton()中后,
public class MyCustomNumericUpDown : NumericUpDown
{
public override void UpButton()
{
SetNextAcceleration();
if (base.UserEdit)
{
ParseEditText();
}
decimal num = currentValue;
try
{
num -= Increment;
if (num < minimum)
{
num = minimum;
if (Spinning)
{
StopAcceleration();
}
}
}
catch (OverflowException)
{
num = minimum;
}
Value = num;
}
}
上面的程式拋出以下錯誤。
The name 'SetNextAcceleration' does not exist in the current context
The name 'currentValue' does not exist in the current context
The name 'minimum' does not exist in the current context
The name 'Spinning' does not exist in the current context
The name 'StopAcceleration' does not exist in the current context
The name 'minimum' does not exist in the current context
我看到所有這些方法和變數在基類中都設定為私有。這可能會引發這些“不存在”的錯誤。
有人知道怎么做嗎?我只想交換箭頭按鈕的功能。例如,單擊向上箭頭時,值應減小,類似地,單擊向下箭頭時,值應增大。
uj5u.com熱心網友回復:
您可以從NumericUpDown和 overrideUpButton和DownButton這樣的方法派生(通過呼叫 base.TheOtherMethod 來交換功能):
public class CrazyNumericUpDown : NumericUpDown
{
public override void UpButton()
{
base.DownButton();
}
public override void DownButton()
{
base.UpButton();
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/420881.html
標籤:
上一篇:前端容器如何使用負載均衡器與同一EC2實體上的API容器通信
下一篇:服務總線訂購快速連續訊息
