coltsith

Does it happen I have a form with one textbox on it and when I remove it at runtime, the form's OnDeactivate method is called.


Re: .NET Compact Framework Forms calls deactivate when last control on it is removed?

ChunSheng Tang - MSFT


Hi, coltsith

I cannot repro it. When i removed the last control from a form, the deactive event is not fired. What is your code







Re: .NET Compact Framework Forms calls deactivate when last control on it is removed?

coltsith

Code Snippet

TextBox tb;


public Form() {

tb = new TextBox();

Controls.add(tb);

}


protected override void OnDeactivate() {
}



public static void Remove(Form f) {

f.Invoke(new callBackDelegate(f.callBack));

}


private delegate void callBackDelegate;

private void callBack() {

Controls.remove(tb);

}

This isn't the exact code but should be basically what I'm doing.Thanks




Re: .NET Compact Framework Forms calls deactivate when last control on it is removed?

timg_msft

what version of the runtime are you using v1 (SP1, SP2, SP3) or v2 (SP1, SP2)

Please run \windows\cgacutil.exe and report what version(s) are installed on your device.






Re: .NET Compact Framework Forms calls deactivate when last control on it is removed?

coltsith

I'm using SP2 and compact framework 2.0.




Re: .NET Compact Framework Forms calls deactivate when last control on it is removed?

timg_msft

I too cannot reproduce the behavior you describe using V2.SP2 and the PPC 2003 emulator.

If you can construct a simple repro (your previous post indicated the code shown wasn't the actual code), I'll be happy to take a further look. Here is the code I used in attempting to repro. If I missed something that is important to your scenario, please let me know.

Code Snippet

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Threading;

namespace DeviceApplication38

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

ThreadPool.QueueUserWorkItem(new WaitCallback(this.Worker));

}

protected override void OnDeactivate(EventArgs e)

{

base.OnDeactivate(e); // set breakpoint here

}

private void Worker(object o)

{

Thread.Sleep(2000);

Remove(this);

}

public static void Remove(Form f)

{

f.Invoke(new callBackDelegate(((Form1)f).callBack));

}

private delegate void callBackDelegate();

private void callBack()

{

Controls.Remove(textBox1);

}

}

}