|
Stephane David wrote:
class CPoint<br />
{<br />
int X;<br />
int Y;<br />
}
First: This little class is unneeded; check out System.Drawing.Point .
Second: You then need to mark your classes with Serializable attributes.
[Serializable(true)]
class CShape
{
string name;
virtual void Draw();
}
[Serializable(true)]
class CCircle : CShape
{
int Radius;
CPoint center;
override void Draw();
}
[Serializable(true)]
class CPolygon : CShape
{
CPoint[] geometry;
override void Draw();
}
[Serializable(true)]
class CDrawing
{
public CShape[] shapes;
}
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
void SaveToFile(string path,CDrawing drawing)
{
using(FileStream fs = File.OpenWrite(path))
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs,drawing);
}
}
CDrawing LoadFromFile(string path)
{
using(FileStream fs = File.OpenRead(path))
{
BinaryFormatter bf = new BinaryFormatter();
return (CDrawing)bf.Deserialize(fs);
}
}
Hope this gets you on your way...
-Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
The actual name of classes were just illustration, ht class architecture is muh more complex. I'll try what you say. It was what I read in the documentation, but I was doubtfull it would actually save an array of derived classes as the shapes member in my CDrawing class.
|
|
|
|
|
Does anyone know if it is possible to store an a class in Message queue body as an object? If so, is there a special type of formatter I need to use? Thanks for all the help.
|
|
|
|
|
hi all, I'm newbies please help me solve this problem with C#
My project windowForm like Chat Program, but when I append text into Richtextbox (ScrollBars: ForcedVertical), it don't autoscroll to see last text I was append
someone help me, please. Thanks
Nho'c ti`
|
|
|
|
|
Do this every time you append text:
rtb.SelectionStart=rtb.TextLength;
rtb.ScrollToCaret();
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
but It doesn't run, and here is mycode (RichTextBox rtbMessage, TextBox tbInput)
private void tbInput_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode==System.Windows.Forms.Keys.Enter)
{
if (tbInput.Text.Length>0)
{
rtbMessage.AppendText("myID : "+tbInput.Text+"\n");
rtbMessage.SelectionStart = rtbMessage.TextLength;
rtbMessage.ScrollToCaret();
this.tbInput.Text = "";
}
}
}
some one can write somecode
thanks
Nho'c ti`
|
|
|
|
|
What's the error that makes it not run?
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
"it not run" like that richtextbox doesn't autoscroll when I appendtext to it (with your code) )
Nho'c ti`
|
|
|
|
|
you need to set HideSelection to "FALSE"
in .net / C# the richtextbox doesnt move down to show the most recent text unless you set it's hideselection property to false .
Vb:
<font color="blue">Public Function</font> TwinsOnWay(<font color="blue">ByVal</font> twins <font color="blue">As String</font>) <font color="blue">As String <br> Select Case</font> twins<br> <font color="blue">Case</font> "Gender" <br> <font color="blue">Return</font> "Two Girls" <br> <font color="blue">End Select <br> End Function</font> <br>
|
|
|
|
|
Now I remember. Thanks for pointing this out. I remember a while back I was stumped by this, and when I found out, I was a bit irritated that they did it that way.
Thanks.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
np i've been making irc clients for longer than i can remember and it was the first problem i came across in .net
Vb:
<font color="blue">Public Function</font> TwinsOnWay(<font color="blue">ByVal</font> twins <font color="blue">As String</font>) <font color="blue">As String <br> Select Case</font> twins<br> <font color="blue">Case</font> "Gender" <br> <font color="blue">Return</font> "Two Girls" <br> <font color="blue">End Select <br> End Function</font> <br>
|
|
|
|
|
Thank you very much !!!
Nho'c ti`
|
|
|
|
|
Does anybody know how I could get a current property value from a loaded process? What I am trying to do is to have a user log-in in a main application, which would initialize a user object containing all the neccessary information about a user, and then every other application openned afterword, while the main application is still open, would use the same user object that was initialized in the main application. This would save the user from having to log-in again, it would save having to make unneeded trips to a remote database, plus it would save having a database connection for every application that is openned. Any suggestions or comments would be greatly appreciated. Thanks
|
|
|
|
|
What happens if you put it into a class library module and then reference that module in your different programs / segements?
I have a program that maintains a form of program state in via an external (seperate project) class (with static members and properties). It is referenced and initialized in the main program which keeps a hold in it while all the other modules reference the DLL and have access to the data.
The only data I think you would have to worry about is process or thread specific data. Other than that it seems to work fine.
Rocky Moore <><
|
|
|
|
|
I have the user object in a class library and it is referenced by my other programs. I didn't think about making all the methods static but I think I would prefer to keep it as an instance class. I just need to know how to get an instance of that class from my main application when it is already an active process. Any other ideas?
Shaun
|
|
|
|
|
Shaun Becker wrote:
I just need to know how to get an instance of that class
That is the reason for the static. You can add a class with a static property that you assign the instance of the class you want to use. This is what I do with my Data Abstraction classes. I have a class that has memebers which are static but the values in this are static. The instance of the class you wish to use is available to all other modules.
Rocky Moore <><
|
|
|
|
|
I tried that and it didn't work for me, unless I did something wrong. I had a class library with two classes. The first class just held a static reference to an instance of the second class. Then I had two applications that referenced the class library. Each program checked the first class to see if the static reference was already set. If it wasn't set, it sets the reference to a new instance of the second class. If it was set, it displays the contents of the second class. The class was only static for each application process and not cross-process.
Hopefully I am explaining what I am trying to do correctly. I am writing a logistics application suite. It will have a main program, a maintenance program, an order entry program, and an admin program. The main program will just control security while all other application are running. Whenever any of the other programs start up, first it is going to check if there is already an instance of the application running using System.Diagnostics.Process.GetProcessesByName(). If there is then it will just activate that instance. If there isn't then it will then check if there is an instance of the main application using System.Diagnostics.Process.GetProcessesByName(). If there is an instance of the main application, then it will just get a reference to the user object from the main program. If there isn't an instance of the main application, then it will create a new process of the main application with System.Diagnostics.Process.Start(), which will require the user to log in and that will intialize the user object. Then the executing program will get a reference to the user object from the main program that was just started. I hope this explains everything I am trying to do. If you have any suggestions on how to do this or of a better way to reach the desired outcome, I would greatly appreciate it. Thanks
Shaun
|
|
|
|
|
Do you happen to have all the exe's and dll's in the same directory?
Rocky Moore <><
|
|
|
|
|
Yes, they are built to common bin directory.
Shaun
|
|
|
|
|
Is there a non-threaded class that's like System.Net.WebRequest? When I use WebRequest/WebResponse in a thread pool, I sometimes notice, under heavy load situations, that WebRequest/WebResponse seems to use a threadpool for its implementation.
Actually, I may be wrong, and that only WebClient happens to use the asynchronous version of WebRequest/WebResponse, which is annoying when my threadpool is full, and WebRequest/WebResponse can't run asynchronously, so WebClient bombs.
But if I have to use WebRequest/WebResponse, no biggie.
|
|
|
|
|
Argh. Reflector confirms what I suspected, that WebClient and WebRequest.GetResponse() both depend on WebRequest.BeginGetResponse(), which requires at least two free threads in the system threadpool.
That's pretty annoying. But not as annoying as how WebClient and WebRequest/WebResponse don't have a satisfactory overlap in power. WebClient makes certain common things easy, like POSTing data. WebRequest/WebResponse allow for certain things like changing the TransferEncoding or setting timeouts, but then I have to write my own UploadValues() for WebResponse, and all of the URL encoding functions are private. Useless!
|
|
|
|
|
hello,
i want to create a dialoge box and then dispose or close it, how can i do this in c#? can i?
ASIM
Asim
|
|
|
|
|
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace SolidAvatar
{
public class Form2 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button cmdOK;
private System.Windows.Forms.Button cmdCancel;
private System.ComponentModel.Container components = null;
public static DialogResult DoShowDialog(IWin32Window owner)
{
Form2 myForm = new Form2 ();
return myForm.ShowDialog (owner);
}
private Form2()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
if(components != null)
components.Dispose();
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.cmdOK = new System.Windows.Forms.Button();
this.cmdCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
this.cmdOK.DialogResult =
System.Windows.Forms.DialogResult.OK;
this.cmdOK.Location = new System.Drawing.Point(112, 200);
this.cmdOK.Name = "cmdOK";
this.cmdOK.TabIndex = 0;
this.cmdOK.Text = "OK";
this.cmdCancel.DialogResult =
System.Windows.Forms.DialogResult.Cancel;
this.cmdCancel.Location = new System.Drawing.Point(208, 200);
this.cmdCancel.Name = "cmdCancel";
this.cmdCancel.TabIndex = 1;
this.cmdCancel.Text = "Cancel";
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.cmdCancel, this.cmdOK});
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false);
}
}
}
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
If you just want to display a message, use
MessageBox.Show("message", "heading").
-or-
Create the form and call it using ShowDialog() instead of Show().
You can have the form return you Yes or No (or Cancel) by setting a value like
like
this.DialogResult = DialogResult.OK
And then the form that called it can retrieve it by:
if(myDialogBox.DialogResult == DialogResult.OK)
{
//code here to act on that.
}
hope that helps
|
|
|
|
|
In C++ the OnIdle() function is available from CView. How can I gain access to it in C# for a Windows based application. A simple application with one form.
thanks
|
|
|
|