howto add control dynamicaly
-
Hy everyone! I designed a windows Form which contains a control by default. Now I do want to add another control depending on the data, meaning if the data contains ínfos which have to be displayed in the control then the control should be inserted, the Form size is changed etc. (if the length where the data is stored is not 0) I managed to check if the data needs the second form and I changed the Forms size, but at the moment I am not sure how to insert the second control dynamicaly. I can't just throw it in like I did with the otherone and let the code being insert automaticaly. So I do want to do something like
if(data.secondform.length!=0) { resize Form insert second control display data in the control }
the other way round shouldn't be the problem meaning removing the control again when I do get data which is not asking for the control. Could anyone of you please tell me what I do have to do to insert the control in my Forms windows? (maybe with some code statements) Thanks! Stephan. -
Hy everyone! I designed a windows Form which contains a control by default. Now I do want to add another control depending on the data, meaning if the data contains ínfos which have to be displayed in the control then the control should be inserted, the Form size is changed etc. (if the length where the data is stored is not 0) I managed to check if the data needs the second form and I changed the Forms size, but at the moment I am not sure how to insert the second control dynamicaly. I can't just throw it in like I did with the otherone and let the code being insert automaticaly. So I do want to do something like
if(data.secondform.length!=0) { resize Form insert second control display data in the control }
the other way round shouldn't be the problem meaning removing the control again when I do get data which is not asking for the control. Could anyone of you please tell me what I do have to do to insert the control in my Forms windows? (maybe with some code statements) Thanks! Stephan.check http://support.microsoft.com/default.aspx?scid=kb;EN-US;319266 Sanjay Sansanwal www.sansanwal.com
-
check http://support.microsoft.com/default.aspx?scid=kb;EN-US;319266 Sanjay Sansanwal www.sansanwal.com
is this the same for Windows.Controls? Meaning could I use the button for example as a sample for my task? Thanks! Stephan.
-
Hy everyone! I designed a windows Form which contains a control by default. Now I do want to add another control depending on the data, meaning if the data contains ínfos which have to be displayed in the control then the control should be inserted, the Form size is changed etc. (if the length where the data is stored is not 0) I managed to check if the data needs the second form and I changed the Forms size, but at the moment I am not sure how to insert the second control dynamicaly. I can't just throw it in like I did with the otherone and let the code being insert automaticaly. So I do want to do something like
if(data.secondform.length!=0) { resize Form insert second control display data in the control }
the other way round shouldn't be the problem meaning removing the control again when I do get data which is not asking for the control. Could anyone of you please tell me what I do have to do to insert the control in my Forms windows? (maybe with some code statements) Thanks! Stephan.The
Form
class inSystem.Windows.Forms
namespace contains aControls
property which is a collection of controls. It has methods to add and remove controls, among others. Check it out on MSDN. - Nick Parker
My Blog | My Articles -
Hy everyone! I designed a windows Form which contains a control by default. Now I do want to add another control depending on the data, meaning if the data contains ínfos which have to be displayed in the control then the control should be inserted, the Form size is changed etc. (if the length where the data is stored is not 0) I managed to check if the data needs the second form and I changed the Forms size, but at the moment I am not sure how to insert the second control dynamicaly. I can't just throw it in like I did with the otherone and let the code being insert automaticaly. So I do want to do something like
if(data.secondform.length!=0) { resize Form insert second control display data in the control }
the other way round shouldn't be the problem meaning removing the control again when I do get data which is not asking for the control. Could anyone of you please tell me what I do have to do to insert the control in my Forms windows? (maybe with some code statements) Thanks! Stephan.Here is one possible approach: in start of program:
object Item = GetData();
...cast Item to specific type...in your data component:
public object GetData()
{
...read the data and determine the different types of data
...now cast that data to the specific type of data
...and return that type-specific object
}public class DataTypeOne
{ .. what makes this unique .. }
public class DataTypeTwo
{ .. what makes this unique .. }in your form
InitializeComponents(); // look familiar?
LoadForm(TypeSpecificItem);
...
public void LoadForm(DataTypeOne item)
{
DataOneForm form = new DataOneForm(item);
this.Components.Add(form);
}
public void LoadForm(DataTypeTwo item)
{
DataTwoForm form = new DataTwoForm(item);
this.Components.Add(form);
}
.... overload for each object type ....This signature left intentionally blank