我有两个做同样事情的轨迹条,除了一个用于左侧执行器,一个用于右侧执行器。我想在我的 GUI 中添加同步轨迹栏的选项,以便用户可以选择以相同的方式控制两个执行器。现在,问题是轨迹栏会在我第一次尝试时同步,但随后两个手柄都冻结了。这是我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace GUI1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.slider1.Minimum = 0;
this.slider1.Maximum = 9;
this.slider2.Minimum = 0;
this.slider2.Maximum = 9;
}
//ends public form1
private void Form1_Load(object sender, EventArgs e)
{
}
//starts first slider
private void slider1_Scroll(object sender, EventArgs e)
{
System.Windows.Forms.TrackBar slider1;
slider1 = (System.Windows.Forms.TrackBar)sender;
textBox1.Text = "" + slider1.Value.ToString();
if (syncOption.Checked == true)
{
slider1.Value = Convert.ToInt32(slider2.Value);
textBox1.Text = slider1.Value.ToString();
}
}//ends first slider
//starts second slider
private void slider2_Scroll(object sender, EventArgs e)
{
System.Windows.Forms.TrackBar slider2;
slider2 = (System.Windows.Forms.TrackBar)sender;
textBox2.Text = "" + slider2.Value.ToString();
if (syncOption.Checked == true)
{
slider2.Value = Convert.ToInt32(slider1.Value);
textBox2.Text = slider2.Value.ToString();
}
}//ends second slider
}
}
我感谢您的帮助!