ArgumentException when create controls.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My Application made by sevral forms.

Main form construct sevral forms in construction time.

Click the button in Main form then hide Main form and show other form.

Each form has many controls. (almost PictureBox and little panel, Label)

But in creating time, other form's throw ArgumentException in
InitializeComponent() Function. (I cannot fix InitializeComponent() Function.
This function automatically made by IDE.)

Please somebody help me.
Thanks a lot.
 
Put a break point and step into so you can see which line throws. If you are
still having trouble after that, post the code so we can see it.

Cheers
Daniel
 
This is my code.

========== Main Form Constructor==========

public MainForm()
{
Thread timeThread = new Thread(new ThreadStart(timeThreadProc));
timeThread.Start();

if(UserInterfaceManager.DEBUG > 0) HMSConsole.WriteLine("==========
MainForm Start!! =========="); // For Test
//
// Windows Form ë””ìžì´ë„ˆ 지ì›ì— 필요합니다.
//
InitializeComponent();
//
// TODO: InitializeComponent를 호출한 ë‹¤ìŒ ìƒì„±ìž 코드를 추가합니다.
//
this.SetDefaultValue();

if(UserInterfaceManager.DEBUG > 0) HMSConsole.WriteLine("==========
MainForm Start Complete!! =========="); // For Test


try
{
this.frontForm = new FrontForm(this);
if(UserInterfaceManager.DEBUG > 0) HMSConsole.WriteLine("==========
FrontForm Start Complete!! =========="); // For Test

this.telForm = new TelForm(this);

this.controlDeviceForm = new ControlDeviceForm(this);
this.controlElectronicForm = new ControlElectronicForm(this);

this.controlModeForm = new ControlModeForm(this);
this.securityForm = new SecurityForm(this);
this.otherForm = new OtherForm(this);

this.otherScheduleForm = new OtherScheduleForm(this);
this.errorForm = new ErrorForm(this);
}
catch(Exception e)
{
HMSConsole.WriteLine("MainForm Exception String >> {0}", e.ToString());
}
}
=============================================

========== other Form InitializeComponent() Function==========

private void InitializeComponent()
{
this.PB_Running = new ImageButton();
this.Panel_Ctrl = new System.Windows.Forms.Panel();
this.PB_Ctrl_02_Icon_Oven = new ImageButton();
this.PB_Ctrl_02_Icon_Refre = new ImageButton();
this.PB_Ctrl_02_Icon_Aircon = new ImageButton();
this.PB_Ctrl_02_Icon_Washer = new ImageButton();
this.PB_Ctrl_02_Icon_Range = new ImageButton();
this.PB_Ctrl_02_BTN_Up_Off = new ImageButton();
this.PB_Ctrl_02_BTN_Down_Off = new ImageButton();
this.PB_Ctrl_Home = new ImageButton();
this.PB_Ctrl_02_Title = new ImageButton();
this.PB_Ctrl_02_Sub_List = new ImageButton();
this.PB_Ctrl_02_Sub_Nothing = new ImageButton();
this.PB_Ctrl_02_Background = new ImageButton();
this.PB_Ctrl_02_Sub_Background = new ImageButton();
//
// Panel_Ctrl
//
this.Panel_Ctrl.BackColor =
System.Drawing.Color.FromArgb(((System.Byte)(227)), ((System.Byte)(226)),
((System.Byte)(227)));
this.Panel_Ctrl.Controls.Add(this.PB_Running);
this.Panel_Ctrl.Controls.Add(this.PB_Ctrl_02_Icon_Oven);
this.Panel_Ctrl.Controls.Add(this.PB_Ctrl_02_Icon_Refre);
this.Panel_Ctrl.Controls.Add(this.PB_Ctrl_02_Icon_Aircon);
this.Panel_Ctrl.Controls.Add(this.PB_Ctrl_02_Icon_Washer);
this.Panel_Ctrl.Controls.Add(this.PB_Ctrl_02_Icon_Range);
this.Panel_Ctrl.Controls.Add(this.PB_Ctrl_02_BTN_Up_Off);
this.Panel_Ctrl.Controls.Add(this.PB_Ctrl_02_BTN_Down_Off);
this.Panel_Ctrl.Controls.Add(this.PB_Ctrl_Home);
this.Panel_Ctrl.Controls.Add(this.PB_Ctrl_02_Title);
this.Panel_Ctrl.Controls.Add(this.PB_Ctrl_02_Sub_List);
this.Panel_Ctrl.Controls.Add(this.PB_Ctrl_02_Sub_Nothing);
this.Panel_Ctrl.Controls.Add(this.PB_Ctrl_02_Background);
this.Panel_Ctrl.Controls.Add(this.PB_Ctrl_02_Sub_Background);
this.Panel_Ctrl.Size = new System.Drawing.Size(800, 600);
//
// PB_Running
//
this.PB_Running.Image = new
Bitmap(@"\DiskOnChip\HHNS\Framework\Images\running.jpg");
this.PB_Running.Location = new System.Drawing.Point(86, 197);
this.PB_Running.Size = new System.Drawing.Size(637, 174);
this.PB_Running.Visible = false;
//
// PB_Ctrl_02_Icon_Oven
//
this.PB_Ctrl_02_Icon_Oven.Image = new
Bitmap(@"DiskOnChip\HHNS\Framework\Images\ctrl_02_icon_oven.jpg");
this.PB_Ctrl_02_Icon_Oven.Location = new System.Drawing.Point(162, 172);
this.PB_Ctrl_02_Icon_Oven.Size = new System.Drawing.Size(91, 109);
this.PB_Ctrl_02_Icon_Oven.Visible = false;
this.PB_Ctrl_02_Icon_Oven.Click += new
System.EventHandler(this.PB_Ctrl_02_Icon_Oven_Click);
//
// PB_Ctrl_02_Icon_Refre
//
this.PB_Ctrl_02_Icon_Refre.Image = new
Bitmap(@"DiskOnChip\HHNS\Framework\Images\ctrl_02_icon_ref.jpg");
this.PB_Ctrl_02_Icon_Refre.Location = new System.Drawing.Point(347, 172);
this.PB_Ctrl_02_Icon_Refre.Size = new System.Drawing.Size(91, 109);
this.PB_Ctrl_02_Icon_Refre.Visible = false;
this.PB_Ctrl_02_Icon_Refre.Click += new
System.EventHandler(this.PB_Ctrl_02_Icon_Refre_Click);//
// PB_Ctrl_02_Icon_Aircon
//
this.PB_Ctrl_02_Icon_Aircon.Image = new
Bitmap(@"DiskOnChip\HHNS\Framework\Images\ctrl_02_icon_aircon.jpg");
this.PB_Ctrl_02_Icon_Aircon.Location = new System.Drawing.Point(532, 172);
this.PB_Ctrl_02_Icon_Aircon.Size = new System.Drawing.Size(91, 109);
this.PB_Ctrl_02_Icon_Aircon.Visible = false;
this.PB_Ctrl_02_Icon_Aircon.Click += new
System.EventHandler(this.PB_Ctrl_02_Icon_Aircon_Click);
//
// PB_Ctrl_02_Icon_Washer
//
this.PB_Ctrl_02_Icon_Washer.Image = new
Bitmap(@"DiskOnChip\HHNS\Framework\Images\ctrl_02_icon_washer.jpg");
this.PB_Ctrl_02_Icon_Washer.Location = new System.Drawing.Point(162, 323);
this.PB_Ctrl_02_Icon_Washer.Size = new System.Drawing.Size(91, 109);
this.PB_Ctrl_02_Icon_Washer.Visible = false;
this.PB_Ctrl_02_Icon_Washer.Click += new
System.EventHandler(this.PB_Ctrl_02_Icon_Washer_Click);
//
// PB_Ctrl_02_Icon_Range
//
this.PB_Ctrl_02_Icon_Range.Image = new
Bitmap(@"DiskOnChip\HHNS\Framework\Images\ctrl_02_icon_range.jpg");
this.PB_Ctrl_02_Icon_Range.Location = new System.Drawing.Point(347, 323);
this.PB_Ctrl_02_Icon_Range.Size = new System.Drawing.Size(91, 109);
this.PB_Ctrl_02_Icon_Range.Visible = false;
this.PB_Ctrl_02_Icon_Range.Click += new
System.EventHandler(this.PB_Ctrl_02_Icon_Range_Click);
//
// PB_Ctrl_02_BTN_Up_Off
//
this.PB_Ctrl_02_BTN_Up_Off.Image = new
Bitmap(@"DiskOnChip\HHNS\Framework\Images\ctrl_02_btn_up_off.jpg");
this.PB_Ctrl_02_BTN_Up_Off.Location = new System.Drawing.Point(512, 517);
this.PB_Ctrl_02_BTN_Up_Off.Size = new System.Drawing.Size(80, 32);
this.PB_Ctrl_02_BTN_Up_Off.Visible = false;
//
// PB_Ctrl_02_BTN_Down_Off
//
this.PB_Ctrl_02_BTN_Down_Off.Image = new
Bitmap(@"DiskOnChip\HHNS\Framework\Images\ctrl_02_btn_down_off.jpg");
this.PB_Ctrl_02_BTN_Down_Off.Location = new System.Drawing.Point(604, 517);
this.PB_Ctrl_02_BTN_Down_Off.Size = new System.Drawing.Size(80, 32);
this.PB_Ctrl_02_BTN_Down_Off.Visible = false;
//
// PB_Ctrl_Home
//
this.PB_Ctrl_Home.Image = new
Bitmap(@"DiskOnChip\HHNS\Framework\Images\home.jpg");
this.PB_Ctrl_Home.Location = new System.Drawing.Point(629, 15);
this.PB_Ctrl_Home.Size = new System.Drawing.Size(151, 46);
this.PB_Ctrl_Home.Click += new System.EventHandler(this.PB_BTN_Home_Click);
//
// PB_Ctrl_02_Title
//
this.PB_Ctrl_02_Title.Image = new
Bitmap(@"DiskOnChip\HHNS\Framework\Images\ctrl_02_title.jpg");
this.PB_Ctrl_02_Title.Location = new System.Drawing.Point(74, 18);
this.PB_Ctrl_02_Title.Size = new System.Drawing.Size(161, 38);
this.PB_Ctrl_02_Title.Visible = false;
//
// PB_Ctrl_02_Background
//
this.PB_Ctrl_02_Background.Image = new
Bitmap(@"\DiskOnChip\HHNS\Framework\Images\ctrl_02_bg.jpg");
this.PB_Ctrl_02_Background.Size = new System.Drawing.Size(800, 600);
this.PB_Ctrl_02_Background.Enabled = false;
this.PB_Ctrl_02_Background.Visible = false;
//
// PB_Ctrl_02_Sub_Background
//
this.PB_Ctrl_02_Sub_Background.Image = new
Bitmap(@"\DiskOnChip\HHNS\Framework\Images\ctrl_02_sub_bg.jpg");
this.PB_Ctrl_02_Sub_Background.Size = new System.Drawing.Size(800, 600);
this.PB_Ctrl_02_Sub_Background.Enabled = false;
this.PB_Ctrl_02_Sub_Background.Visible = false;
//
// PB_Ctrl_02_Sub_List
//
this.PB_Ctrl_02_Sub_List.Image = new
Bitmap(@"DiskOnChip\HHNS\Framework\Images\ctrl_02_btn_list.jpg");
this.PB_Ctrl_02_Sub_List.Location = new System.Drawing.Point(697, 158);
this.PB_Ctrl_02_Sub_List.Size = new System.Drawing.Size(52, 160);
this.PB_Ctrl_02_Sub_List.Visible = false;
this.PB_Ctrl_02_Sub_List.Click += new
System.EventHandler(this.PB_Ctrl_02_Sub_List_Click);
//
// PB_Ctrl_02_Sub_Nothing
//
this.PB_Ctrl_02_Sub_Nothing.Image = new
Bitmap(@"DiskOnChip\HHNS\Framework\Images\ctrl_02_icon_no.jpg");
this.PB_Ctrl_02_Sub_Nothing.Location = new System.Drawing.Point(159, 251);
this.PB_Ctrl_02_Sub_Nothing.Size = new System.Drawing.Size(463, 196);
this.PB_Ctrl_02_Sub_Nothing.Visible = false;
//
// ControlModeForm
//
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(798, 598);
this.Controls.Add(this.Panel_Ctrl);
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = FormBorderStyle.None;
this.ControlBox = false;
this.Menu = null;
}

===================================================

If I delete "PB_Ctrl_02_Icon_Aircon" part then "PB_Ctrl_02_Icon_Washer" part
occured error.

I wait your advice.

Thanks a lot.
 
I wouldn't class that as a small reproducible sample, but even so it is
missing a lot of methods (e.g. SetDefaultValue and all the event handlers).

You are starting a thread in one of the ctors. The question is what does
that thread do? Also note that in the timeThreadProc you cannot touch any UI
elements. Also note that you do not keep a reference to that thread anywhere
outside the scope of the method (is that by design or an error?).

In many place you are calling form ctors that take an argument; clearly you
have written those yourself but you haven't showed us what is inside them. A
common error is to forget to call the parameterless ctor (or at least
InitializeComponent) from in them.

I am not sure it is worth analysing further your code since as I said it is
missing many methods and context. Please provide a small reproducible sample
(or at least something that compiles) if you want me to look at this
further.

Feel free to post back with specifics.

Cheers
Daniel
 
Back
Top