C#彩色按钮

时间:2017-04-18 08:47:13

标签: c#

我的代码创建了具有特定颜色的多个按钮。当我单击一个按钮时,我希望它改为HEX颜色并且效果很好。 问题是,当我点击另一个按钮时,我希望之前选择的按钮返回默认颜色方案。

 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;

//当我点击另一个按钮时,我希望所有其他按钮都是默认颜色。

AXIS SEQUENCE:

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; } }
}

0 个答案:

没有答案