|
In short you want something to that gives you an 'undo' feature. I don't like recommending 'design patterns' without looking at several alternatives, but in this case the Memento pattern fits well.
Googling will give you a solid explanation.
Wikipedia has a short code sample:
Memento pattern[^]
|
|
|
|
|
I see the use of the pattern, but it seems this will only work for a single member that defines the state, while I meant the state of the object itself and all of its members... I'm afraid this won't work, but thanks for the info.
|
|
|
|
|
You could do the following:
Make the following changes to your class:
public class MyClass : ICloneable
{
public MyClass(){}
public MyClass(object newInstance)
{
if ( !(newInstance is MyClass) ) throw new Exception...
MyClass instance = (MyClass)newInstance;
}
public object Clone
{
return (object)this;
{
}
Then in your code you would do as follows:
...
MyClass newObject = new MyClass(oldObject.Clone());
Unfortunately, there is no ICloneable<t> and object is all you can pass.
|
|
|
|
|
Wesner Moise has a good blog posting[^] regarding how to clone objects that don't implement ICloneable. He basically uses reflection to invoke the protected MemberwiseClone method.
If you have the source code to this object, I'd just make it implement ICloneable.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Looks interesting, I'll try this out...
|
|
|
|
|
Works perfectly... Thank you.
|
|
|
|
|
I'm doing this using the Clone method of the object. I think there's no universal mechanism for copying objects, so you need to implement this method by your own. If you are working with more types, it is good to use some ICloneable interface.
This is an example:
<br />
public interface ICloneable {<br />
<br />
object Clone();<br />
}<br />
<br />
public class BitmapWithArray : ICloneable {<br />
<br />
public Bitmap bitmap = null;<br />
public int[] array = null;<br />
public ushort someValue = 0;<br />
<br />
public object Clone() {<br />
<br />
BitmapWithArray obj = new BitmapWithArray();<br />
<br />
if (this.bitmap != null)<br />
obj.bitmap = (Bitmap)this.bitmap.Clone();<br />
<br />
if (this.array != null)<br />
obj.array = (int[])this.array.Clone();<br />
<br />
obj.someValue = this.someValue;
}<br />
}<br />
|
|
|
|
|
Why does the cursor moves one tab ahead when i press Ctrl + I key combination?
Thanks,
Pramod
|
|
|
|
|
Uhhmm because you pressed the Ctrl+I key?
If you want a different behaviour, you must program it.
private void richTextBox1_KeyPress( object sender, KeyPressEventArgs e )
{
if ( e.KeyChar == Keys.ControlKey & Keys.I )
{
richTextBox1.Font = new Font( "Arial", FontStyle.Italic );
e.Handled = true;
}
}
|
|
|
|
|
I want to change the Font Style to Italics,
and i have written the following code:
if (e.KeyCode == Keys.B && e.Modifiers == Keys.Control)
{
tbbTextFormatting_ButtonClick(tbbTextFormatting, new ToolBarButtonClickEventArgs(tbbBold));
}
else if (e.KeyCode == Keys.I && e.Modifiers == Keys.Control)
{
tbbTextFormatting_ButtonClick(tbbTextFormatting, new ToolBarButtonClickEventArgs(tbbItalic));
}
else if (e.KeyCode == Keys.U && e.Modifiers == Keys.Control)
tbbTextFormatting_ButtonClick(tbbTextFormatting, new ToolBarButtonClickEventArgs(tbbUnderline));
is something wrong in this code?
the Bold and Underline work fine
but for italics the cursor moves one tab ahead.
Thanks & Regards,
Pramod
|
|
|
|
|
Try this...
if (e.KeyCode == Keys.B && e.Modifiers & Keys.Control != 0)
{
Reformat(tbbTextFormatting, new ToolBarButtonClickEventArgs(tbbBold));
}
else if (e.KeyCode == Keys.I && e.Modifiers & Keys.Control != 0)
{
Reformat(tbbTextFormatting, new ToolBarButtonClickEventArgs(tbbItalic));
}
else if (e.KeyCode == Keys.U && e.Modifiers & Keys.Control != 0)
Reformat(tbbTextFormatting, new ToolBarButtonClickEventArgs(tbbUnderline));
|
|
|
|
|
Still the cursor moves one tab ahead from the current location.
Pramod
|
|
|
|
|
Are you setting e.Handled = true ???
|
|
|
|
|
NO,
When should i set that?
after my code or before that.
Thanks & Regards,
Pramod
|
|
|
|
|
Hi guys,
I need some help, I am working on validation of the product and I was wondering if you guys could give me some suggestions on how to do it. Basically what I intend to do is to have 1 month, 6 months and 12 month product keys. I am having trouble especially figuring out how to monitor the time; what if the user changes time on their system? etc.
Please help
|
|
|
|
|
At this moment there is no hack free easy solution for this problem.
|
|
|
|
|
you can try one thing,
Store the Key, The Registratrion Date and the period in the database
and whenever u need to check the validity use the database servers current date instead of the local machine date.
I guess u dont change the database servers date.
Hope that works for u.
Regards,
Pramod
|
|
|
|
|
This response might work for the one who asked , but on a theoretical level their is a problem with this solutions. The problem is that you need the client to connect to the server all the time (or by the start of the application).
1 The client can block your app in the firewall.
2 And what if the app is installed on a labtop? One cannot block out users that don't have a connection to the internet 24/7.
|
|
|
|
|
You have a point,
my solution will work only for the applications that connect to the database.
Thanks & Regards,
Pramod
|
|
|
|
|
Internet activation always works but it is wrong. Machine based authentication can be done with encypryption and the registry Unf, windows doesn't allow self modifying executables. However, you could also use a generated resource file.
I like to cripple my apps in such a manner as to allow full access but make it difficult to use professionally.
For more expensive applications there is always the hardware key.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
One thing that I've seen products do is they will create a dll in the Windows/System32 library that is actually a binary serialization of the data they need. They do a nice job of also picking a name that looks important. You are still vulnerable if they are running a product that allows the user to stop an application from writing to disk. I've seen demo products running for months because they could not write their DLL to the hard drive.
|
|
|
|
|
What about using the licensing system that is built into .NET? There is a free open source version that ties into that and works pretty well. Open License[^]
It allows you to set a date range or number of days that a license is valid. The app would then fail on coming up and you could tell in the main function that it was a license issue and prompt the user to get a new one or whatever you want.
Steve Maier, MCSD MCAD MCTS
|
|
|
|
|
Hi guys/gals!
I have a little problem with creating a MSI package. I have added the custom "Customer Information" dialog to my installation process, but I don't know where this information is written to. I want to use this information for display on my "About" box and maybe later for online registration proposes.
Can anybody help?
Willem Le Roux
|
|
|
|
|
The information only exists in memory. You would have to write a custom installer action that gets the data passed to it, then the code would have to persist it.
|
|
|
|
|
Okay And now repeat in English please
Sorry mrCondor, but I have no idea what you are talking about... Yet. I played around with what I think your idea is, and it seems that I will have to write some other application (exe), DLL, script (js... preferably) or something like that to get the information and write it to the registry... somewhere... Perhaps?
Also, I toyed around in MS help and got some interesting goodies about Properties, USERNAME properties, COPANYNAME properties, UserSID properties, how all this gets written to the registry under the "InstallProperties" key and all sorts of tit-bits like that, but no example, no nothing.
Can anybody please steer me in a general direction? I have absolutly no idea where to start... Fooling a little feelish now! uhm he he he...
Willem Le Roux
|
|
|
|