using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using log4net; using IntelligentControlForsx.Service; namespace IntelligentControlForsx.MyControls { public partial class StationRadio : UserControl { private ILog logger = LogManager.GetLogger("AppInfoLog"); public StationRadio() { InitializeComponent(); } private string stationId = ""; public string StationId { get { return stationId; } set { if (stationId.Equals(value) == false) { stationId = value; UpdateUI(); StationIdChanged(this, null); } } } public event EventHandler StationIdChanged; private void StationRadio_Load(object sender, EventArgs e) { try { var lstStation = CacheService.Instance.GetFDCList(); foreach(var st in lstStation) { Button btnSt = new ImageButton(); this.Controls.Add(btnSt); //this.SuspendLayout(); btnSt.Text = st.NAME; btnSt.Tag = st.ID; btnSt.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.btn_station1; btnSt.Dock = System.Windows.Forms.DockStyle.Left; btnSt.Click += new System.EventHandler(this.btnStation_Click); //this.ResumeLayout(false); } StationId = lstStation.Last().ID; } catch(Exception ex) { logger.Error(ex); } } private void btnStation_Click(object sender, EventArgs e) { ImageButton btn = sender as ImageButton; if (btn != null) StationId = btn.Tag.ToString(); //MessageBox.Show(btn.Tag.ToString()); } private void UpdateUI() { foreach(var control in this.Controls) { ImageButton btn = control as ImageButton; if (btn != null) { if (StationId.Equals(btn.Tag.ToString())) { btn.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.btn_station2; } else { btn.BackgroundImage = global::IntelligentControlForsx.Properties.Resources.btn_station1; } } } } } }