Useful C# extensions for windows form applications
Installation Nuget Package Download
Package Manager:
Install-Package CSUtils.LinkExtension.LinkControlByPropertyName -Version 1.0.0.2
.Net CLI:
dotnet add package CSUtils.LinkExtension.LinkControlByPropertyName --version 1.0.0.2
private void LinkOneWay()
{
// when checkbox2 and checkbox3 change their properties checkbox1 is not updated.
checkbox1.LinkOneWay("Checked", checkbox2, checkbox3);
}
private void LinkBothWay()
{
// all checkboxes are linked together by their "Checked" property.
checkbox1.Link("Checked", checkbox2, checkbox3);
}
private void Unlink()
{
checkbox1.UnLink();
}
private Dictionary<string, object> namesWithColors = new Dictionary<string, object>()
{
{ "Red" , Color.MediumVioletRed },
{ "Yellow" , Color.Yellow },
{ "Green" , Color.LightGreen },
};
private void bt_shift_names_with_colors_Click(object sender, EventArgs e)
{
Button bt = sender as Button;
bt.Enumerate(namesWithColors, (s, o) => {
Color newColor = (Color)o;
bt.BackColor = newColor;
Console.WriteLine("new color is {0}", newColor.Name);
});
}
private void Form1_Load(object sender, EventArgs e)
{
// sample usage of MakeAll<T> extension to make all checkboxes checked: true on initialization
this.MakeAll<CheckBox>(cb => cb.Checked = true);
}
private void Form1_Load(object sender, EventArgs e)
{
// sample usage of GetAll<T> extension to select all radiobuttons which are defaulted by their tag
foreach (RadioButton rb in this.GetAll<RadioButton>().Where(r => r.Tag.ConvertWithDefault<int>() == 0))
{
rb.Checked = true;
}
}
After Downloading project, build 'BuilAll' project and use generated DLL file in your projects.
Oğuzhan Katlı – LinkedIn: ogzhnktl – [email protected]
Distributed under the MIT license. See LICENSE
for more information.
https://github.com/nixiz/csharp-utils
- Fork it (https://github.com/nixiz/csharp-utils/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request