Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 给按钮上色_C# - Fatal编程技术网

C# 给按钮上色

C# 给按钮上色,c#,C#,我的代码创建具有特定颜色的多个按钮。当我点击一个按钮,我希望它改变为十六进制颜色,它工作良好问题是,当我单击另一个按钮时,我希望先前选择的按钮返回默认配色方案。 private void createButtons() { foreach (int axis_number in axis_sequence.number) { AxisSequence axis = new AxisSequence

我的代码创建具有特定颜色的多个按钮。当我点击一个按钮,我希望它改变为十六进制颜色,它工作良好问题是,当我单击另一个按钮时,我希望先前选择的按钮返回默认配色方案。

 private void createButtons()
        {

            foreach (int axis_number in axis_sequence.number)
            {
                AxisSequence axis = new AxisSequence (axis_number); 
                axis.MouseLeftButtonDown += new MouseButtonEventHandler (axis_MouseLeftButtonDown);
                axis_sequence.Children.Add (axis);                           
            }
        }


void axis_MouseLeftButtonDown (object sender, MouseButtonEventArgs e)
    {

        var converter = new System.Windows.Media.BrushConverter();
        var brush_amob_gray = (System.Windows.Media.Brush)converter.ConvertFromString("#515151");
        var brush_amob_orange = (System.Windows.Media.Brush)converter.ConvertFromString("#FF8C00");

        ((AxisSequence)sender).change_canvas = brush_amob_orange;
        ((AxisSequence)sender).change_text_color = System.Windows.Media.Brushes.Black;
//当我单击另一个按钮时,我想将所有其他按钮设置为默认颜色

轴顺序:

public partial class AxisSequence : UserControl
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="numero_eixo"></param>
    public AxisSequence (int numero_eixo)
    {
        try
        {
            InitializeComponent();
            Value.Content = numero_eixo.ToString();

        }
        catch (System.Exception ex)
        {
            System.Windows.MessageBox.Show(ex.ToString());
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public int get_numero_eixo ()
    {
        return Int32.Parse (Value.Content.ToString());
    }

    /// <summary>
    /// 
    /// </summary>
    public System.Windows.Media.Brush change_canvas { get { return canvas.Background; } set { canvas.Background = value; } }

    /// <summary>
    /// 
    /// </summary>
    public System.Windows.Media.Brush change_text_color { get { return Value.Foreground; } set { Value.Foreground = value; } }
}
公共部分类AxisSequence:UserControl { /// /// /// /// 公共轴序列(整数) { 尝试 { 初始化组件(); Value.Content=numero_eixo.ToString(); } catch(System.Exception-ex) { System.Windows.MessageBox.Show(例如ToString()); } } /// /// /// /// 公共整数获取数字eixo() { 返回Int32.Parse(Value.Content.ToString()); } /// /// /// public System.Windows.Media.Brush change_canvas{get{return canvas.Background;}set{canvas.Background=value;}} /// /// /// public System.Windows.Media.Brush change_text_color{get{return Value.Foreground;}set{Value.Foreground=Value;} }
如果当前单击按钮,则使用上次焦点null,将颜色设置为默认方案。然后保留当前按钮的实例,即currClickedButton=(AxisSequence)sender。此更改必须在axis_MouseLeftButtonDown()中完成