|
Code you gave doesn't tell much, for example I don't see any relation with UserControl and Student class. It could be possible that you initialize student class in Control constructor (use Load event instead and use if (!DesignMode) { <initialization code=""> }), or that you have two Student classes...
So please provide more code (like complete definition of both classes).
P.
|
|
|
|
|
Hello,
I've got a singleton Settings Class and implemented the Serialization. I can write the object to a file, read the object from file. this all works rather well except for the tiny inconvieniance that i have to create a new instance of my settings class, while i would like to read the file to the already excisting Settings.Instance.
in short..
i have a Singleton class that has methods for writing itself to disk (settings.set)
// [Serializable] public sealed class Settings : ISerializable
is there a elegant way for this class to read itself from disk.
my complete code so far. (not yet polished)
<br />
[Serializable] public sealed class Settings : ISerializable<br />
{<br />
Logging logevent = Logging.Instance;<br />
<br />
string logFilePath = "";<br />
<br />
public string LogFilePath {<br />
get { return logFilePath; }<br />
set { logFilePath = value; }<br />
}<br />
string logFileName = "";<br />
<br />
public string LogFileName {<br />
get { return logFileName; }<br />
set { logFileName = value; }<br />
}<br />
string language = "";<br />
<br />
public string Language {<br />
get { return language; }<br />
set { language = value; }<br />
}<br />
<br />
SerializationInfo info;<br />
StreamingContext context;<br />
<br />
private static Settings instance = new Settings();<br />
<br />
public static Settings Instance {<br />
get {<br />
return instance;<br />
}<br />
}<br />
<br />
private Settings()<br />
{<br />
}<br />
<br />
#region Serialization methods<br />
private Settings(SerializationInfo info, StreamingContext context)<br />
{<br />
<br />
this.logFilePath = (string)info.GetValue("logFilePath", typeof(string));<br />
this.logFileName = (string)info.GetValue("logFileName", typeof(string));<br />
this.language = (string)info.GetValue("language", typeof(string));<br />
}<br />
<br />
public void GetObjectData(SerializationInfo info, StreamingContext context)<br />
{<br />
this.info = info;<br />
this.context = context;<br />
<br />
info.AddValue("logFilePath", this.logFilePath);<br />
info.AddValue("logFileName", this.logFileName);<br />
info.AddValue("language", this.language);<br />
}<br />
#endregion<br />
<br />
#region Reading and Writing Settings object to file stream.<br />
public void ReadFromFile()<br />
{<br />
ReadFromFile(System.Windows.Forms.Application.StartupPath);<br />
}<br />
<br />
public void ReadFromFile(string path)<br />
{<br />
string SettingsFile = path + "\\settings.set";<br />
if (File.Exists(SettingsFile))<br />
{<br />
System.Console.WriteLine(SettingsFile);<br />
<br />
Stream stream = File.Open(SettingsFile, FileMode.Open);<br />
BinaryFormatter bformatter = new BinaryFormatter();<br />
<br />
Settings tmp = Settings.Instance;<br />
<br />
try <br />
{<br />
tmp = (Settings)bformatter.Deserialize(stream);<br />
}<br />
catch (SerializationException ex) <br />
{<br />
logevent.write("Class Settings 'ReadFromFile' - error : " + ex.Message);<br />
throw;<br />
}<br />
finally <br />
{<br />
stream.Close();<br />
}<br />
stream.Close();<br />
}<br />
}<br />
<br />
public void WriteToFile()<br />
{<br />
WriteToFile(System.Windows.Forms.Application.StartupPath);<br />
}<br />
<br />
public void WriteToFile(string path)<br />
{<br />
string test = path + "\\settings.set";<br />
<br />
Stream stream = File.Open(test, FileMode.Create);<br />
BinaryFormatter bformatter = new BinaryFormatter();<br />
<br />
Settings tmp = Settings.Instance;<br />
<br />
try <br />
{<br />
bformatter.Serialize(stream, tmp);<br />
}<br />
catch (SerializationException ex) <br />
{<br />
logevent.write("Class Settings 'WriteToFile' - error : " + ex.Message);<br />
throw;<br />
}<br />
finally <br />
{<br />
stream.Close();<br />
}<br />
}<br />
#endregion<br />
}<br />
Ludo Stroetenga
|
|
|
|
|
Hi!
I've got an issue with RichTextBox. I'm formatting the text inside, indents, colours, font attributes etc. When I insert the text from the same control - it's ok. But when I do it from another one - my RTB blinks, as if repainting its contents. I've tried to change my text formatting, checked which events were fired and nothing.
Any help from you?
Thanx in advance.
|
|
|
|
|
Hi!
What do you mean by
the_yeast wrote: insert the text from the same control
Without any code it's very hard to help you.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
hi...
SendKeys() is not working for the windows logo key(start menu key)...there is no code for these keys in that function....any solution??
Im a C# beginner...
|
|
|
|
|
Hi!
You can let the start menu pop up by pressing Ctrl+ESC as well, so perhaps you can use ^{Escape} for your SendKey call.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
that one worked.thank you mav
regards,
vivek
In the depths of C#...
|
|
|
|
|
I want to synchronize my system clock wiht the NIST standard in coding.
Is there any provision for this?
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
Not built in, but there's at least one CP article on NIST servers in C#.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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 want to know whether it can be done using C# windows service.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
OK, then I suggest you read that article.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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 )
|
|
|
|
|
CAn you give the link.
In tha mean while I will also try to get it.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
Just type NIST C# into the search box, I had bookmarked the link, but I lost it waiting for the page to load, sorry.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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 )
|
|
|
|
|
|
http://www.codeguru.com/csharp/csharp/cs_date_time/timeroutines/article.php/c4207/
|
|
|
|
|
Thank you thanks a lot I got it and i have gone through it I got the logic also
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
in that they have specified NTPClient what is it?
Is it a built in class or else created by the user.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
Hi Every one ....
I want to develope a "windows application" with openfile dailog and save filedialog
in c#
Plz help me ...
Iam new to dotnet ...
help me with examples
Thanks inadvance
naresh.s.s
|
|
|
|
|
The classes are OpenFileDialog and SaveFileDialog.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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 )
|
|
|
|
|
sssss
Ive done upto open dialog it will gies the path ...
but for the sae dialog am not getting the path there ....
and i cant able to save the file to desired forder ...
my code is .......
For Opendailog
OpenFileDialog fdlg = new OpenFileDialog();
SaveFileDialog dlg = new SaveFileDialog();
fdlg.Title = "Browse any file from here ";
fdlg.InitialDirectory = @"c:/Resume";
fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
fdlg.FilterIndex = 2;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
textBox1.Text = fdlg.FileName;
}
for Savedailog
saveFileDialog1.Title = "Specify Destination Filename";
saveFileDialog1.Filter = "Text Files|*.txt";
saveFileDialog1.OverwritePrompt = true;
saveFileDialog1.FilterIndex = 1;
if (saveFileDialog1.ShowDialog() != DialogResult.Cancel)
{
textBox1.Text = saveFileDialog1.FileName;
}
this is wat ive done till now ...
but iam not gettign the path there at textbox1 when iam going to save the file ...
Plz help me .....
bye
naresh.s.s
|
|
|
|
|
1. Create a object for the dialog control (OpenFileDialog or SaveFileDialog)or use the controls
2. Then you open the dialog with ShowDialog() method
3. You can use Filter property to set the patterns to be displaye For e.g (Text Files|*.txt|All Files|*.*"
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
sssss
Ive done upto open dialog it will gies the path ...
but for the sae dialog am not getting the path there ....
and i cant able to save the file to desired forder ...
my code is .......
For Opendailog
OpenFileDialog fdlg = new OpenFileDialog();
SaveFileDialog dlg = new SaveFileDialog();
fdlg.Title = "Browse any file from here ";
fdlg.InitialDirectory = @"c:/Resume";
fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
fdlg.FilterIndex = 2;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
textBox1.Text = fdlg.FileName;
}
for Savedailog
saveFileDialog1.Title = "Specify Destination Filename";
saveFileDialog1.Filter = "Text Files|*.txt";
saveFileDialog1.OverwritePrompt = true;
saveFileDialog1.FilterIndex = 1;
if (saveFileDialog1.ShowDialog() != DialogResult.Cancel)
{
textBox1.Text = saveFileDialog1.FileName;
}
this is wat ive done till now ...
but iam not gettign the path there at textbox1 when iam going to save the file ...
Plz help me .....
bye
naresh.s.s
|
|
|
|
|
can you tell then what does it show??
One thing I found in your code is that... your code for declaring SaveDialog object is
SaveFileDialog dlg = new SaveFileDialog();
where you are using ..
saveFileDialog1.Title = "Specify Destination Filename";
saveFileDialog1.Filter = "Text Files|*.txt";
saveFileDialog1.OverwritePrompt = true;
saveFileDialog1.FilterIndex = 1;
if (saveFileDialog1.ShowDialog() != DialogResult.Cancel)
{
textBox1.Text = saveFileDialog1.FileName;
}
....
it seems you are also using another Object of SaveFileDialog, that you added in your form from toolbox (as naming convention suggest)...
|
|
|
|
|
you can get all those this from .net itself.
make use of the toolbox
My small attempt...
|
|
|
|
|
I have a file C#(window form),its name Server,I use method bind and listent of class socket,but after I turn off the dialogue,I turn on the task manager,I see it is running
Why ?
please help me
help me
|
|
|
|