Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
who knows how to overcome this error:
I defined an input field dim
C#
dim = new TextBox();

according to the contents (is an integer) I define a twodimensional array of TextBox:
C#
TextBox [,] a; //-> this Array is defined globally (to have access everywhere in the functions)

in the function
C#
private void dim_Leave(object sender, EventArgs e)
{
try
{
int dm = Int.Parse(dim.Text);
a = new TextBox[dm, dm];
for (int i = 0; i < dm; i++)      // Zeilen
{
    for (int j = 0; j < dm; j++)
    {       // Spalten
        a[i, j] = new TextBox();
        a[i, j].Location = new Point(j * 70 + 26, i * 20 + 70);
        a[i, j].Size = new Size(68, 18);
        a[i, j].Text = "";
        this.Controls.Add(a[i, j]);
    }
}
}
catch {}

By trying to add a[i,j] to the Controls I receive an error "Win32 Exception was unhandled" - error creating windowhandle.
In detail:
System.ComponentModel.Win32Exception was unhandled
  Message="Fehler beim Erstellen des Fensterhandles."
  Source="System.Windows.Forms"
  ErrorCode=-2147467259
  NativeErrorCode=0
  StackTrace:
       bei System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
       bei System.Windows.Forms.Control.CreateHandle()
       bei System.Windows.Forms.TextBoxBase.CreateHandle()
       bei System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       bei System.Windows.Forms.Control.CreateControl()
       bei System.Windows.Forms.Control.ControlCollection.Add(Control value)
       bei System.Windows.Forms.Form.ControlCollection.Add(Control value)
       bei Determinante.detA.dim_Leave(Object sender, EventArgs e) in C:\Users\Michael\Documents\Visual Studio 2008\Projects\Determinante\Determinante\detA.cs:Zeile 60.
       bei System.Windows.Forms.Control.OnLeave(EventArgs e)
       bei System.Windows.Forms.ContainerControl.UpdateFocusedControl()
       bei System.Windows.Forms.ContainerControl.AssignActiveControlInternal(Control value)
       bei System.Windows.Forms.ContainerControl.ActivateControlInternal(Control control, Boolean originator)
       bei System.Windows.Forms.Control.WmSetFocus(Message& m)
       bei System.Windows.Forms.Control.WndProc(Message& m)
       bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  InnerException: 

The coding was already checked, it is ok and works in other machines, I restarted already my machine, the error remained unchanged, please help if you know how!


Thank you in advance
Your's
MiKr41
Posted
Updated 17-Oct-13 10:20am
v4
Comments
Richard MacCutchan 16-Oct-13 6:48am    
I just tried this code and it works fine, there must be something else that is happening in your version. Check the value of dm when the error occurs.
ZurdoDev 17-Oct-13 13:35pm    
What's the error in English?
Sergey Alexandrovich Kryukov 17-Oct-13 13:45pm    
You need to tag not just platform, but also language, some library used (in this case, tag "WinForms"), whatever is relevant...
—SA
Member 10284036 18-Oct-13 19:11pm    
language is C#, VS 2008, environment windows 7 professional, 4 GB memory Dell machine
Sergey Alexandrovich Kryukov 18-Oct-13 19:16pm    
It needs tags (using "Improve question"): C# and WinForms (which you did not mention, can be seen by content).
You are the one who is interested in tags the most.

And, no, nothing is "defined globally" (thank goodness, there is no such thing).
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900