Events in customTextBox.

This commit is contained in:
Yuee Shiness 2023-09-21 17:03:20 +04:00
parent 5ec0cd07a7
commit 2fc9ddf69f
9 changed files with 96 additions and 165 deletions

View File

@ -34,20 +34,22 @@
// listBox
//
listBox.FormattingEnabled = true;
listBox.ItemHeight = 20;
listBox.Location = new Point(13, 12);
listBox.ItemHeight = 15;
listBox.Location = new Point(11, 9);
listBox.Margin = new Padding(3, 2, 3, 2);
listBox.Name = "listBox";
listBox.Size = new Size(150, 104);
listBox.Size = new Size(132, 79);
listBox.TabIndex = 0;
listBox.SelectedValueChanged +=
listBox.SelectedValueChanged += SelectedValue_Changed;
//
// Frame
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(listBox);
Margin = new Padding(3, 2, 3, 2);
Name = "Frame";
Size = new Size(189, 136);
Size = new Size(165, 103);
ResumeLayout(false);
}

View File

@ -3,21 +3,10 @@
public partial class Frame : UserControl
{
private event EventHandler? _valueChanged;
private string? SelectedValue = string.Empty;
public event EventHandler ValueChanged
{
add
{
_valueChanged += value;
}
remove
{
_valueChanged -= value;
}
}
public event EventHandler ValueChanged;
public Frame()
{
@ -42,6 +31,10 @@
{
get
{
if (listBox.SelectedItem is null)
{
return "";
}
return SelectedValue;
}
set
@ -54,7 +47,7 @@
{
var element = sender as ListBox;
Value = element.Text.ToString();
_valueChanged?.Invoke(this, e);
ValueChanged?.Invoke(this, e);
}
}
}

View File

@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CustomComponents.Exceptions
{
public class ContentException : Exception
{
public ContentException(bool state) : base(CustomMessage(state)){ }
private static string CustomMessage(bool state)
{
if(state)
{
return "TextBox is empty however null flag is checked.";
}
return "TextBox is empty. You better write something!";
}
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CustomComponents.Exceptions
{
public class NotIntegerException : Exception
{
public NotIntegerException() { }
public NotIntegerException(string message) : base(new string($"{message} is not an integer!")) { }
}
}

View File

@ -1,4 +1,5 @@
using System;
using CustomComponents.Exceptions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -13,6 +14,9 @@ namespace CustomComponents
public partial class frameTextBox : UserControl
{
private string? _text;
public event EventHandler taskHandler;
public frameTextBox()
{
InitializeComponent();
@ -32,22 +36,32 @@ namespace CustomComponents
private void CheckBoxStateChanged(object sender, EventArgs e)
{
if (ruleCheckBox.Checked)
try
{
textBox.Enabled = false;
if (!string.IsNullOrEmpty(_text))
if (ruleCheckBox.Checked)
{
MessageBox.Show("TextBox is not empty!");
textBox.Enabled = false;
if (!string.IsNullOrEmpty(_text))
{
throw new ContentException(true);
}
}
else
{
textBox.Enabled = true;
if (string.IsNullOrEmpty(_text))
{
throw new ContentException(false);
}
}
}
else
catch(ContentException ex)
{
textBox.Enabled = true;
if (string.IsNullOrEmpty(_text))
{
MessageBox.Show("TextBox is empty. You better write something!");
}
taskHandler += (sender, e) => MessageBox.Show(ex.Message);
}
taskHandler?.Invoke(this, e);
}
private void CheckTextBoxValueType(object sender, EventArgs args)

View File

@ -36,9 +36,10 @@
//
// fillButton
//
fillButton.Location = new Point(175, 18);
fillButton.Location = new Point(153, 14);
fillButton.Margin = new Padding(3, 2, 3, 2);
fillButton.Name = "fillButton";
fillButton.Size = new Size(94, 29);
fillButton.Size = new Size(82, 22);
fillButton.TabIndex = 1;
fillButton.Text = "FILL";
fillButton.UseVisualStyleBackColor = true;
@ -46,9 +47,10 @@
//
// clearButton
//
clearButton.Location = new Point(175, 75);
clearButton.Location = new Point(153, 56);
clearButton.Margin = new Padding(3, 2, 3, 2);
clearButton.Name = "clearButton";
clearButton.Size = new Size(94, 29);
clearButton.Size = new Size(82, 22);
clearButton.TabIndex = 2;
clearButton.Text = "CLEAR";
clearButton.UseVisualStyleBackColor = true;
@ -57,28 +59,31 @@
// listBox
//
listBox.Location = new Point(-3, 0);
listBox.Margin = new Padding(3, 2, 3, 2);
listBox.Name = "listBox";
listBox.Size = new Size(172, 137);
listBox.Size = new Size(150, 120);
listBox.TabIndex = 3;
listBox.Value = "";
//
// frameTextBox1
//
frameTextBox1.Location = new Point(312, 18);
frameTextBox1.Location = new Point(273, 14);
frameTextBox1.Margin = new Padding(3, 2, 3, 2);
frameTextBox1.Name = "frameTextBox1";
frameTextBox1.Size = new Size(291, 91);
frameTextBox1.Size = new Size(255, 68);
frameTextBox1.TabIndex = 4;
frameTextBox1.Value = null;
//
// TestFrame
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
ClientSize = new Size(700, 338);
Controls.Add(frameTextBox1);
Controls.Add(clearButton);
Controls.Add(fillButton);
Controls.Add(listBox);
Margin = new Padding(3, 2, 3, 2);
Name = "TestFrame";
Text = "Form1";
ResumeLayout(false);

View File

@ -2,11 +2,10 @@ namespace TestForms
{
public partial class TestFrame : Form
{
public TestFrame()
{
InitializeComponent();
listBox.ValueChanged += new EventHandler()
}
private void clearButton_Click(object sender, EventArgs e)
@ -17,10 +16,9 @@ namespace TestForms
private void fillButton_Click(object sender, EventArgs e)
{
listBox.PopulateList(new List<string> { "SILENT", "RIZZ", "BLSSDY", "YUEEJKE" });
}
}
}

View File

@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">