Why are events such as Resize, Click, DoublClick, etc. are not raised for a Windows Form?

E

Emre Sevinc

Hello,

I have a strange situation. I create a very simple Windows Forms
application and place the code below however even though I place
breakpoints in various event handling points VS.NET 2005 only enters
the breakpoint for the button but not for the form. Am I missing
something? Why don't the events for my form Form1 have any effect?

Form1.cs:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GeciciResize
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
}

private void Form1_Resize(object sender, System.EventArgs e)
{
// I place a breakpoint in the line below BUT it doesn't
enter here when I resize the form.
if (FormWindowState.Minimized == WindowState)
Form1.ActiveForm.Hide();
}


private void Form1_Click(object sender, System.EventArgs e)
{
// I place a breakpoint in the line below BUT it doesn't
enter here when I click on the form.
if (FormWindowState.Minimized == WindowState)
Form1.ActiveForm.Hide();
}

private void Form1_DoubleClick(object sender, System.EventArgs
e)
{
// I place a breakpoint in the line below BUT it doesn't
enter here when I double click on the form.
if (FormWindowState.Minimized == WindowState)
Form1.ActiveForm.Hide();
}

private void button1_Click(object sender, EventArgs e)
{
// I place a breakpoint in the line below AND it enters
here when I click on the button.
Form1.ActiveForm.Hide();
}
}
}

Regards,
Emre Sevinc
 
M

Mahmoud Al-Qudsi

Emre said:
Hello,

I have a strange situation. I create a very simple Windows Forms
application and place the code below however even though I place
breakpoints in various event handling points VS.NET 2005 only enters
the breakpoint for the button but not for the form. Am I missing
something? Why don't the events for my form Form1 have any effect?

Form1.cs:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GeciciResize
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
}

private void Form1_Resize(object sender, System.EventArgs e)
{
// I place a breakpoint in the line below BUT it doesn't
enter here when I resize the form.
if (FormWindowState.Minimized == WindowState)
Form1.ActiveForm.Hide();
}


private void Form1_Click(object sender, System.EventArgs e)
{
// I place a breakpoint in the line below BUT it doesn't
enter here when I click on the form.
if (FormWindowState.Minimized == WindowState)
Form1.ActiveForm.Hide();
}

private void Form1_DoubleClick(object sender, System.EventArgs
e)
{
// I place a breakpoint in the line below BUT it doesn't
enter here when I double click on the form.
if (FormWindowState.Minimized == WindowState)
Form1.ActiveForm.Hide();
}

private void button1_Click(object sender, EventArgs e)
{
// I place a breakpoint in the line below AND it enters
here when I click on the button.
Form1.ActiveForm.Hide();
}
}
}

Regards,
Emre Sevinc

Let me guess, this used to work with Visual Basic? ;)

You have to add event handlers:

In the main:
Form1.ActiveForm.Resize += new EventHandler(Form1_Resize);

_Then_ you can put code in Form1_Resize which will run when the form
is resized.
 
G

Guest

in case the event registration write under designer code, then maybe you
should clean the solution turn the solution to debug and rebuild the
solution, it will work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top