|
My program has different "modes". Each mode has its own control which inherits a base control. The base control has the base code which each control uses. The mode controls have different functionnality.
What i want to be able to do is change the mode, which means changing the control but without loosing the data/view which the control is using.
E.g: If your in Edit mode, you can switch to View mode but not have to re-create the data.
Im abit stuck on how i'd do this, as once you dispose of the control, you loose the data.
Any ideas are appreciated.
Regards,
Gareth.
|
|
|
|
|
Why disposing it? simply make it hidden. it will keep the data.
~~~ From Milano to The Hague, easy as it goes ~~~
|
|
|
|
|
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 />
{
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 />
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 works ) 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
|
|
|
|
|
Martin, your code example doesnt work. It creates the control but doesnt show it. I've tried adding it to the Controls class, as well as Docking and BringToFront.
|
|
|
|
|
Hello,
I think I have to see the code to say more about that.
All the best,
Martin
|
|
|
|
|
SimulationModel newControl = new SimulationModel(session, true);<br />
EditModel oldControl = this as EditModel;<br />
<br />
PropertyDescriptorCollection pdcoldControl = TypeDescriptor.GetProperties(oldControl);<br />
PropertyDescriptorCollection pdcnewControl = TypeDescriptor.GetProperties(newControl);<br />
<br />
foreach (PropertyDescriptor pdoldControl in pdcoldControl)<br />
{<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 />
<br />
TypeDescriptor.Refresh(oldControl);<br />
TypeDescriptor.Refresh(newControl);<br />
<br />
newControl.Size = oldControl.Size;<br />
newControl.Text = oldControl.Text;<br />
<br />
oldControl.Dispose();<br />
Controls.Add(newControl);<br />
newControl.BringToFront();
|
|
|
|
|
Hello Gareth,
gareth111 wrote: this as EditModel
Ohhhhhh,
You are inside of one derived class.
You have to be carefull there.
gareth111 wrote: oldControl.Dispose();
Controls.Add(newControl);
newControl.BringToFront();
//You have to place the new Control in the Parent Container(Controls) not in the oldControls Container(Controls).
if(Parent!=null)
{
Parent.Controls.Remove(this); //Remove oldControls(this)
Parent.Controls.Add(newControl); //Add newControl
Dispose(); //frees the memory
}
Hope it works! (please let me know)
All the best,
Martin
|
|
|
|
|
Hello Gareth,
Just saw you in the forum, whanted to know if this worked for you?
Martin
|
|
|
|
|
Martin,
After your post, my super visor decided we didnt need to implement it anymore, so i never got around to trying it. Thanks for your help anyways!
|
|
|
|
|
Hello all together,
I have a problem with my custom user control. It has some childcontrols (also usercontrols) which will be movable inbetween the custom control.
But I have some regions (Top and Left area) which should be tabu for it's childcontrols. So my question is, how can I set a ClipRectangle Region where childcontrols are allowed to be painted?
I solved temporarly this problem with calculating a Region area, if a childcontrols location is inbetween the "zone which is not allowed", but I have to check this Region each movement and will be very slowly.
So I would be pleased if someone could explain me a solution.
Thanks for replies.
With best regards
Norman-Timo
|
|
|
|
|
Hi,
Hope every one is doing fine... well I need a little help regarding FOLDER LOCK, by which I necessarily mean that on double clicking the folder my own custom exe could run and after doing some task, could finally open the folder upon successful authentication.
If any body could help me out... and secondly I am thinking about folder lock in terms of archiving files and then giving that archived file a custom extension... this could also solve the problem... I have to make a decision what to do... if any body has some idea to work around this issue I will be very thankful to him/her.
PS:I am using C#, .NET Framework 2.0.
Thanks...
Regards.
|
|
|
|
|
Hello Sir,
Did u find solution for your question?
If so, please let me know ..even i got stuck at this point.
Thank you
|
|
|
|
|
Guys,
I have multiple listviews on a form. I select one item of one listview (so far so good), but if I select an item from another listview, the item from the first listview is deselected. Is this some property setting? I couldn't found which one.
I want to select an item from each listview without deslecting the item when the focus moves.
Thanks!
Found it! mm to quick: HideSelection=false; doesn't seem to solve it
V.
Stop smoking so you can: enjoy longer the money you save.
|
|
|
|
|
I normally iterate through arraylists with a foreach loop. However im iterating to search for a certain item to remove from the arraylist and i cant iterate and remove the item when its found in the foreach loop becasue it throws an exception. my arraylist is holding a list of listview items and im going to use a for loop or while loop to remove it from the arraylist. my problem is that i dont know how to iterate through arraylists and extract a single item when im not using a foreach loop. can someone help me get the right syntax for this?
|
|
|
|
|
A solution may be copying the arraylist and iteration over the copied version
|
|
|
|
|
I never thought about doing that and it worked perfectly, and was extremely simple. Thanks!!!
|
|
|
|
|
Try this.
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace Assistant
{
class Program
{
static void Main(string[] args)
{
ArrayList al = new ArrayList(4);
al.Add("Val1");
al.Add("Val2");
al.Add("Val3");
al.Add("Val4");
int iListLen = al.Count;
for (int i = 0; iListLen > i; i++)
{
if (al[i].ToString() == "Val3")
{
al.RemoveAt(i);
break;
}
}
}
}
}
|
|
|
|
|
Thanks for your help too
|
|
|
|
|
How to read an exact character from text file
Example:line 2 char 15
I have Visual Studio 2003
sr.Read()[15]; is not the correct sollution
Vasildb
|
|
|
|
|
I would imagine you would have to parse the file to find the second line, then offset from the start of the second line to find the 15th character. Some text representations use multibyte character encoding so it may not be a 15 byte (or 30 byte) offset because each character can have a different length to the next one.
|
|
|
|
|
You, or somebody else already asked this question a couple of days before...
Is this homework?
V.
Stop smoking so you can: enjoy longer the money you save.
|
|
|
|
|
Not only is it most likely homework, but the other guy was on the ball, and asked immediately. This person seems to be a slacker that waits for the last minute.
|
|
|
|
|
i am using the progressbar control to show the progress of the sound file
how could i do that?
thank u
abdelhameed81
|
|
|
|
|
According to your first sentence, you already are!
|
|
|
|
|
Get the time that it will take for the sound file to complete - set the max value of the progress bar to this, and then every second (hint - use a timer), increment the counter.
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|