Tôi đang gặp sự cố vòng lặp vô hạn.C# set UserControl.Value mà không cần gọi sự kiện ValueChanged
Tôi có hai điều khiển lên/xuống số (tham số nhập Chiều cao và Chiều rộng). Khi người dùng thay đổi giá trị của một trong các điều khiển, tôi cần phải quy mô khác để giữ một hằng số tỷ lệ chiều cao đến chiều rộng.
Có cách nào để đặt giá trị của điều khiển mà không cần gọi sự kiện ValueChanged hay không. Tôi chỉ muốn sự kiện ValueChanged thực hiện khi người dùng thay đổi giá trị.
private void FloorLength_ValueChanged(object sender, EventArgs e)
{
if (this.mCurrentDocument.System.SuperTrakSystem.FloorBitmap != null)
{
FloorWidth.Value = FloorLength.Value *
((decimal)this.mCurrentDocument.System.SuperTrakSystem.FloorBitmap.Height/
(decimal)this.mCurrentDocument.System.SuperTrakSystem.FloorBitmap.Width);
}
}
private void FloorWidth_ValueChanged(object sender, EventArgs e)
{
if (this.mCurrentDocument.System.SuperTrakSystem.FloorBitmap != null)
{
FloorLength.Value = FloorWidth.Value *
((decimal)this.mCurrentDocument.System.SuperTrakSystem.FloorBitmap.Width/
(decimal)this.mCurrentDocument.System.SuperTrakSystem.FloorBitmap.Height);
}
}
tôi thích giải pháp này – David