Click here to Skip to main content
15,903,175 members
Home / Discussions / C#
   

C#

 
QuestionClosing Console Window without Closing Application Window Pin
jackie83sg200517-Nov-06 3:43
jackie83sg200517-Nov-06 3:43 
AnswerRe: Closing Console Window without Closing Application Window Pin
Karthik Kalyanasundaram17-Nov-06 4:17
Karthik Kalyanasundaram17-Nov-06 4:17 
GeneralRe: Closing Console Window without Closing Application Window Pin
jackie83sg200517-Nov-06 13:36
jackie83sg200517-Nov-06 13:36 
QuestionScale form with it controls Pin
seq-17-Nov-06 3:36
seq-17-Nov-06 3:36 
AnswerRe: Scale form with it controls Pin
seq-17-Nov-06 4:16
seq-17-Nov-06 4:16 
QuestionChanging a Control at run time Pin
Gareth H17-Nov-06 3:18
Gareth H17-Nov-06 3:18 
AnswerRe: Changing a Control at run time Pin
Rey999917-Nov-06 4:23
Rey999917-Nov-06 4:23 
AnswerRe: Changing a Control at run time [modified] Pin
Martin#17-Nov-06 10:37
Martin#17-Nov-06 10:37 
Hello,

Hope I understand everything write.

You have a base Control (I name it ControlA) and two Controls (I name them ControlA1 and ControlA2) which inherit from ControlA.
You have for example a ControlA1 (I name it myControlA1) in your program(on your form) and at runtime it has to be changed to a ControlA2.

I think what you have to do in, this very special case, is to make a new instance of your ControlA2.

ControlA2 newControl = new ControlA2();

Then you have to, lets say downgrade, your ControlA1 to a ControlA Control.

ControlA oldControl = myControlA1 as ControlA;

Now you should copy (clone) the property values from oldControl to newControl.
Therefore the namespace "System.ComponentModel" is required.

			PropertyDescriptorCollection pdcoldControl = TypeDescriptor.GetProperties(oldControl);<br />
			PropertyDescriptorCollection pdcnewControl = TypeDescriptor.GetProperties(newControl);<br />
<br />
			foreach(PropertyDescriptor pdoldControl in pdcoldControl)<br />
			{        //Here you should define some rules like this:<br />
				if((pdoldControl.Attributes.Contains(CategoryAttribute.Appearance) && pdoldControl.IsBrowsable)<br />
					|| (pdoldControl.Attributes.Contains(CategoryAttribute.Behavior) && pdoldControl.IsBrowsable && pdoldControl.IsReadOnly==false))<br />
				{<br />
					PropertyDescriptor pdnewControl = pdcnewControl[pdoldControl.Name];<br />
					pdnewControl.SetValue(newControl,pdoldControl.GetValue(oldControl));<br />
				}<br />
			}<br />
			TypeDescriptor.Refresh(oldControl);<br />
			TypeDescriptor.Refresh(newControl);<br />
<br />
                        //set some additional properties, like this:<br />
			newControl.Size = oldControl.Size;<br />
			newControl.Text = oldControl.Text;


This code would of course look nicer in a method.

Now you can place the newControl, and remove and dispose the myControlA1.

This only works (if it worksUnsure | :~ ) as long as your Form or parent control is in memory.

Hope that helped you.

All the best,

Martin



-- modified at 16:43 Friday 17th November, 2006
GeneralRe: Changing a Control at run time Pin
Gareth H21-Nov-06 3:34
Gareth H21-Nov-06 3:34 
GeneralRe: Changing a Control at run time Pin
Martin#21-Nov-06 9:20
Martin#21-Nov-06 9:20 
GeneralRe: Changing a Control at run time Pin
Gareth H21-Nov-06 22:46
Gareth H21-Nov-06 22:46 
GeneralRe: Changing a Control at run time Pin
Martin#22-Nov-06 2:12
Martin#22-Nov-06 2:12 
GeneralRe: Changing a Control at run time Pin
Martin#12-Dec-06 0:55
Martin#12-Dec-06 0:55 
GeneralRe: Changing a Control at run time Pin
Gareth H12-Dec-06 6:25
Gareth H12-Dec-06 6:25 
QuestionDefine ClipRectangle for ChildControls Pin
Norman-Timo17-Nov-06 3:16
Norman-Timo17-Nov-06 3:16 
QuestionNeed help regarding folder lock Pin
Waqas Nasir17-Nov-06 2:51
Waqas Nasir17-Nov-06 2:51 
AnswerRe: Need help regarding folder lock Pin
archananaresh29-Mar-09 18:20
archananaresh29-Mar-09 18:20 
GeneralTwo listviews Pin
V.17-Nov-06 2:43
professionalV.17-Nov-06 2:43 
Questioniterating arraylists Pin
numbers1thru917-Nov-06 2:04
numbers1thru917-Nov-06 2:04 
AnswerRe: iterating arraylists Pin
ejuanpp17-Nov-06 2:27
ejuanpp17-Nov-06 2:27 
GeneralRe: iterating arraylists Pin
numbers1thru917-Nov-06 2:47
numbers1thru917-Nov-06 2:47 
AnswerRe: iterating arraylists Pin
Private_Void17-Nov-06 2:29
Private_Void17-Nov-06 2:29 
GeneralRe: iterating arraylists Pin
numbers1thru917-Nov-06 2:48
numbers1thru917-Nov-06 2:48 
QuestionHow to read an exact character from text file Pin
CodeItWell17-Nov-06 1:34
CodeItWell17-Nov-06 1:34 
AnswerRe: How to read an exact character from text file Pin
Colin Angus Mackay17-Nov-06 1:46
Colin Angus Mackay17-Nov-06 1:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.