Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's some code snippets for my homebrewed control:</p> <pre><code>public partial class DaysOfWeekPicker : UserControl { public event EventHandler ValueChanged; private DaysOfWeek myValue; [DefaultValue (0)] public DaysOfWeek Value { get { return myValue; } set { myValue = value; RefreshData (); } } public DaysOfWeekPicker () { InitializeComponent (); } private void DayOfWeekClick (object sender, EventArgs e) { if (Object.ReferenceEquals (sender, g_l_Sunday)) { this.Value = this.Value ^ DaysOfWeek.Sunday; } else if (Object.ReferenceEquals (sender, g_l_Monday)) { this.Value = this.Value ^ DaysOfWeek.Monday; } else if (Object.ReferenceEquals (sender, g_l_Tuesday)) { this.Value = this.Value ^ DaysOfWeek.Tuesday; } else if (Object.ReferenceEquals (sender, g_l_Wednesday)) { this.Value = this.Value ^ DaysOfWeek.Wednesday; } else if (Object.ReferenceEquals (sender, g_l_Thursday)) { this.Value = this.Value ^ DaysOfWeek.Thursday; } else if (Object.ReferenceEquals (sender, g_l_Friday)) { this.Value = this.Value ^ DaysOfWeek.Friday; } else if (Object.ReferenceEquals (sender, g_l_Saturday)) { this.Value = this.Value ^ DaysOfWeek.Saturday; } } private void RefreshData () { SetLabelDisplay (g_l_Sunday, (this.Value &amp; DaysOfWeek.Sunday) == DaysOfWeek.Sunday); SetLabelDisplay (g_l_Monday, (this.Value &amp; DaysOfWeek.Monday) == DaysOfWeek.Monday); SetLabelDisplay (g_l_Tuesday, (this.Value &amp; DaysOfWeek.Tuesday) == DaysOfWeek.Tuesday); SetLabelDisplay (g_l_Wednesday, (this.Value &amp; DaysOfWeek.Wednesday) == DaysOfWeek.Wednesday); SetLabelDisplay (g_l_Thursday, (this.Value &amp; DaysOfWeek.Thursday) == DaysOfWeek.Thursday); SetLabelDisplay (g_l_Friday, (this.Value &amp; DaysOfWeek.Friday) == DaysOfWeek.Friday); SetLabelDisplay (g_l_Saturday, (this.Value &amp; DaysOfWeek.Saturday) == DaysOfWeek.Saturday); if (this.ValueChanged != null) this.ValueChanged (this, EventArgs.Empty); } private void SetLabelDisplay (LinkLabel label, bool enabled) { if (enabled) { label.BackColor = Color.Black; label.ForeColor = Color.White; } else { label.BackColor = Color.White; label.ForeColor = Color.Black; } } } </code></pre> <p>There may be a better way to do the value comparisons, but this is just what I came up with very quickly.</p> <p>As far as the designer part of it goes, I won't put it in here because of its verbosity, but it's rather simple. Each day is represented by a LinkLabel with the click event set to DayOfWeekClick. Each LinkLabel is at (1,1) and is 2 pixels smaller in both dimensions from is parent Panel. Each parent Panel has a black ForeColor, giving a border effect. Each Panel is set to DockStyle.Left, and the overall control size is equivalent to panel.Width * 7, panel.Height.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload