1

I have been working on a Windows Forms application based in c# and I am in need of some assistance.

as seen in sample code:

frmPopUp frmAdd = new frmPopUp();

frmAdd.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
frmAdd.Location = new System.Drawing.Point(450, 200);
frmAdd.showdialog();
this.Create();

and when I use this function in code and click anywhere outside the frmAdd boundry it blinks or flickers which is annoying and I dont want that. (But "Create" function does called after form is closed) this is my problem I dont want blinking and at same time function should also be called after the form closes.

After some search, I tried dll import solutions from the link mentioned below - in this case the problem I am facing is that the Create function should always be called after frmadd form is closed. But it gets called when the form is created. e.g.:

SetNativeEnabled(false);
frmPopUp frmAdd = new frmPopUp();

frmAdd.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
frmAdd.Location = new System.Drawing.Point(450, 200);
frmAdd.Closed += (s, a) =>
{
    SetNativeEnabled(true);
};
frmAdd.Show(this);

this.Create();

I am fairly new to making Windows Forms applications so there are still things I don't understand so be patient with me if I don't understand something at first.

These are the links that I've tried:

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Kapil
  • 13
  • 3
  • Is it really shown "modally"? What does `this.Create()` and `frmPopUp.showdialog()` do? Are you reshowing form or what? And as a side comment, consider to use common styling (*Pascal* for classes and methods, *Kamel* is mostly used for local variables, perhaps fields). – Sinatr Jun 07 '13 at 12:56
  • @Sinatr as far as i know yap its shown modally. "this.Create()" method resets few variables in form. well "frmAdd.showdialog()" opens a child form over parent form ref. by "this" keyword. No i am not reshowing my form i am opening a child form over parent form on button_click event. – Kapil Jun 07 '13 at 13:19
  • In the second part of code you are displaying modeless window, try to change `frmAdd.ShowModal(this)`. And in first one _maybe_ you forgot to set an owner for the window (aka used `form.ShowModal()` instead of `form.ShowModal(this)`). In any case I wouldn't recommend using `WS_EX_COMPOSITED`, imho its makes lots of things buggy (and doesn't works on XP, if you didn't knew that). – Sinatr Jun 07 '13 at 13:38
  • @Sinatr I did tried the things you suggested but it still not working. i.e. child form still flickers when tried first part of code shown above and after using **"dllimport"** in second part the function gets called when form is shown rather at close. – Kapil Jun 07 '13 at 13:53

1 Answers1

0

the Create function should always be called after frmadd form is closed.

So change up your anonymous delegate:

private void button1_Click(object sender, EventArgs e)
{
    frmPopUp frmAdd = new frmPopUp();

    frmAdd.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
    frmAdd.Location = new System.Drawing.Point(450, 200);
    frmAdd.Closed += (s, a) =>
    {
        this.Create();
    };
    frmAdd.Show(this);
}
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
  • thanks a ton. Easy solution but did not think of it, I think I need to be more attentive while coding. again thanks.. – Kapil Jun 08 '13 at 12:48