EnableVisualStyles, ComboBox, ShowDialog?

G

Guest

hi all,
I encounter problems when calling Form.ShowDialog() in a
ComboBox.SelectedIndexChanged-EventHandler. After the EventHandler is
executed a SEHException is thrown. This only happens if EnableVisualStyles
was called (see sample code).

Is this a known problem? is there a workaround other than not using
VisualStyles?

pp

VS 2003 (7.1.3088)
..NET 1.1 (1.1.4322)

#####code#####

using System;
using System.Windows.Forms;

namespace EnableVisualStylesComboBox
{
public class Form1 : Form
{
private System.Windows.Forms.ComboBox comboBox1;
private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();

comboBox1.Items.Add("Item 0");
}

private void comboBox1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
new Form().ShowDialog();
}

#region dispose

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#endregion

#region designer

private void InitializeComponent()
{
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(20, 20);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(250, 21);
this.comboBox1.TabIndex = 0;
this.comboBox1.Text = "Select an item and close the popup form.";
this.comboBox1.SelectedIndexChanged += new
System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 66);
this.Controls.Add(this.comboBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}

#endregion


[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();

Application.Run(new Form1());
}
}
}
 
G

Guest

Hello pachyphloia,

Your problem may be related with the following article:
You receive an "unhandled exception of type 'System.Runtime.InteropServices.SEHException'" error message when you call the Application.EnableVisualStyles method in Visual Basic .NET 2003 and in Visual Basic 2002
http://support.microsoft.com/default.aspx?scid=kb;en-us;897298

Regards.


"pachyphloia" <[email protected]> escribió en el mensaje | hi all,
| I encounter problems when calling Form.ShowDialog() in a
| ComboBox.SelectedIndexChanged-EventHandler. After the EventHandler is
| executed a SEHException is thrown. This only happens if EnableVisualStyles
| was called (see sample code).
|
| Is this a known problem? is there a workaround other than not using
| VisualStyles?
|
| pp
 
G

Guest

hello josé,

thanks for your input. I know that article, it deals with problems caused by
calling EnableVisualStyles from eventhandlers. As you can see in the sample
code in my original post, I call EnableVisualStyles in Main even before
calling Application.Run() as it is recommended by the article.

pp
 
G

Guest

Hello pp,

Have you tried using a manifest file instead of calling Application.EnableVisualStyles? It seems that the .NET implementation has some problems.

Regards.


"pachyphloia" <[email protected]> escribió en el mensaje | hello josé,
|
| thanks for your input. I know that article, it deals with problems caused by
| calling EnableVisualStyles from eventhandlers. As you can see in the sample
| code in my original post, I call EnableVisualStyles in Main even before
| calling Application.Run() as it is recommended by the article.
|
| pp
|
| "José Manuel Agüero" wrote:
|
| > Hello pachyphloia,
| >
| > Your problem may be related with the following article:
| > You receive an "unhandled exception of type 'System.Runtime.InteropServices.SEHException'" error message when you call the Application.EnableVisualStyles method in Visual Basic .NET 2003 and in Visual Basic 2002
| > http://support.microsoft.com/default.aspx?scid=kb;en-us;897298
| >
| > Regards.
| >
| >
| > "pachyphloia" <[email protected]> escribió en el mensaje | > | hi all,
| > | I encounter problems when calling Form.ShowDialog() in a
| > | ComboBox.SelectedIndexChanged-EventHandler. After the EventHandler is
| > | executed a SEHException is thrown. This only happens if EnableVisualStyles
| > | was called (see sample code).
| > |
| > | Is this a known problem? is there a workaround other than not using
| > | VisualStyles?
| > |
| > | pp
| >
| >
 
G

Guest

hello josé,

I expected Application.EnableVisualStyles() to be equivalent to a manifest
file declaring the visual style common-control dependency - how could I be so
naive?
now I tried and no more SEHExceptions in the combobox sample and various
other code.

thanks
pp
 

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