|
Thanks. But this way I'll be creating a new Form eacht time the GetForm function is called, while all I really want is a reference to an existing instance of the form if it exists, or a reference to a new instance if it doesn't. This works. The real problem for me is that the pool is serializable: Some basic data (location, position) can be stored and retrieved from a file. I save the info when the application is exited. When I start it up I want it to reconstruct each instance using its respective constructor...
Standards are great! Everybody should have one!
|
|
|
|
|
No, you won't be creating a new Form each time. It was just an example,
you can replace:
pool.Add("myformid", new LoginForm());
pool.Add("myAboutformid", new AboutForm());
as
pool.Add("myformid", myAlreadyCreatedLoginForm);
pool.Add("myAboutformid", myAlreadyCreatedAboutForm());
also:
GetForm(...) code I sent you does not create anything. Do you see any "new" keyword in the code/or am I blind?
Result:
- You have an assembly created in you bin\debug folder in which your Forms are also embedded. This is your store to create the Forms at run-time. You want to store some configuration related to your forms, so what you need is to store this configuration like size and location somewhere like an xml file. If you've done it(you've written Some basic data(location, position) can be retrieved from a file), then you want to get a Form from the pool. Then your pool is the one which is responsible of returning an instance of the Form type if there is already one, created in pre-call to GetForm(...) or you want to create a new instance with the configuration parameters stored using reflection. If this is what you want:
// The configurtation of the Form you serialize/deserialize
public class FormConfig : ConfigurationProperty /*or string, or xml file, or whatever you want */
{
}
public T GetForm<t>(string form_id) where T: Form
{
if(pool.ContainsKey(form_id))
{
return pool[form_id] as T;
}
else
{
// you may have a look at other overloaded method(s) of Activator.CreateInstance
return Activator.CreateInstance(T, new object[]{GetConfig(typeof(mySerializedForm))}) as T;
}
}
public FormConfig GetConfig(string key)
{
return ..... // return the deserialized config
}
public FormConfig GetConfig(Type key)
{
return ..... // return the deserialized config
}
"Peace at home, peace in the world"
Mustafa Kemal Atatürk(the founder of the Republic of Turkey and its first President.))
|
|
|
|
|
Hmm, I think I might have been having a bit of an off day in explaining what I was aiming for, but you guessed about right the second time. This line of code was close enough to what I was looking for:
return Activator.CreateInstance(T, new object[]{GetConfig(typeof(mySerializedForm))}) as T;
I've just been staring at the same CreateInstance method without ever realizing there's a bunch of overloads to choose from. Thanks very much for the help .
Standards are great! Everybody should have one!
|
|
|
|
|
If I could help you then I'm glad to win a coder's heart
|
|
|
|
|
Hi all,
I need help regarding how to communicate with OPCServer. i am developing application in C#. In project Reference i added OPCAutomation 2.0(COM) . I am adding the code which i done .
OPCServer MyServer = null;
OPCGroups MyOPCGroups = null;
OPCGroup MYOPCGroup = null;
MyServer = new OPCServer();
MyServer.Connect(ProgID,NODE);
// till here ok
MyOPCGroups =(OPCGroups) MyServer.OPCGroups;
// but when i tried to create the OPCGroups i am getting casting error //saying that " OPCAutmation.OPCServerClass to type OPCAutomation.IOPCGroup"
MYOPCGroup = (OPCGroup)MyOPCGroups.Add("MyGroup");
any help is appreciated
Regards,
Kotha.
|
|
|
|
|
Hi!
I have the same problem
Were you able to solve it?
Would be glad for any help...
Regards,
Alessandro
|
|
|
|
|
Hi.
I want to develope an application that this application will be installed on computers of a LAN.
Now I want the DataBase(Access , SQL Server) of these applications be one and on one of the computers(Server).
i.e. I want the DB be shared between these applications.
Best wishes
|
|
|
|
|
So make the connection string of the app point to the one DB, on the LAN.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
And if in same time 2 want to update one table what happens?
Best wishes
|
|
|
|
|
mehrdadc48 wrote: if in same time 2 want to update one table what happens?
SQL Server is a highly scalable multi user database system. You get versions from Express upto Enterprise which can handle thousands of users simultaneously. The database engine deals with it - that's what its good at.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
You have a few choices, you can have it as last one to update wins, you could put in a check to see if the record has been updated since the last read (sql server provides the TIMESTAMP column type for this).
You could create some sort of checkout/checkin/lock system.
It all depends on what the app is for and how it will be used. This issue is called concurrency if you want to do some searching on the subject. I personally tend towards optimistic concurrency, but that is what normally suits my apps.
|
|
|
|
|
How do I make a window application run on a network
|
|
|
|
|
What do you mean by 'run on a network' ? It will access files on the network, just pass network paths to it. You can run it over a network, point to the exe over the network. How else do you mean ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I have a various tables which gets activated as a user selects an option.I want to poulate the results in a datatable and check they are not duplicate data from each table.My datatable should contain a dataonly once no duplicates.
How do i go about that?
Is there a function that checks the data before writing it to datatable so that it cant duplicate?
Please advice
Thanks and regards
|
|
|
|
|
Not really, your database should have keys set so that it won't accept duplicates. The other way is to write a select to see if the data exists. Finally, you can insert with a stored proc that first checks if the data exists, and only inserts if it doesn't.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Every table must have primary key and the Domain of each column must matches with one another to get the correct type of data in a column of the datatable.Load 1st row from i(Option selected) table to common datatable, check whether that rows is exists in common datatble,if it is then dont add the row else add them and proceed further with next row in i table.
Regards
Chintan
www.visharadsoft.com
(Nothing is so purify as KNOWLEDGE)
|
|
|
|
|
THANK YOU ALL YOUR HELP IS VERY GREAT.
|
|
|
|
|
Have a look at DataColumn.Unique property.
|
|
|
|
|
Kindly link me anyone who have successfully deployed a windows based application with crystal report, using C#.Net 2005. B'cos am bug with deployment issue on crystal report.
|
|
|
|
|
Describe your bug with the deployment and someone might be able to help.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
hi
the application is written in .net compact framework 1.0.
i need to display a list of items with different forecolor for each item. the items get added to the list from a file. i have two problems:
1. the items get added but i get a horizontal scrollbar by default. i just want them too be added to the end like that in a listbox.
2. how do i set the forecolor of individual items?
thanks.
|
|
|
|
|
i got the way to get view the items in a list with vertical scrollbar but the second problem still remains...
does anyone have any suggestions???
thanks.
|
|
|
|
|
For each item in listview you have to set the color like
this.listView1.Items[0].ForeColor = System.Drawing.Color.Red;
this.listView1.Items[0].ForeColor = System.Drawing.Color.Blue;
|
|
|
|
|
hi
How can i build colourful context menu for notification icon(System Tray Icon). Plz share any idea with u. I am getting sooo trouble on it
thanks
evilinside
|
|
|
|
|
You are going to have to read up on custom controls.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|