|
I want to display a form, which(name of form) is stored into a table.After firing query to that table I am getting appropriate value (e.g "frmSTART") into a string variable(myfrm = "frmSTART"),
now how can I treat a string variable value as an object?
So that I can write:
myfrm nSTART = new myfrm ();
nSTART.Show();
Hallo
|
|
|
|
|
Hello,
What you asked for is not possible!
.)
If you know all the possible class names during design time, you simple could make a switch case over the returned string.
string myform = actual_returned_string;
switch(myform)
{
case "test1":
{
MyTest1 t1 = new MyTest1();
break;
}
case "test2":
{
MyTest2 t1 = new MyTest2();
break;
}
default:
break;
}
.)
If you have to make it more dynamic, then you have to look into reflection.
Therefore you should know the namespace of youre formclasses.
You could use a method like this, which returns you a Form to Show.
using System.Reflection;
public System.Windows.Forms.Form GetFormByName(string _name)
{
Type t = Type.GetType(_name);
if (t != null)
{
ConstructorInfo c = t.GetConstructor(Type.EmptyTypes);
Object o = c.Invoke(new Object[0]);
return o as System.Windows.Forms.Form;
}
else
{
return null;
}
}
And you can call it like that:
string namespace =
string myform = namespace+actual_returned_string;
System.Windows.Forms.Form actForm = GetFormByName(myform);
Hope it works for you!
All the best,
Martin
|
|
|
|
|
I don't know why you got voted a 2 for that - I thought the reflection idea was sound.
|
|
|
|
|
Hello,
Colin Angus Mackay wrote: I don't know why you got voted a 2 for that - I thought the reflection idea was sound.
I have also no idea!
It would also be interesting for me to know way, cause I'm using reflection in my application.
So thank's for youre statement!
All the best,
Martin
|
|
|
|
|
Probably because the answer was above the person's comprehension.
|
|
|
|
|
ednrgc wrote: Probably because the answer was above the person's comprehension.
If someone gave me an answer that I didn't understand then I'd follow it up with a request for clarification. Oh, Well....
|
|
|
|
|
Hi
I have to detect either sql server (any version) and db2 are installed on my system or not through c#. Can someone tell me how can i do that?
Regards
sAqIb
"Our scientific power has outrun our spiritual power. We have guided missiles and misguided men."
Dr. Martin Luther King Jr.
|
|
|
|
|
|
Hi there,
What are the controls that can be added as UIElements? can a form be added as a UIElement in dockpanel? Any examples?
|
|
|
|
|
say i have my own defined class, MyClassA, MyClassB
MyClassB b;
MyClassA a = new MyClass(1,"MyName", b);
MyClassA aCopy = new MyClassA();
aCopy = a;
This will make aCopy point to the same object as a, being a reference. I want aCopy to be a distinct object from a, but equal in the sense that it has all its member-data equal in value to those of a. Is the best way to make a copy of another user-defined class through the copy-constructor?
Therefore:
MyClassA aCopy = new MyClassA(a);
provided the copy ctor is provided for MyClassA.
I am a SysAdmin, I battle my own daemons.
|
|
|
|
|
That is certainly one way to do it. .NET also includes the ICloneable interface for the same purpose. Objects which could be copied would implement the interface's single method Clone() that would return a new copy of the object. From my reading, however, the use of this interface seems to be discouraged now due to the lack of consistent semantics regarding the copying act. That is, whether an object created a shallow copy or a deep copy is dependent on a particular implementation of ICloneable. The interface did not specify one way or the other. Plus, having been introduced in .NET 1.0 before generics, client use of ICloneable always required an ugly cast back to the original object type (because the Clone() method return an object of type System.Object). Nonetheless, in my opinion, creating a custom Clone() method that returns a new object of the same type is preferable to a copy constructor. In my mind, the intent of:
MyClassA a = new MyClass();
MyClassA aCopy = a.Clone();
is more obvious than:
MyClassA a = new MyClass();
MyClassA aCopy = new MyClassA(a);
-Phil
|
|
|
|
|
Hello everyone!
Hey, so I need to use System.Net.Sockets.Socket.BeginAccept() , but I'm forced to use System.AsyncCallback to pass a callback function... What if I want to use my own event instead? How can I do that? Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
Can someone explain why numbers are being dropped off in this regular expression replace statement??
string phone = "1012345678912345";<br />
string newphone = Regex.Replace(phone, @"^((?<country>[1])([ ]|.|-))(\(|\[)?(?<area>\d{3})(\)[ ]?|\][ ]?|.|-)?(?<prefix>\d{3})(.|-|[ ])?(?<suffix>\d{4})[ ]?(x|X|#|.)?(?<ext>\d{0,5})$", "${country} (${area}) ${prefix}-${suffix} #${ext}"); <br />
<br />
newphone = newphone.TrimEnd('#');<br />
newphone = newphone.Trim();<br />
<br />
Console.WriteLine(newphone);<br />
The output is: 1 (123) 567-9123 #5
What it should be is 1 (012) 345-6789 #12345
Why is a number being removed between each storage area??? Thanks for your help.
|
|
|
|
|
How is this working at all? I tested the Regular Expression and am getting a grouping error.
|
|
|
|
|
For some reason it cut out a lot of it....
I'll try it again.
string newphone = Regex.Replace(phone,
@"^((?<country>[1])([ ]|.|-))(\(|\[)?(?<area>\d{3})(\)[ ]?|\][ ]?|.|-)?(?<prefix>\d{3})(.|-|" +
"[ ])?(?<suffix>\d{4})[ ]?(x|X|#|.)?(?<ext>\d{0,5})$",
"${country} (${area}) ${prefix}-${suffix} #${ext}");
Well i can't get it to use the entire expression for some reason... it cuts out prefix and suffix when trying to post as well as a a few things within the expression.
|
|
|
|
|
check the "ignore HTML tags" checkbox.
|
|
|
|
|
Well just in case anyone wants to see it, or use it in the future here it is... Thanks again ed...
<code>
string phone = "1012345678912345";
string newphone = Regex.Replace(phone, @"^((?<country>[1])([ ]|\.|-)?)(\(|\[)?(?<area>\d{3})(\)[ ]?|\][ ]?|\.|-|[ ])?(?<prefix>\d{3})(\.|-|[ ])?(?<suffix>\d{4})[ ]?(x| #|\.)?(?<ext>\d{0,5})$", "${country} (${area}) ${prefix}-${suffix} #${ext}");
newphone = newphone.TrimEnd('#');
newphone = newphone.Trim();
Console.WriteLine(newphone);
</code>
|
|
|
|
|
Excellent routine. It will definitely come in handy.
Thanks,
Ed
|
|
|
|
|
At first glance, I would guess you would have to qualify the periods with \
|
|
|
|
|
Hey perfect that was it... Thanks a lot for your help... I completely forgot periods meant any single character.. stupid me...
|
|
|
|
|
Hi,
I'm still new to C# so please bear with me.
I am trying to write a windows program, and am struggling to find info for the following things :-
1. How to get an event to trigger when the user clicks the mouse button anywhere on the window. I would like a container thats will contain grahics in the end. But when the user clicks the button I would like to get the Co-ors (X/Y) for where the user clicked.
2. I would like to show a flashing icon on the screen at particular X/Y co-ords, then when the Co-Ords have changed it will update and flash in a different place. I would like to have multiple flashes. Be able to add and remove the flashes. I am assuming I would need to create a new class for this object??
Any help or points to articles would be greatly appreciated.
Regards
Tony
|
|
|
|
|
Nooie wrote: But when the user clicks the button I would like to get the Co-ors (X/Y) for where the user clicked.
Look at the MouseClick event of the control, e.g. a Form or a Panel control. The e parameter contains e.X and e.Y
Nooie wrote: 2. I would like to show a flashing icon on the screen at particular X/Y co-ords
Why not drop a picture box where you want to paint the control? Or just paint directly to the control (look at the paint event) and make it flash using a timer. Many articles in this[^] section will show you how to paint to a control.
Hope that's of use.
|
|
|
|
|
Hi Chris,
Sorry I thought I had replied. I've had a good play with what you suggested and its getting better.
Thats what experience is all about, which is what I get from playing.
Again many thanks for your reply.
Tony
|
|
|
|
|
Hi!
I'm experiencing serialization problems with the .NET XML Serializer on a dictionary datatype:
8<===================================================
...
[Serializable]
public class StringPair
{
public StringPair()
{
m_Key = null; m_Value = null;
}
public StringPair(string p_Key, string p_Value)
{
m_Key = p_Key; m_Value = p_Value;
}
[XmlAttribute("Key")]
public string Key
{
get { return m_Key; }
set { m_Key = value; }
}
[XmlAttribute("Value")]
public string Value
{
get { return m_Value; }
set { m_Value = value; }
}
private string m_Key;
private string m_Value;
}
[Serializable]
public class StringsTable : Dictionary<string, string>, ISerializable, IDeserializationCallback
{
private SerializationInfo _savedSI;
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
string[] keys = new string[Count];
string[] values = new string[Count];
int i = 0;
foreach (string l_Key in Keys)
{
keys[i] = l_Key;
values[i] = this[l_Key];
++i;
}
info.AddValue("Keys", keys);
info.AddValue("Values", values);
}
public StringsTable()
{
}
protected StringsTable(SerializationInfo info, StreamingContext context)
{
_savedSI = info;
}
void IDeserializationCallback.OnDeserialization(Object sender)
{
string[] keys = (string[])_savedSI.GetValue("Keys", typeof(string[]));
string[] values = (string[])_savedSI.GetValue("Values", typeof(string[]));
for (Int32 i = 0; i < keys.Length; ++i)
Add(keys[i], values[i]);
_savedSI = null;
}
}
[Serializable]
public class Instance
{
public Instance()
{
m_Vars = new StringsTable();
}
[XmlElement("VariableAssignments"]
public StringsTable Variables
{
get
{
return m_Variables;
}
set
{
m_Variables = value;
}
}
private StringsTable m_Vars;
}
...
8<===================================================
This code compiles without any hassles in Visual C# Express 2005. When Serializing an "Instance" object, I always get an InvalidOperationException telling me that "There was an error reflecting type 'Instance'".
What's wrong with my de-/serializatoin?
Thanks in advance,
Rainer
|
|
|
|
|
I need urgent help.
here is my problem.
for the first 2 columns i fetched records from back end through sql query
GroupCode Plan
1 H1
1 H2
3 F1
4 D1
1 H3
4 D2
3 F2
3 F3
I have to add one more column manually
I would like to display
GroupCode Plan Order
1 H1 1
1 H22 2
3 F1 1
4 D1 1
1 H43 3
4 D2 2
3 F55 2
3 F41 3
How do we do it in c#.
Thanks
|
|
|
|