I am working on a project where I have designed a custom control, and I am trying to add it to and locate it within a group box.
The steps of initialising and adding the control to the box work fine, but then anything I attempt to move or resize the control causes an exception.
//initialise using object in outputs collection
VitalsVisual vitalsVisual = vitalOutputs.getVitalsVisual();
//add to relevant groupbox
grpbxIntraOp.Controls.Add(vitalsVisual);
//change location (coordinates within groupbox)
vitalsVisual.Location = new Point(249, 256); //THROWS EXCEPTION
//resize
vitalsVisual.Size = new Size(494, 342); //THROWS EXCEPTION IF REACHED
All I get on either of the indicated lines is "Object reference not set to an instance of an object". I don't really understand this, as it would point to the VitalsVisual vitalsVisual
not being initialised, but the constructor is called and the Controls.Add()
command is working. Surely if it had not been initialised, this command would throw the same exception.
Can anybody spot what might be wrong here? Would really appreciate a nudge in the right direction!
Thanks, Mark