My goal is to create 2 Numeric Up Down controls for keeping score in Tennis. So I have to override the Numeric Up Down control class, BUT I'm not sure how to create events or reference the properties of these custom controls from other control's events.
I created the 2 custom controls by this technique (https://stackoverflow.com/a/5921599/10886205), which allowed me to jump from 0, 15, 30 to 40 and place text values in it after it exceeded 40.
However, the control doesn’t exist in the Designer Interface of Visual Studio, so (because I’m kind of an “amateur programmer”) I have no idea how to create an event, such as ValueUp, ValueDown, ValueChanged, OR how to change any of the control’s properties, such as Value or Text, from any other event except by use of “this” keyword in the override events. However, this doesn’t really help me to link the controls programmatically, so that when 1 player is in “Adv”, the other player is in “-“, or when 1 player evens up to “Deuce” then the other player is also in “Deuce.” (I was trying to use Tags and variables, but I think this is a dead-end.)
public partial class Form1 : Form
{
public class NumericUpDownEx : NumericUpDown
{
string tennisAdv = "none";
string whichNumUpDown = "unknown";
public void Form1() { }
public override void UpButton()
{
if (Value == 0) Value = 15;
else if (Value == 15) Value = 30;
else if (Value == 30) Value = 40;
else base.UpButton();
}
public override void DownButton()
{
if (Value == 40) Value = 30;
else if (Value == 30) Value = 15;
else if (Value == 15) Value = 0;
else base.DownButton();
}
protected override void UpdateEditText()
{
if (Value > 40 & Value % 2 == 0)
this.Text = "Deuce";
else if (Value > 40 & Value % 2 != 0)
this.Text = "Adv";
else this.Text = this.Value.ToString();
}
}
public Form1()
{
//create a custom UpDown for Tennis Points
//Tennis Away Points
NumericUpDown mynumTennisAwayScorePoints = new NumericUpDownEx
{
Location = new Point(249, 33),
Size = new Size(52, 20),
Minimum = 0,
Maximum = 1000
};
//Tennis Home POints
NumericUpDown mynumTennisHomeScorePoints = new NumericUpDownEx
{
Location = new Point(249, 32),
Size = new Size(52, 20),
Minimum = 0,
Maximum = 1000
};
//create all other standard componets for the form
InitializeComponent();
//place the two custom UpDowns
((System.ComponentModel.ISupportInitialize)(mynumTennisAwayScorePoints)).BeginInit();
((System.ComponentModel.ISupportInitialize)(mynumTennisHomeScorePoints)).BeginInit();
panel19.Controls.Add(mynumTennisAwayScorePoints);
mynumTennisAwayScorePoints.Tag = "away";
panel20.Controls.Add(mynumTennisHomeScorePoints);
mynumTennisHomeScorePoints.Tag = "home";
}
}
At this point, I have 2 custom controls that give values (0, 15, 30, 40, Adv, Deuce, Adv, Deuce, etc.) in that order, but I'm kind of stuck there.