Click here to Skip to main content
15,896,063 members
Home / Discussions / C#
   

C#

 
GeneralRe: extending a special case of a generic type Pin
harold aptroot5-Jan-18 22:38
harold aptroot5-Jan-18 22:38 
GeneralRe: extending a special case of a generic type Pin
Alexander Kindel5-Jan-18 23:09
Alexander Kindel5-Jan-18 23:09 
GeneralRe: extending a special case of a generic type Pin
harold aptroot5-Jan-18 23:34
harold aptroot5-Jan-18 23:34 
GeneralRe: extending a special case of a generic type Pin
Alexander Kindel5-Jan-18 23:37
Alexander Kindel5-Jan-18 23:37 
GeneralRe: extending a special case of a generic type Pin
Alexander Kindel6-Jan-18 2:39
Alexander Kindel6-Jan-18 2:39 
AnswerRe: extending a special case of a generic type Pin
jschell6-Jan-18 6:06
jschell6-Jan-18 6:06 
GeneralRe: extending a special case of a generic type Pin
Alexander Kindel6-Jan-18 8:28
Alexander Kindel6-Jan-18 8:28 
GeneralRe: extending a special case of a generic type Pin
jschell8-Jan-18 14:59
jschell8-Jan-18 14:59 
QuestionProblem with click event of a button on C # Pin
BEN SBAI5-Jan-18 13:41
BEN SBAI5-Jan-18 13:41 
AnswerRe: Problem with click event of a button on C # Pin
Jim Meadors5-Jan-18 16:06
Jim Meadors5-Jan-18 16:06 
AnswerRe: Problem with click event of a button on C # Pin
OriginalGriff5-Jan-18 20:04
mveOriginalGriff5-Jan-18 20:04 
AnswerRe: Problem with click event of a button on C # Pin
BillWoodruff5-Jan-18 21:33
professionalBillWoodruff5-Jan-18 21:33 
GeneralRe: Problem with click event of a button on C # Pin
OriginalGriff5-Jan-18 21:46
mveOriginalGriff5-Jan-18 21:46 
GeneralRe: Problem with click event of a button on C # Pin
BillWoodruff6-Jan-18 2:46
professionalBillWoodruff6-Jan-18 2:46 
QuestionDisabling events of objects stored in array Pin
Pogoodill5-Jan-18 2:32
Pogoodill5-Jan-18 2:32 
AnswerRe: Disabling events of objects stored in array Pin
OriginalGriff5-Jan-18 3:14
mveOriginalGriff5-Jan-18 3:14 
GeneralRe: Disabling events of objects stored in array Pin
Pogoodill5-Jan-18 3:55
Pogoodill5-Jan-18 3:55 
AnswerRe: Disabling events of objects stored in array Pin
OriginalGriff5-Jan-18 4:59
mveOriginalGriff5-Jan-18 4:59 
GeneralRe: Disabling events of objects stored in array Pin
Pogoodill5-Jan-18 6:13
Pogoodill5-Jan-18 6:13 
AnswerRe: Disabling events of objects stored in array Pin
BillWoodruff6-Jan-18 2:12
professionalBillWoodruff6-Jan-18 2:12 
OriginalGriff has given you the "grand tour" of EventHandlers here; I hope I can add another perspective:

1. the "head 'em off at the pass" stratagem: if you don;t want the TextBoxes to raise the Event, consider setting their 'Enabled property to 'false, or their locked Property to 'true.

or ... if you want the user to enter edit text, but, not raise the event:

2. the sub-class stratagem: you inject an action into the instances of the sub-classed TextBox; whether that action is executed is controlled by a boolean flag
using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace YourNameSpace
{
    // built on a WinForm Component
    public partial class TextBoxEXEvents : TextBox
    {
        public TextBoxEXEvents()
        {
            InitializeComponent();
        }

        // the executable code method to be injected
        public Action<string, string> TextChangedAction { set; get; }

        // the boolean flag for execution control
        public bool IsTextChangedEnabled = true;

        public TextBoxEXEvents(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        private void TextBoxEXEvents_TextChanged(object sender, EventArgs e)
        {
            if (IsTextChangedEnabled && TextChangedAction != null) TextChangedAction(this.Text, this.Name);
        }
    }
}
Here's an example of how this can be used:
// in Form scope
private List<TextBoxEXEvents> TBxExInUse;

// Action to be injected
private void TextChangedAction(string text, string name = "")
{
    Console.WriteLine($"text: {text} in: {name}");
}

// in Form 'Load event
TBxExInUse = this.Controls.OfType<TextBoxEXEvents>().ToList();

foreach (var tbxex in TBxExInUse)
{
    tbxex.TextChangedAction = TextChangedAction;
}

// to turn-off/on TextChanged execution in sub-classed TectBoxes:

foreach (var tbxex in TBxExInUse)
{
    tbxex.IsTextChangedEnabled = YourBooleanValue;
}

«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12

AnswerRe: Disabling events of objects stored in array Pin
Gerry Schmitz6-Jan-18 6:55
mveGerry Schmitz6-Jan-18 6:55 
QuestionGet current point in time in recurring time interval. Pin
Member 136084655-Jan-18 2:10
Member 136084655-Jan-18 2:10 
AnswerRe: Get current point in time in recurring time interval. Pin
Ralf Meier5-Jan-18 2:38
mveRalf Meier5-Jan-18 2:38 
AnswerRe: Get current point in time in recurring time interval. Pin
Gerry Schmitz6-Jan-18 7:06
mveGerry Schmitz6-Jan-18 7:06 
QuestionHow to fetch master detail data using EF and LINQ Pin
Mou_kol5-Jan-18 0:15
Mou_kol5-Jan-18 0:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.