Click here to Skip to main content
15,503,579 members
Home / Discussions / C#
   

C#

 
QuestionCreating a SELECT Query Based on Textbox Data Pin
John L. DeVito19-Jul-15 5:59
professionalJohn L. DeVito19-Jul-15 5:59 
GeneralRe: Creating a SELECT Query Based on Textbox Data Pin
PIEBALDconsult19-Jul-15 6:06
professionalPIEBALDconsult19-Jul-15 6:06 
AnswerRe: Creating a SELECT Query Based on Textbox Data Pin
Wendelius19-Jul-15 6:25
mveWendelius19-Jul-15 6:25 
AnswerRe: Creating a SELECT Query Based on Textbox Data Pin
Dave Kreskowiak19-Jul-15 7:29
mveDave Kreskowiak19-Jul-15 7:29 
AnswerRe: Creating a SELECT Query Based on Textbox Data Pin
F-ES Sitecore19-Jul-15 23:29
professionalF-ES Sitecore19-Jul-15 23:29 
AnswerRe: Creating a SELECT Query Based on Textbox Data Pin
Richard Deeming20-Jul-15 7:58
mveRichard Deeming20-Jul-15 7:58 
Questionan unexpected absence of fail ... using anonymous actions in a WinForm EventHandler Pin
BillWoodruff19-Jul-15 5:05
mveBillWoodruff19-Jul-15 5:05 
AnswerRe: an unexpected absence of fail ... using anonymous actions in a WinForm EventHandler Pin
Alan N19-Jul-15 10:44
Alan N19-Jul-15 10:44 
Everyone knows that anonymous delegates cannot be removed so obviously there are places where they should not be used!

But what if?
What if the add and remove mechanisms are set up at the same time? Sure the delegate code is anonymous but, as you say in your message, a reference can be kept.

I have lambdaphobia so here is the great idea in old school code.
C#
public class Form1 : Form {

  protected override void OnLoad(EventArgs e) {
    base.OnLoad(e);
    this.Text = "One";

    Form f = new Form();
    f.Text = "Two";
    f.Show();
    ISeeAWitch(this, f);
  }

  private void ISeeAWitch(Form bControl, Form dControl) {
    // I don't know who you are but I can point a finger at you
    EventHandler locationChanged = new EventHandler(delegate(Object sender, EventArgs e) {
      dControl.Left = bControl.Right;
      dControl.Top = bControl.Top;
    });

    bControl.LocationChanged += locationChanged;
    
    // I don't know who you are either but I can see that you are pointing at that other guy too
    dControl.FormClosed += new FormClosedEventHandler(delegate(Object sender, FormClosedEventArgs e) {
      if (bControl != null) {
        bControl.LocationChanged -= locationChanged;
        MessageBox.Show("I'm off");
      }
    });
    
    locationChanged(null, null);
  }
}

Alan.
GeneralRe: an unexpected absence of fail ... using anonymous actions in a WinForm EventHandler Pin
BillWoodruff19-Jul-15 12:46
mveBillWoodruff19-Jul-15 12:46 
GeneralRe: an unexpected absence of fail ... using anonymous actions in a WinForm EventHandler Pin
Member 1113646119-Jul-15 11:01
Member 1113646119-Jul-15 11:01 
GeneralRe: an unexpected absence of fail ... using anonymous actions in a WinForm EventHandler Pin
BillWoodruff19-Jul-15 12:49
mveBillWoodruff19-Jul-15 12:49 
AnswerRe: an unexpected absence of fail ... using anonymous actions in a WinForm EventHandler Pin
Richard Deeming20-Jul-15 7:43
mveRichard Deeming20-Jul-15 7:43 
QuestionApplication is Crashing Pin
Jassim Rahma19-Jul-15 2:10
Jassim Rahma19-Jul-15 2:10 
AnswerRe: Application is Crashing Pin
OriginalGriff19-Jul-15 2:36
mveOriginalGriff19-Jul-15 2:36 
AnswerRe: Application is Crashing Pin
Dave Kreskowiak19-Jul-15 4:54
mveDave Kreskowiak19-Jul-15 4:54 
QuestionHow to get google place predictions with latitude, longitude and address based on Textbox entry in c# Pin
sr15918-Jul-15 20:05
sr15918-Jul-15 20:05 
AnswerRe: How to get google place predictions with latitude, longitude and address based on Textbox entry in c# Pin
OriginalGriff18-Jul-15 21:17
mveOriginalGriff18-Jul-15 21:17 
QuestionCar tracker Pin
lolinga218-Jul-15 9:58
lolinga218-Jul-15 9:58 
AnswerRe: Car tracker Pin
Dave Kreskowiak18-Jul-15 10:36
mveDave Kreskowiak18-Jul-15 10:36 
GeneralRe: Car tracker Pin
lolinga218-Jul-15 10:42
lolinga218-Jul-15 10:42 
GeneralRe: Car tracker Pin
Mycroft Holmes18-Jul-15 15:35
professionalMycroft Holmes18-Jul-15 15:35 
QuestionError Converting String to Int Pin
Broodje Games18-Jul-15 3:26
Broodje Games18-Jul-15 3:26 
AnswerRe: Error Converting String to Int Pin
OriginalGriff18-Jul-15 3:31
mveOriginalGriff18-Jul-15 3:31 
AnswerRe: Error Converting String to Int Pin
miki-bgd18-Jul-15 6:12
miki-bgd18-Jul-15 6:12 
QuestionHide a Panel on MDI Container Pin
Jassim Rahma17-Jul-15 12:13
Jassim Rahma17-Jul-15 12:13 

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.