找到你要的答案

Q:Only 1 slider changes value

Q:只有1滑块改变值

I created a project with 3 sliders and 2 radiobuttons, the radiobuttons switch between which cursor I want to edit, Main, or the border of the cursor..

Each time the slider changes value it sets it into a variable and saves it, so 3 for main, 3 for border, when I change radio buttons, I want the slider to go to their respective values depending on which radio button is checked..

The code should work right but only R works.. if I remove the code that sets the R slider's value, then the blue slider works.. vice versa, has anyone got any idea why this is happening? here is the code.

sliderR.Value = borderrgb.R; sliderG.Value = borderrgb.G; SliderB.Value = borderrgb.B;

This Line of code should work...

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;
using Newtonsoft.Json;

namespace Terraria_Cursor_Editor_V2
{
   public partial class Form1 : Form
   {
      int R;
      int G;
      int B;
      int R1;
      int G1;
      int B1;
      Color mainrgb;
      Color borderrgb;
      bool changed = false;

      public Form1()
      {
         InitializeComponent();
         dynamic json = JsonConvert.DeserializeObject<Data>(File.ReadAllText(
             System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) 
            + "/My Games/Terraria/config.json"));
         var value = json.MouseColorR;
         sliderR.Value = value;
         value = json.MouseColorG;
         sliderG.Value = value;
         value = json.MouseColorB;
         sliderG.Value = value;
         value = json.ThickMouseEdges;
         if (value == true)
         {
             nsOnOffBox1.Checked = true;
         }
         else
         {
             nsOnOffBox1.Checked = false;
         }
         UpdateRGB();

         R = sliderR.Value; G = sliderG.Value; B = SliderB.Value;
         mainrgb = Color.FromArgb(R, G, B);
         mpanel.BackColor = mainrgb;
    }

    public void mainRGB()
    {
        if (rbMain.Checked == true)
        { 
           R1 = R;
           G1 = G;
           B1 = B;
        }
        else
        {
           borderrgb = Color.FromArgb(R, G, B);
        }
        pnl();
    }

    public void pnl()
    {
        mpanel.BackColor = mainrgb;
        bpanel.BackColor = borderrgb;
        rbMain.MainColor = mainrgb;
        rbBorder.MainColor = borderrgb;
        rval.Value1 = sliderR.Value.ToString();
        gval.Value1 = sliderG.Value.ToString();
        bval.Value1 = SliderB.Value.ToString();
        cbLabel.val1Color = mainrgb;
        cbLabel.val2Color = borderrgb;
    }

    public void UpdateRGB()
    {
    }

    private void sliderG_Scroll(object sender)
    {
        G = sliderG.Value;
        mainRGB();
    }

    private void SliderB_Scroll(object sender)
    {
        B = SliderB.Value;
        mainRGB();
    }

    private void sliderR_Scroll(object sender)
    {
        R = sliderR.Value;
        mainRGB();
    }

    private void rbMain_CheckedChanged(object sender)
    {
        if (rbMain.Checked) 
        {
            sliderR.Value = R1; 
            sliderG.Value = G1; 
            SliderB.Value = B1;
        }
        else
        {
            sliderR.Value = borderrgb.R; 
            sliderG.Value = borderrgb.G; 
            SliderB.Value = borderrgb.B;
        }
    }

    private void rbBorder_CheckedChanged(object sender)
    {
    }
  }
}

我创建了一个项目,3个滑块和2个单选按钮,单选按钮开关之间的光标,我想编辑、主、或光标的边界

每次滑块改变值,它设置成一个变量,并保存它,所以3为主,3为边界,当我改变单选按钮,我想滑块到各自的值取决于哪个单选按钮检查..

代码应该工作,但只有R工作..如果我删除的代码,设置R滑块的值,然后蓝色滑块工作..反之亦然,有人知道为什么会发生这种情况吗?这里是代码。

sliderR.Value = borderrgb.R; sliderG.Value = borderrgb.G; SliderB.Value = borderrgb.B;

这行代码应该工作…

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;
using Newtonsoft.Json;

namespace Terraria_Cursor_Editor_V2
{
   public partial class Form1 : Form
   {
      int R;
      int G;
      int B;
      int R1;
      int G1;
      int B1;
      Color mainrgb;
      Color borderrgb;
      bool changed = false;

      public Form1()
      {
         InitializeComponent();
         dynamic json = JsonConvert.DeserializeObject<Data>(File.ReadAllText(
             System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) 
            + "/My Games/Terraria/config.json"));
         var value = json.MouseColorR;
         sliderR.Value = value;
         value = json.MouseColorG;
         sliderG.Value = value;
         value = json.MouseColorB;
         sliderG.Value = value;
         value = json.ThickMouseEdges;
         if (value == true)
         {
             nsOnOffBox1.Checked = true;
         }
         else
         {
             nsOnOffBox1.Checked = false;
         }
         UpdateRGB();

         R = sliderR.Value; G = sliderG.Value; B = SliderB.Value;
         mainrgb = Color.FromArgb(R, G, B);
         mpanel.BackColor = mainrgb;
    }

    public void mainRGB()
    {
        if (rbMain.Checked == true)
        { 
           R1 = R;
           G1 = G;
           B1 = B;
        }
        else
        {
           borderrgb = Color.FromArgb(R, G, B);
        }
        pnl();
    }

    public void pnl()
    {
        mpanel.BackColor = mainrgb;
        bpanel.BackColor = borderrgb;
        rbMain.MainColor = mainrgb;
        rbBorder.MainColor = borderrgb;
        rval.Value1 = sliderR.Value.ToString();
        gval.Value1 = sliderG.Value.ToString();
        bval.Value1 = SliderB.Value.ToString();
        cbLabel.val1Color = mainrgb;
        cbLabel.val2Color = borderrgb;
    }

    public void UpdateRGB()
    {
    }

    private void sliderG_Scroll(object sender)
    {
        G = sliderG.Value;
        mainRGB();
    }

    private void SliderB_Scroll(object sender)
    {
        B = SliderB.Value;
        mainRGB();
    }

    private void sliderR_Scroll(object sender)
    {
        R = sliderR.Value;
        mainRGB();
    }

    private void rbMain_CheckedChanged(object sender)
    {
        if (rbMain.Checked) 
        {
            sliderR.Value = R1; 
            sliderG.Value = G1; 
            SliderB.Value = B1;
        }
        else
        {
            sliderR.Value = borderrgb.R; 
            sliderG.Value = borderrgb.G; 
            SliderB.Value = borderrgb.B;
        }
    }

    private void rbBorder_CheckedChanged(object sender)
    {
    }
  }
}
c#  slider  rgb