diff --git a/WinFormSolution/Components/Components.csproj b/WinFormSolution/Components/Components.csproj index 6737136..0ef8996 100644 --- a/WinFormSolution/Components/Components.csproj +++ b/WinFormSolution/Components/Components.csproj @@ -7,7 +7,7 @@ enable True ns.potapov - 1.0.6 + 1.0.7 $(VersionPrefix) diff --git a/WinFormSolution/Components/UserControlCheckedList.Designer.cs b/WinFormSolution/Components/UserControlCheckedList.Designer.cs index 26c3d47..bda7b92 100644 --- a/WinFormSolution/Components/UserControlCheckedList.Designer.cs +++ b/WinFormSolution/Components/UserControlCheckedList.Designer.cs @@ -36,22 +36,20 @@ checkedListBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; checkedListBox.CheckOnClick = true; checkedListBox.FormattingEnabled = true; - checkedListBox.Location = new Point(9, 8); - checkedListBox.Margin = new Padding(3, 4, 3, 4); + checkedListBox.Location = new Point(8, 6); checkedListBox.Name = "checkedListBox"; - checkedListBox.Size = new Size(509, 400); + checkedListBox.Size = new Size(446, 292); checkedListBox.TabIndex = 0; checkedListBox.ItemCheck += checkedListBox_ItemCheck; // // UserControlCheckedList // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; BackColor = Color.Firebrick; Controls.Add(checkedListBox); - Margin = new Padding(3, 4, 3, 4); Name = "UserControlCheckedList"; - Size = new Size(527, 415); + Size = new Size(461, 311); ResumeLayout(false); } diff --git a/WinFormSolution/Components/UserControlCheckedList.cs b/WinFormSolution/Components/UserControlCheckedList.cs index fc1ba33..19c058a 100644 --- a/WinFormSolution/Components/UserControlCheckedList.cs +++ b/WinFormSolution/Components/UserControlCheckedList.cs @@ -1,4 +1,5 @@ using Components.Exceptions; +using System.Windows.Forms; namespace Components { @@ -44,15 +45,15 @@ namespace Components } } } - public List CheckedItems + public List CheckedItemss { get { List list = new List(); - foreach(var item in checkedListBox.CheckedItems ) + foreach (var item in checkedListBox.CheckedItems) { list.Add(item.ToString()); - } + } return list; } set @@ -84,20 +85,24 @@ namespace Components } private void checkedListBox_ItemCheck(object sender, ItemCheckEventArgs e) { - if (checkedListBox.CheckedItems.Count > MaxCheckedItemsCount) + this.BeginInvoke((MethodInvoker)( + () => { - if (typeOfMaxChecked == Types.Exception) + if (checkedListBox.CheckedItems.Count > MaxCheckedItemsCount) { - checkedListBox.SetItemChecked(e.Index, false); - throw new MaxCheckedItemsCountExceedException("Превышено максимальное число выбранных элементов"); + if (typeOfMaxChecked == Types.Exception) + { + MessageBox.Show("Превышено максимальное число выбранных элементов"); + checkedListBox.SetItemChecked(e.Index, false); + } + else if (typeOfMaxChecked == Types.DeleteFirst) + { + checkedListBox.SetItemCheckState(checkedListBox.Items.IndexOf(CheckedItem), CheckState.Unchecked); + } + } - else if (typeOfMaxChecked == Types.DeleteFirst) - { - checkedListBox.SetItemChecked(0, false); - } - - } - _onCheckedItemChangedEvent?.Invoke(sender, e); + _onCheckedItemChangedEvent?.Invoke(sender, e); + })); } } } diff --git a/WinFormSolution/WinFormsApp/FormVisual.cs b/WinFormSolution/WinFormsApp/FormVisual.cs index 85ec9f6..708c453 100644 --- a/WinFormSolution/WinFormsApp/FormVisual.cs +++ b/WinFormSolution/WinFormsApp/FormVisual.cs @@ -18,8 +18,8 @@ namespace WinFormsApp list.Add(""); list.Add("C#"); userControlCheckedList.SetCheckedListBoxValues(list); - - userControlCheckedList.CheckedItem = list[3]; + userControlCheckedList.MaxCheckedItemsCount = 3; + userControlCheckedList.ChangeTypeOfMaxChecked(Components.Types.DeleteFirst); } private void buttonClearList_Click(object sender, EventArgs e) diff --git a/WinFormSolution/WinFormsApp/Program.cs b/WinFormSolution/WinFormsApp/Program.cs index 6418cb6..3325059 100644 --- a/WinFormSolution/WinFormsApp/Program.cs +++ b/WinFormSolution/WinFormsApp/Program.cs @@ -11,7 +11,7 @@ namespace WinFormsApp // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormNoVisual()); + Application.Run(new FormVisual()); } } } \ No newline at end of file