|
Hi originSH,
It seems that u didn't got me correctly. U have told me about Text property of control, but I was talking about setting IME mode. U have told me about translation but I was asking about Transliteration.
Anyways thanx for ur efforts.
Regards
Prasad
|
|
|
|
|
|
Hi All,How can I create popup menu with images in C#...for example in iGoogle when we want to change the theme,it lists us several options with images...
Hi,Im Razana
|
|
|
|
|
Hello,
There are some articles here on CP which will help!
I found this one[^] written by John O'Byrne.
All the best,
Martin
|
|
|
|
|
Hey Martin I would like to do it in web form...
Hi,Im Razana
|
|
|
|
|
i want to know how can i write combobox items in a file
here is coding which i wrote but its giving error
StreamWriter sw = new StreamWriter(".\\ABCD.B");
for (int a = 0; a < am.Items.Count; a++)
{
sw.WriteLine(am.Items(a));
}
sw.Flush();
sw.Close();
where "am" is combobox
the error is
'System.Windows.Forms.ComboBox.Items' is a 'property' but is used like a 'method'
|
|
|
|
|
Hello,
Use "Items[a]".
xmen_xwk wrote: where "am" is combobox
You should really name it different, than you wouldn't have to explain it!
All the best,
Martin
|
|
|
|
|
oh thats it
Martin# wrote: You should really name it different
i changed the name for private purpose
|
|
|
|
|
xmen_xwk wrote: i changed the name for private purpose
And the first which came in your mind was "am"?
Don't care too much!
Glad I could help.
All the best,
Martin
|
|
|
|
|
Martin# wrote: And the first which came in your mind was "am"?
just shortform
|
|
|
|
|
am.Items[a] to be more safe am.Items[a].ToString()
|
|
|
|
|
Hello,
Nouman Bhatti wrote: to be more safe am.Items[a].ToString()
I'm not working with the StreamWriter to often so I'm currious.
What does it make more safe to pass the object as string?
All the best,
Martin
|
|
|
|
|
Yeah... I think the ToString() method is implicitly called.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Hi
Is there any easy way to draw Digital Signal by using pixel level drawing in C#?
|
|
|
|
|
have you considered looking at WPF in .NET 3.0 for this ? I am assuming by digital signal you are implying something like a Sine or Cosine wave?
|
|
|
|
|
You probably mean Digital Signature? Just look at the system.drawing namespace.
Input would just need to associate the device (whatever it is) to defined events in your objects.
|
|
|
|
|
Hi all,
What is more efficient/better coding practice:
1. Copying objects using the new keyword and a copy constructor
2. Using a Copy member routine which essentially does the same thing as the copy constructor (except we don't actually allocate memory for it using the new keyword).
My gut tells me that (1) is most likely to be more inefficient (since memory has to be allocated and the 'old' value of the object has to be deallocated) but I'd like to confirm this.
cheers!
|
|
|
|
|
jozsurf wrote: Copying objects by value
You mean a deep copy? i.e. all contained objects wether they are value types or reference tpyes are copied? Or a shallow copy where the references to reference types are just copied rather than the values?
jozsurf wrote: 2. Using a Copy member routine which essentially does the same thing as the copy constructor (except we don't actually allocate memory for it using the new keyword).
You mean a static method that does the copy by passing by value?
I'm not very clear about what your suggesting here. If you give some more details I'll be happy to help
|
|
|
|
|
Hi,
if you have one instance of a class, and you suddenly need a second instance that initially
has the same value, you can go either way:
- instantiate the class with what you call a "copy constructor", i.e. a regular constructor
that takes its own type as an input argument and copies values from it (shallow copy);
- or create an instance method that creates a "clone" (=again a shallow copy), by first
instantiating a new instance, then copying values into it. Several CLI classes offer
such a Clone method, e.g. Array and ArrayList
I havent encountered a Copy method yet, one that takes two objects and copies values
from one into the other (DirectX has some Copy methods, but IMO they should have been called
Clone instead).
The cost for both approaches would be the same; they both create a new object and
initialize it. Nowhere in this an object gets deallocated.
Hope this helps.
|
|
|
|
|
Thanks both for your replies. Apologies for being unclear, as my class consists only of primitive/value types (i.e. bools, structs), I only need to do a shallow copy (I suppose a deep copy could be implemented by some form of reflection?).
The following snippet of code is what I'm trying to do:
<br />
<br />
public class SimpleClass<br />
{<br />
public SimpleClass ()<br />
{<br />
a = false;<br />
b = 0;<br />
}<br />
public SimpleClass (SimpleClass s)<br />
{<br />
a = s.a;<br />
b = s.b;<br />
}<br />
public Copy (SimpleClass s)<br />
{<br />
a = s.a;<br />
b = s.b;<br />
}<br />
public bool a;<br />
public int b;<br />
}<br />
<br />
and so my original question was: is there a performance difference between doing
<br />
SimpleClass a = new SimpleClass();<br />
foreach (SimpleClass y in ListOfSimpleClasses)<br />
x.Copy(y); <br />
and
<br />
SimpleClass a = new SimpleClass();<br />
foreach (SimpleClass y in ListOfSimpleClasses)<br />
a = new SimpleClass(y);<br />
Hope this is a little clearer.
cheers!
|
|
|
|
|
Hi,
When taking your examples literally (except for x.Copy which I read as a.Copy),
there is a performance difference, since the second case creates a lot of new objects,
whereas the first does not.
But none of them make any sense: the first copies all existing elements of ListOfSimpleClass
into a single one, one after another without using it at all; the second creates a lot
of objects, each one a copy from a list element, again without using them.
If you need the objects to exist next to each other, the second case is the right one;
if you need the objects only one at a time, there is no need to do the "new..." stuff;
if you only need to read the values anyhow, there is no need to do a Copy at all: just
read the members of y itself.
Hope this helps.
|
|
|
|
|
Apologies for the lousy example. I was trying to give an 'abstract' example and was a bit rushed for time. Guess it's better to spend a bit more time giving a proper example rather then screwing about with 'abstract' (ultimately incomprehensible) examples
What I need this for is to save some application settings as well as be able to load up default settings. If using simple assignment (=), which copies the reference rather then the value, we run the risk of changing the default values which should really be a static, constant value.
1. Load up default values
m_settings = SavedData.DefaultSettings;
2. Change the settings
3. Save the settings
SavedData.Settings = m_settings;
I'm sure you can see how I ended up changing both SavedData.Settings and SavedData.DefaultSettings, and indeed have made both data structures point to one and the same thing!
And so I realised that I needed to copy-by-value; which brought up my original question. I thought it would be a bit weird to do a m_settings = new SettingsClass(SavedData.DefaultSettings); everywhere I want to do a value copy; of course there is also the potential of a difference in performance (although in my case probably negligible, which is why I wanted to bring it up to check).
cheers!
|
|
|
|
|
Hi,
m_settings = SavedData.DefaultSettings;
is quite misleading, it seems to copy a lot of settings, but since it really is a ref type
its just copying the reference as you pointed out. This does not feel good.
Of course, if you have two labels (label1 and label2) on a form, then label1=label2;
also does not change any of the labels, it simply throws away the ref to one of them.
m_settings = new SettingsClass(SavedData.DefaultSettings); is a big no no for me, it does
not reveal the intention.
m_settings = SavedData.DefaultSettings.Clone(); is what I would do, it is much more intuitive.
It resembles list2=list1.Clone(); when you need a copy of an ArrayList so you can modify
list2 while keeping list1 intact.
As I have pointed out in a previous reply, the Clone() method is a combination of
a "new" statement and a copy operation (together, you might call that a copy constructor,
but AFAIK that is not a regular notion in C#)
I am not quite sure I understood it all, the following points are still unclear to me;
I did not need the answers to answer your question, but a better understanding might
(or might not) allow me to propose another approach altogether.
1. the settings (either actual, or default) are stored in a class (SettingsClass) ?
2. you need at least two instances of it, one for defaults, one for actuals ?
3. a ref to both instances, and a lot of other stuff, are stored in SavedData ?
4. you want to be able to modify the default settings ?
5. where did you obtain the default settings ? I guess from a file ? XML ?
6. are you going to save everything (all of SavedData) at once and in one location ?
7. if default settings can be changed, what is the meaning of settings ?
8. is SettingsClass just a list of value types, or does it also contain references
(e.g. strings) ?
9. do you need more than one clone ? I would expect it contains all settings, so you
start of with the defaults, copy once, then modify at will, but your message seems
to suggest you often need a copy ??
Cheers
|
|
|
|
|
Thanks for your reply, Luc. I wasn't aware of the Clone method and I'm afraid that I've probably reinvented the wheel by introducing a Copy method.
1. the settings (either actual, or default) are stored in a class (SettingsClass) ?
Yes.
2. you need at least two instances of it, one for defaults, one for actuals ?
Yes. As we want to be able to revert back to the default settings at any time.
3. a ref to both instances, and a lot of other stuff, are stored in SavedData ?
Correct.
4. you want to be able to modify the default settings ?
Nope.
5. where did you obtain the default settings ? I guess from a file ? XML ?
It's actually hardcoded in the setting class default constructor.
6. are you going to save everything (all of SavedData) at once and in one location ?
Yes the 'current' version of SavedData is written to an XML file at the end of the session. The default version of SavedData is simply recreated at the start of each session.
7. if default settings can be changed, what is the meaning of settings ?
8. is SettingsClass just a list of value types, or does it also contain references
(e.g. strings) ?
Just value types (primitive types and structs). Funny you should mention strings there, although I think my confusion with strings is to do with the fact that strings behave like value types sometimes (i.e. with the "=" operator and the .Equals() method)
9. do you need more than one clone ? I would expect it contains all settings, so you
start of with the defaults, copy once, then modify at will, but your message seems
to suggest you often need a copy ??
Well I may need to copy it many times i.e. the user may choose to revert to default, change something, revert back to default, change something, revert back to default...ad infinitum. So my local copy may be one of three values: a modified version, the default version or the saved version but it has to be independent of the default and saved references.
Hope I understood your questions correctly.
|
|
|
|
|
Hi,
as the default settings are hardcoded and not obtained by parsing an XML file
(hence cheap to reproduce), seems to me the following scheme would do just fine:
1. have class "Settings" with a single constructor, returning a Settings object with
everything set to its default value.
2. do settings=new Settings(); when you need the default settings;
3. do settings=new Settings(); followed by whatever you like, when you want modified
settings
4. do again settings=new Settings(); when you need to revert to the default settings.
In doing so, you dont see any Copy() or Clone() operation; you simply start from the
default, and modify what needs being modified.
One slight modification could be to provide a Clear() method, which sets all
settings in a Settings instance to their default values (obviously now the
constructor would simply call Clear() itself). This allows you to reuse a Settings
object, if you consider this relevant.
[Edit: I guess Reset() is a better name]
One other idea would be to turn Settings into a struct (assuming you stick with
values and structs, again containing only values and structs, etc ad infinitum).
Now settings1=settings2 would really copy everything.
Nevertheless, I do prefer the former approach, because I like "new Settings()";
it shows you get a new object with settings, and it does not limit the members to value types.
(in my apps a lot of settings tend to be strings).
Hope this helps
-- modified at 23:42 Tuesday 17th July, 2007
|
|
|
|
|