|
Ok. Thank you very much for the help. I am new to C# so tips are very helpfull.
Albert
|
|
|
|
|
I tried to override ToString but it doesn't see label1 in this function. Do you know why? Also I remove the clas Athlete from the program there is only person class, and the form.
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
}
public class Person
{
public Person(int age, double height, double weight, string bankName, double bankAccount, double balance)
{
this.age = age;
this.height = height;
this.weight = weight;
this.bankName = bankName;
this.bankAccount = bankAccount;
this.balance = balance;
}
public override string ToString()
{
Person[] person = new Person[3];
person[0] = new Person();
person[0].Age = 22;
label1. -////// no properties shown
return "";
}
}
-- modified at 22:48 Wednesday 25th January, 2006
|
|
|
|
|
You just want ToString to return a string for that current element. You don't want it to create an array or anything like that.
I've modified your code as an example:
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
Person[] arr = new Person[2];
arr[0] = new Person(12, 3.3, 3.3, "test", 3.3, 3.3);
arr[1] = new Person(15, 3.3, 3.3, "test", 3.3, 3.3);
this.label1.Text = "";
for (int i = 0; i < arr.Length; i++)
{
this.label1.Text += arr[i].ToString();
}
}
}
public class Person
{
public int age;
public double height;
public double weight;
public string bankName;
public double bankAccount;
public double balance;
public Person(int age, double height, double weight, string bankName, double bankAccount, double balance)
{
this.age = age;
this.height = height;
this.weight = weight;
this.bankName = bankName;
this.bankAccount = bankAccount;
this.balance = balance;
}
public override string ToString()
{
return this.Age;
}
}
|
|
|
|
|
Great!!! Thank you very much Garry. Now it works just as needed. Thanks for all the help.
Albert
|
|
|
|
|
Hello, HOw do you write a c# program to copy 2 files from one directory to another? I am going to have the files in the same directory as the program. Thanks in advance
|
|
|
|
|
You might want to look into the File.Copy[^] method.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
iam developing chat server /Client architecture and it works very very well on my localhost and even in Lan in cyber of internet . But it doesn't work on the internet i need to connect to someone running my server through knowing his ipaddress and the port my server listening on ?
Please solve this problem with me.
Mess With The Best And Die Like The Rest
|
|
|
|
|
Actually, your problem most likely has nothing to do with your code, but the setup of port forwarding on the your router on the server side. If you have a router anyway. I would suggest digging up the manual on whatever router/firewall/NAT thingy your using and looking up port forwarding.
Basically, you have to have the server on a static IP on the inside of your router. Then configure port forwarding to send packets destined for your server's chat server port on your Internet IP to the inside network IP and port.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
As the first poster mentioned, you'll need to configure any local routing infrastructure to allow inbound traffic, but you will also have to consider inbound/outbound traffic from your ISP's point of view.
Make sure that their hardware doesn't block the ports you are trying to use, and maybe check up to see if they have an isolated "proxy only" environment or something similar. This is when the only outbound connection you are allowed to make is through a proxy server, in which case you may have to to detect you default proxy of your machine (System.Net.WebProxy.GetDefaultProxy()), or create your own proxy object and wrap the packets you're sending out in an HTTP request. Most IRC clients and servers will now send and accept HTTP encapsulated data in this manner. Not sure about other protocols, though.
|
|
|
|
|
I'm a fairly new C# programmer, and not sure how to phrase this question. Perhaps you could point me to a project on this site that'll be close to what I'm looking for. here goes:
I would like to have codefiles (as part of a class or not) that are indicated to a main program by their filepath. Somewhat like how files and functions work in Matlab. For example, let's say I know for a particular condition (True/False) a user of my program will have to write their own C# boolean function. Since this function is to be stored in a separate codefile from the project/solution, my main program will find it by reading in an input XML file from the user. could the code be in the XML? if not, how could I read in their c# file and compile it with the main project at runtime.
Thanks in advance,
Matt
|
|
|
|
|
Hello my friend.
Try to look at System.Xml Namespace it has a full set of classes to manupilate any xml or schema file on this planet.
try first to load the xml file using
<br />
XmlDocument myxmlfile = new XmlDocument("the path for your file");<br />
<br />
//if you need the Help on these classes try searching msdn
http://msdn.microsoft.com
Mess With The Best And Die Like The Rest
|
|
|
|
|
well, there may be something there in the XML class but I don't think so. I use the XML namespace quite a bit, but this is different. I wanna say it's like stored procedures or compiling at runtime but I need some examples that are close.
What I'm actually writing is an optimization program (ala genetic algorithm) and I don't know what the user's objective function or constraints are, but I want him/her to indicate them to the program by the filepath of the custom C# files written by the user. These user functions will be called a lot so I don't want to continue reading it in each time I need to invoke it.
Any ideas?
Matt
|
|
|
|
|
Look at the Reflection name space (and the various load functions available from the Assembly class - at least I think it is on the assembly class, haven't used them for the last year or something like that).
These allows you to load a compiled DLL, find a method, and then call it.
Alternatively simply compile the C# program to an assembly, then call it though reflection (I can't remember the class name, but the C# compiler is available in the framework). Notice that you might have to think a bit about how to handle dependencies this way - after all, the C# code provided might use a DLL you did not anticipate.
|
|
|
|
|
Hi,
I am tryin to simulate a key sequence in a windows form ,I can simulate ctrl + c but I am tryin to simulate a break sequence which is ctrl + pause/break thats where I'm drawing a blank.
any suggestions will be appreciated
|
|
|
|
|
Is there a way to keep the text of a label from wrapping to the next line if it is too long. I would like to just have the text disappear at the end of the label. In other words force it to be only one line and if it doesn't fit, too bad.
Thanks for any suggestions.
Brent
Brent
|
|
|
|
|
Try to use TextBox .The TextBox Control has WordWrap property that can help in your case ...
DevIntelligence.com - My blog for .Net Developers
|
|
|
|
|
Hi!
you can try to override the OnPaint and use the DrawString method of the graphics parameter to redraw the text on your label.
hope that helps!
|
|
|
|
|
If you only need a single line of text/label, you can reduce them to minimum height.
|
|
|
|
|
This was good enough... Changing the TextAlign property to TopLeft and setting the height small enough to not show the next line worked for what I need it for.
Using text boxes just doesn't work and look the same as using labels. And I don't have the time to create my own custom controls right now.
Thanks
Brent
|
|
|
|
|
public class NewMonitorDetails<br />
{<br />
<br />
public static int MonNumber;<br />
public static string EDID_Info; <br />
<br />
public NewMonitorDetails(){}<br />
}
I have the above class...I want to create an array of the above class to store different values in MonNumber and EDID_Info, so that I can access those values in other calsses where ever I want.
How do I do this. Thanks.
|
|
|
|
|
Manu_81 wrote: I want to create an array of the above class to store different values in MonNumber and EDID_Info, so that I can access those values in other calsses where ever I want
First, if you declare the fields as static you will only get one for all instances of the class. So, if you want to create multiple instances of the class you cannot create these as static for the purpose you want.
Second, declaring a field as public is bad form. You should declare them as private or protected and access them through properties. Read this article if you want to know why you should make the fields private and access them through a public property[^]
Finally, you can make the array global by adding it as a static field to the class (because you only want one instance of the array made available globally across your application (right?)
So your class will look something like this:
public class NewMonitorDetails
{
private static ArrayList newMonitorDetailsArray = new ArrayList();
private int monNumber;
private string edid_Info;
public NewMonitorDetails()
{
}
public int MonNumber
{
get { return this.monNumber; }
set { this.monNumber = value; }
}
public string EDID_Info
{
get { return this.edid_Info; }
set { this.edid_Info = value; }
}
public static ArrayList NewMonitorDetailsArray
{
get { return NewMonitorDetails.newMonitorDetailsArray; }
}
}
Does this help?
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
-- modified at 4:19 Tuesday 24th January, 2006
|
|
|
|
|
Thanks a lot for your reply Colin. Its really helpful as I am new to obj. oriented...
Got what you r saying.
Now how do I set and retrieve values to this class.
What I am doing exactly is I get the Monitor number and EDID info for each active Monitors connected from dll. So I want store this pair of values for each monitors in some global data structure so that I can use it where ever I want in my app...
Thanks again.
|
|
|
|
|
Manu_81 wrote: Now how do I set and retrieve values to this class.
Through the properties. In C# this looks just the same as getting and setting the field (although the compiled MSIL is different, but you don't need to worry about that). For example:
myMonitor.MonNumber = 2;
myMonitor.EDID_Info = "Some Info";
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
Also, I just double checked the code. The NewMonitorDetailsArray property should have been static - so I've corrected that (see updated previous post)
You can access the ArrayList of all NewMonitorDetails by using
NewMonitorDetails.NewMonitorDetailsArray
You cannot set this as it is controlled by the class. But you can perform any methods on the ArrayList (like Add ) so you can modify the contents of the array.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
If you wan't to store any data in the objects, you have to have any non-static members. If you create an object from that class, the object will contain no data what so ever.
If you create an array, you can access it from where ever you like, as long as you have a reference to it. How to best handle that reference is hard to say, as you have given so very little information on what you are trying to accomplish.
---
b { font-weight: normal; }
|
|
|
|