Merge pull request 'переписал обработку при изменении itemcheck' (#5) from fix_lab2_again into lab2

Reviewed-on: #5
This commit is contained in:
Никита Потапов 2024-12-11 15:18:47 +04:00
commit 5c2bd79687
5 changed files with 27 additions and 24 deletions

View File

@ -7,7 +7,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>ns.potapov</Authors>
<VersionPrefix>1.0.6</VersionPrefix>
<VersionPrefix>1.0.7</VersionPrefix>
<Version>$(VersionPrefix)</Version>
</PropertyGroup>

View File

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

View File

@ -1,4 +1,5 @@
using Components.Exceptions;
using System.Windows.Forms;
namespace Components
{
@ -44,7 +45,7 @@ namespace Components
}
}
}
public List<string> CheckedItems
public List<string> CheckedItemss
{
get
{
@ -83,21 +84,25 @@ namespace Components
checkedListBox.Items.Clear();
}
private void checkedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
{
this.BeginInvoke((MethodInvoker)(
() =>
{
if (checkedListBox.CheckedItems.Count > MaxCheckedItemsCount)
{
if (typeOfMaxChecked == Types.Exception)
{
MessageBox.Show("Превышено максимальное число выбранных элементов");
checkedListBox.SetItemChecked(e.Index, false);
throw new MaxCheckedItemsCountExceedException("Превышено максимальное число выбранных элементов");
}
else if (typeOfMaxChecked == Types.DeleteFirst)
{
checkedListBox.SetItemChecked(0, false);
checkedListBox.SetItemCheckState(checkedListBox.Items.IndexOf(CheckedItem), CheckState.Unchecked);
}
}
_onCheckedItemChangedEvent?.Invoke(sender, e);
}));
}
}
}

View File

@ -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)

View File

@ -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());
}
}
}