private void AddCustomLabelText(CustomLabelVM customLabel) { var label = new FormattedTextLabel(customLabel.FormatString, customLabel.Color, customLabel.FontSize, customLabel.FontFamily, customLabel.TextAlignment); var labelBindingSource = new BindingSource(components); var trackBindingSource = new BindingSource(components); label.DataBindings.Add(new Binding(nameof(label.Format), labelBindingSource, nameof(customLabel.FormatString), true, DataSourceUpdateMode.OnPropertyChanged)); label.DataBindings.Add(new Binding(nameof(label.DefaultColor), labelBindingSource, nameof(customLabel.Color), true, DataSourceUpdateMode.OnPropertyChanged)); label.DataBindings.Add(new Binding(nameof(label.FontSize), labelBindingSource, nameof(customLabel.FontSize), true, DataSourceUpdateMode.OnPropertyChanged)); label.DataBindings.Add(new Binding(nameof(label.FontFamily), labelBindingSource, nameof(customLabel.FontFamily), true, DataSourceUpdateMode.OnPropertyChanged)); label.DataBindings.Add(new Binding(nameof(label.Alignment), labelBindingSource, nameof(customLabel.TextAlignment), true, DataSourceUpdateMode.OnPropertyChanged)); label.DataBindings.Add(new Binding(nameof(label.Visible), labelBindingSource, nameof(customLabel.IsVisible), true, DataSourceUpdateMode.OnPropertyChanged)); label.DataBindings.Add(new Binding(nameof(label.Width), labelBindingSource, nameof(customLabel.Width), true, DataSourceUpdateMode.OnPropertyChanged)); label.DataBindings.Add(new Binding(nameof(label.Height), labelBindingSource, nameof(customLabel.Height), true, DataSourceUpdateMode.OnPropertyChanged)); label.DataBindings.Add(new Binding(nameof(label.Location), labelBindingSource, nameof(customLabel.Location), true, DataSourceUpdateMode.OnPropertyChanged)); label.DataBindings.Add(new Binding(nameof(label.ScrollSpeed), labelBindingSource, nameof(customLabel.ScrollSpeed), true, DataSourceUpdateMode.OnPropertyChanged)); label.DataBindings.Add(new Binding(nameof(label.AlbumName), trackBindingSource, nameof(_trackModel.AlbumName), true, DataSourceUpdateMode.OnPropertyChanged)); label.DataBindings.Add(new Binding(nameof(label.Artist), trackBindingSource, nameof(_trackModel.Artist), true, DataSourceUpdateMode.OnPropertyChanged)); label.DataBindings.Add(new Binding(nameof(label.SongName), trackBindingSource, nameof(_trackModel.TrackName), true, DataSourceUpdateMode.OnPropertyChanged)); label.DataBindings.Add(new Binding(nameof(label.SongLength), trackBindingSource, nameof(_trackModel.TrackLength), true, DataSourceUpdateMode.OnPropertyChanged)); label.DataBindings.Add(new Binding(nameof(label.SongProgress), trackBindingSource, nameof(_trackModel.TrackProgress), true, DataSourceUpdateMode.OnPropertyChanged)); labelBindingSource.DataSource = customLabel; trackBindingSource.DataSource = _trackModel; label.Tag = customLabel; label.Name = CustomLabelControlsKey; Controls.Add(label); }
/// <inheritdoc/> void ICustomLabelHost.AddCustomTextLabel(CustomLabelVM customLabel) { if (InvokeRequired) { BeginInvoke((Action)(() => AddCustomLabelText(customLabel))); } else { AddCustomLabelText(customLabel); } }
/// <inheritdoc/> void ICustomLabelHost.RemoveCustomTextLabel(CustomLabelVM customLabel) { if (InvokeRequired) { BeginInvoke((Action)(() => RemoveCustomTextLabel(customLabel))); } else { RemoveCustomTextLabel(customLabel); } }
private void LabelServiceOnRemoveCustomTextLabel(object sender, CustomLabelVM customLabel) { if (InvokeRequired) { BeginInvoke((Action)(() => RemoveCustomTextLabel(customLabel))); } else { RemoveCustomTextLabel(customLabel); } }
private void RemoveCustomTextLabel(CustomLabelVM customLabel) { var control = Controls.Find(CustomLabelControlsKey, true) .Cast <FormattedTextLabel>() .FirstOrDefault(l => l.Tag == customLabel); if (control == null) { Logger.Warn("Tried removing label but the control was not found"); return; } Controls.Remove(control); }