Click here to Skip to main content
15,889,876 members
Home / Discussions / C#
   

C#

 
QuestionUITypeEditor problem - Get calling assembly Pin
Chris_McGrath11-Sep-08 15:24
Chris_McGrath11-Sep-08 15:24 
QuestionWindow.open() not working in IE7 & IE8 Pin
hivshi11-Sep-08 14:42
hivshi11-Sep-08 14:42 
AnswerRe: Window.open() not working in IE7 & IE8 Pin
Christian Graus11-Sep-08 15:21
protectorChristian Graus11-Sep-08 15:21 
AnswerRe: Window.open() not working in IE7 & IE8 Pin
Guffa12-Sep-08 0:27
Guffa12-Sep-08 0:27 
Questiondatagridview - edit columns size Pin
nelsonpaixao11-Sep-08 14:27
nelsonpaixao11-Sep-08 14:27 
AnswerRe: datagridview - edit columns size Pin
Eslam Afifi11-Sep-08 14:39
Eslam Afifi11-Sep-08 14:39 
AnswerRe: datagridview - edit columns size Pin
Mycroft Holmes11-Sep-08 15:10
professionalMycroft Holmes11-Sep-08 15:10 
QuestionFunny Control Behavior [modified] Pin
Member 204889411-Sep-08 14:00
Member 204889411-Sep-08 14:00 
Create a C# Windows Application. Replace the non-designer class code in the Form with mine below.

The code simply creates 10 Panels on the form, each with one button on it. I assign each button's parent panel to the button's "Tag" property. I assign one common click event handler to all the buttons. In the click event handler, I simply cast the button's "Tag" to a Panel, then do a Form.Controls.Remove() to remove the Panel from the Form's "Controls" collection.

I also create a "debug" window so that I can see when the button click event handler fires.

Run the application and start hitting the spacebar. Exactly as you would expect, as you "click" each button by hitting the spacebar, the respective panel is removed. But keep hitting the spacebar after no more panels are visible. The click event KEEPS ON FIRING. I can understand that the panel can still be alive (and not have been garbage collected) and still have the button in its' "Controls" collection. But how does the spacebar keypress get from the form (which is in focus and has Controls.Count = 0) to the panel (and on to the button) that is no longer in its "Controls" collection???

public partial class Form1 : Form
{
    private Form debugForm;
    private TextBox debugTextBox;

    public Form1()
    {
        InitializeComponent();
    }

    void b_Click(object sender, EventArgs e)
    {
        // Remove panel from form.controls with button on panel is clicked
        Button b = (Button)sender;
        Panel p = (Panel)(b.Tag);
        this.Controls.Remove(p);
        debugTextBox.Text += "Click event fired for " + b.Name + " : this.Controls.Count = " +
            this.Controls.Count.ToString() + "\r\n";
    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        try
        {
            debugForm.Close();
        }
        catch { }
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        for (int i = 0; i < 10; i++)
        {
            Panel p = new Panel();
            p.Left = 0;
            p.Top = i * 35;
            p.Width = 300;
            p.Height = 30;
            Button b = new Button();
            b.Left = 0;
            b.Top = 0;
            b.Width = 300;
            b.Height = 30;
            b.Name = b.Text = "Button" + i.ToString();
            b.Click += new EventHandler(b_Click);
            b.Tag = p;
            p.Controls.Add(b);
            this.Controls.Add(p);
        }

        Rectangle rScreen = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
        this.Left = 0;
        this.Width = rScreen.Width / 2;
        this.Top = 0;
        this.Height = rScreen.Height;

        debugForm = new Form();
        debugForm.StartPosition = FormStartPosition.Manual;
        debugForm.Left = this.Right + 1;
        debugForm.Width = this.Width;
        debugForm.Top = this.Top;
        debugForm.Height = this.Height;
        debugTextBox = new TextBox();
        debugTextBox.Multiline = true;
        debugTextBox.Dock = DockStyle.Fill;
        debugTextBox.ScrollBars = ScrollBars.Both;
        debugForm.Controls.Add(debugTextBox);

        debugForm.Show();
    }
}

QuestionToolstrip Items Disappeared Pin
kruegersck11-Sep-08 13:05
kruegersck11-Sep-08 13:05 
Questionstruct X class Pin
Dirso11-Sep-08 12:57
Dirso11-Sep-08 12:57 
AnswerRe: struct X class Pin
Judah Gabriel Himango11-Sep-08 13:00
sponsorJudah Gabriel Himango11-Sep-08 13:00 
AnswerRe: struct X class Pin
Christian Graus11-Sep-08 15:15
protectorChristian Graus11-Sep-08 15:15 
GeneralRe: struct X class Pin
Dirso11-Sep-08 15:37
Dirso11-Sep-08 15:37 
GeneralRe: struct X class Pin
Judah Gabriel Himango11-Sep-08 17:27
sponsorJudah Gabriel Himango11-Sep-08 17:27 
GeneralRe: struct X class Pin
Dirso12-Sep-08 0:11
Dirso12-Sep-08 0:11 
AnswerRe: struct X class Pin
Guffa11-Sep-08 20:52
Guffa11-Sep-08 20:52 
GeneralRe: struct X class Pin
Dirso12-Sep-08 0:13
Dirso12-Sep-08 0:13 
GeneralRe: struct X class Pin
Guffa12-Sep-08 2:32
Guffa12-Sep-08 2:32 
Questionwhich database is installed on every computer Pin
Deresen11-Sep-08 12:03
Deresen11-Sep-08 12:03 
AnswerRe: which database is installed on every computer Pin
Pete O'Hanlon11-Sep-08 12:25
mvePete O'Hanlon11-Sep-08 12:25 
AnswerRe: which database is installed on every computer Pin
Eslam Afifi11-Sep-08 12:35
Eslam Afifi11-Sep-08 12:35 
GeneralRe: which database is installed on every computer Pin
Member 204889411-Sep-08 14:05
Member 204889411-Sep-08 14:05 
AnswerRe: which database is installed on every computer Pin
Paul Conrad11-Sep-08 12:49
professionalPaul Conrad11-Sep-08 12:49 
AnswerRe: which database is installed on every computer Pin
Giorgi Dalakishvili12-Sep-08 0:49
mentorGiorgi Dalakishvili12-Sep-08 0:49 
QuestionOpen Another Application from a Windows Form Pin
polishprogrammer11-Sep-08 11:30
polishprogrammer11-Sep-08 11:30 

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.