|
I want to close the Client Socket ....Not the Listner(Server) how u r handeling Client Socket and Socket.Connected returns the previous state
its me sid
|
|
|
|
|
Send me the Exception text on socket.close().
S.Akmal
|
|
|
|
|
static void Main()
{
Application.Run(new Form1());
}
private System.Windows.Forms.GroupBox grpbox;
XPathDocument dom;
XmlDocument doc;
XPathNavigator nav;
XPathExpression expr;
XPathNodeIterator iterator;
int cnt=0;
Label lbl;
TextBox txt;
OpenFileDialog dlg;
TreeNode newTreeNode,rootnode,parentnode;
string text;
int i;
//int cnt = e.Node.GetNodeCount(false);
//string filename;
private void Form1_Load(object sender, System.EventArgs e)
{
//label1.Text = "File Path";
//label1.SetBounds(8, 8, 50, 20);
//filename = Application.StartupPath + "\\Sample.xml";
//textBox1.Text= filename;
//textBox1.SetBounds(64, 8, 256, 20);
button1.Text = "Populate the TreeView with XML";
button1.SetBounds(8, 20, 200, 20);
treeXml.Height = 600;
treeXml.Width = 400;
grpbox = new GroupBox();
grpbox.Height = 600;
grpbox.Width = 400;
grpbox.SetBounds(500, 2, 700, 600);
grpbox.Visible = true;
grpbox.Dock.Equals(Right);
grpbox.Show();
this.Controls.Add(grpbox);
//dom = new XPathDocument(dlg.FileName);
}
// it will acess the xml file into treeview
private void ConvertXmlNodeToTreeNode(XmlNode xmlNode,
TreeNodeCollection treeNodes)
{
TreeNode newTreeNode = treeNodes.Add(xmlNode.Name);
switch (xmlNode.NodeType)
{
case XmlNodeType.ProcessingInstruction:
case XmlNodeType.XmlDeclaration:
newTreeNode.Text = "<?" + xmlNode.Name + " " +
xmlNode.Value + "?>";
break;
case XmlNodeType.Element:
if (xmlNode.Name.ToLower().Equals("node") == true)
{
newTreeNode.Text = "<" + xmlNode.Attributes["label"].Value.ToString() + ">";
}
else
newTreeNode.Text = "<" + xmlNode.Name + ">";
break;
case XmlNodeType.Attribute:
newTreeNode.Text = xmlNode.Name;
// newTreeNode.Text = "ATTRIBUTE: " + xmlNode.Name;
break;
case XmlNodeType.Text:
case XmlNodeType.CDATA:
newTreeNode.Text = xmlNode.Value;
break;
case XmlNodeType.Comment:
newTreeNode.Text = "<!--" + xmlNode.Value + "-->";
break;
}
if (xmlNode.Attributes != null)
{
foreach (XmlAttribute attribute in xmlNode.Attributes)
{
ConvertXmlNodeToTreeNode(attribute, newTreeNode.Nodes);
}
}
foreach (XmlNode childNode in xmlNode.ChildNodes)
{
ConvertXmlNodeToTreeNode(childNode, newTreeNode.Nodes);
}
}
// this is an event on which text box is created...
private void treeXml_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
cnt = e.Node.GetNodeCount(false);
grpbox.Controls.Clear();
for ( i = 0; i < cnt; i++)
{
Label lbl= new Label();
TextBox txt = new TextBox();
//lbl.Name="lbl"+i;
//lbl.Text="lbl"+i;
lbl.Text = e.Node.Text+i;
txt.Name="txt"+i;
txt.Text=txt.Name;
//txt.Text=e.Node.Text+i;
lbl.Left = 200;
lbl.Top = 200 * i;
txt.Left = 250;
txt.Top = 200 * i;
lbl.Show();
txt.Show();
grpbox.Controls.Add(txt);
grpbox.Controls.Add(lbl);
}
}
// this will open an6y xml file stored at your pc.
private void button1_Click(object sender, System.EventArgs e)
{
XmlDocument doc = new XmlDocument();
OpenFileDialog dlg = new OpenFileDialog();
treeXml.Nodes.Clear();
dlg.Title = "Open XML File";
dlg.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*" ;
if (dlg.ShowDialog() == DialogResult.OK)
{
//imgPhoto.Image = new Bitmap(dlg.OpenFile());
doc.Load(dlg.OpenFile());
}
dlg.Dispose();
ConvertXmlNodeToTreeNode(doc, treeXml.Nodes);
treeXml.Nodes[0].ExpandAll();
}
// insert a node
on this button click i want to a node in tree and thje value or string which is in the text box should add to the new treenode....
but this is not wornking,
private void button2_Click(object sender, System.EventArgs e ,TextBox txt)
{
TreeNode rootnode = treeXml.Nodes[0];
TreeNode parentnode = rootnode.Nodes[0];
newTreeNode = new TreeNode(txt.Text);
treeXml.SelectedNode.Nodes.Add(newTreeNode);
// if( treeXml.SelectedNode != null
parentnode = treeXml.SelectedNode;
parentnode.Nodes.Add(new TreeNode(txt.Text));
}
plz help me in this code.
modified on Thursday, February 07, 2008 1:30:10 AM
|
|
|
|
|
|
Hi,
I have learned how to load language specific string from sattelite assemblies by changing the CultureInfo of the Resource's typed class accessor. Now, I am wondering how can I set the culture specific language for the Microsoft's built in UI. For example, I want to change the language of the TextBox's context menu (Cut, Copy, Paste) as there is no "culture" property available for the class Control. Would you please give me any idea.
Thanks
|
|
|
|
|
use System.Globalization,
There, you will get Cultureinfo and RegionInfo Class.
just go through this.
you can also build custome culture using CultureAndRegionBuilder Class!!!
|
|
|
|
|
I'm trying to design my user interface where the user can change the background/foreground colors according to their preference. The XML file format appears to be the best and I would like any advice on making it as effecient as possible. The file's contents could change multiple times (re-written). Is overwriting XML file a good idea. Is there a better file format?
Thanks guys!
may your code be error free.
(okay, maybe two lines.)
|
|
|
|
|
programmingAddict wrote: Is overwriting XML file a good idea. Is there a better file format?
For reading and writing XML files, you can use XMLDocument class which provides a DOM model for the supplied XML file. This class provides methods for creating new node/attributes etc. For reading XML files efficiently, use XPath .
|
|
|
|
|
Thanks for the info. It will get me jump started. The more I look into XML, the more convinced I am that it's my best option. Some of the replies to this thread thought I was intending on the user writing the strings by hand
My opinion of user interaction with text is to limit the use of a textbox AS MUCH as possible! When the user gets a hold of a textbox that will be inputting critical data, bad things will start happening if serious validation is not done.
Best wishes to your code!
may your code be error free.
(okay, maybe two lines.)
|
|
|
|
|
Depends on what you mean by 'better'.
Of course it is OK to overwrite an XML file. But if you want files that can be hand-edited by the user (think Notepad), .properties files are the way to go.
Cheers,
Vikram.
"I will put my new found knolage to good use" - Captain See Sharp.
"Every time Lotus Notes starts up, somewhere a puppy, a kitten, a lamb, and a baby seal are killed." - Gary Wheeler.
|
|
|
|
|
Vikram A Punathambekar wrote: properties files
What is properties file ?
|
|
|
|
|
Very common in Javaland. Instead of angle brackets, they simply use the equals sign. Example:
dbServer=SERVERNAME
userName=user1 To the lay user, editing these in Notepad is much easier than editing XML files.
Cheers,
Vikram.
"I will put my new found knolage to good use" - Captain See Sharp.
"Every time Lotus Notes starts up, somewhere a puppy, a kitten, a lamb, and a baby seal are killed." - Gary Wheeler.
|
|
|
|
|
That's fine. Is this commonly used in .NET ?
|
|
|
|
|
Why not use the standard .NET Profile Provider? It's not just for ASP.NET.
|
|
|
|
|
I have a windows application in C#. On click of a button i want to open windows Explore and navigate to one folder. How can i do that?
|
|
|
|
|
System.Diagnostics.Process.Start("C:\\Inetpub");
|
|
|
|
|
This should work for you:
System.Diagnostics.Process.Start(@"explorer.exe", @"C:\Windows");
Remember, google is your best friend!
Richard
may your code be error free.
(okay, maybe two lines.)
|
|
|
|
|
Hello Friends,
I am developing an windows application in C#.NET now i want that when i install that application in any machine then write into registry. If user wants to install it again then it check whether its entry is in registry or not if it found in registry then user unable to install it again.
Means once installed then unable to reinstall again until unless registry entry are removed....
|
|
|
|
|
Please let me know when find the answer because I need that feature in my app!
may your code be error free.
(okay, maybe two lines.)
|
|
|
|
|
I think you can write custom actions when creating installation package. This[^] blogs says something similar.
|
|
|
|
|
Make a setup of your application using VS IDE and use Registry Editor ...
|
|
|
|
|
Nouman Bhatti wrote: Make a setup of your application using VS IDE and use Registry Editor ...
can you elaborate on this?
|
|
|
|
|
as u said u r making your application in c# and hopefully for that u r using visual studio.
so in that same Visual studio there's a new project type "setup wizard" or "setup project" make your setup and when u done with it... there a option in that setup project with the name of Registry editor. u can add your required registry keys there.
|
|
|
|
|
If you do not want to create an actual setup project you can manipulate the registry the hard way through the Microsoft.Win32 namespace using the class Registry. Check the registry when the program starts.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Could someone help me out with this program?
Draw the circle on a sheet of paper. Remember how big the paper is (how high & how wide, which gives us the total area), and how big the circle is.
2. Randomly pick points on the paper (say, by throwing darts). For each point we randomly pick, we'll do the following:
a. If the point is inside (or on the line of) the circle, we'll increment our counter that keeps track of the number of points that landed inside the circle.
b. If the point isn't inside/on the circle, and you need to, and increment another counter to keep track of that.
c. Either way, increment your "How many times did I pick a point?" counter
d. Darts that fall outside the paper are ignored entirely.
Even better would be to find a way to make sure that your randomly selected points never end up outside the paper in the first place.
3. Once you're done throwing all the darts in step 2, figure out what percentage of the darts fell inside the circle.
As an example, let's say you threw 1,000 darts, 534 of them landed inside/on the boundary of the circle, and 466 landed outside the circle, but on the paper. Thus, 53.4% of the darts landed in the circle.
4. Figure out how big the sheet of paper is (what the total area is).
As a continuing example, let's say that the paper is 100 inches wide, and 200 inches tall, for a total area of (100x200=20,000)
5. Estimate that the area of the circle to be the size of the paper, multiplied by the percentage of points that were inside the circle.
As a continuing example, we'll estimate that the size of the circle is 53.4% of 20,000, or (20,000 * .534=) 10,680 square inches.
The downside is that this is computationally intensive (i.e., you can't really do this by hand). The upside is that this works for *ANY* shape, no matter how complicated. For this homework assignment, we'll stick with circles, and only circles.
Your task is to write a program that will demonstrate how accurate this method is, depending on how many points you randomly select. Basically, you're going to go through, and use the Monte Carlo method to estimate the area of the circle, then use the real formula to find the actual area, then compare the two. The 'error' here will be measured as the percentage difference between the estimated & real circle (so if the circle is 314 units in size, and the estimate is 0, then the error is -100%, meaning that we're 100% below the real size. If the estimate is 345.4 units, then the error is +10%, meaning that we're 10% over the actual size).
An example of the output is given below. Everything that's highlighted in gray is optional output – your program isn't required to produce this output, if you don’t want to. The rest of it is required output. Make the columns of the table line up as best you can.
In addition to accomplishing the above objective, you have two additional, technical goals:
1. Use functions and methods in order to modularize your code as much as possible. If you know how to, and want to create classes here, that would be great.
2. You want to minimize the amount of code you copy-and-paste, so use an array to store the number of points to randomly select each time, and iterate through that. In the below example, there's an array that holds 1, 10, 100, 500, 1000, 5000, 10000, 50000, 100000. The objective here is that by adding numbers to / removing numbers from this array, we can quickly & easily try different numbers of points. The program should run correctly for different numbers of points, even if the only thing changed between runs are the numbers in that array. Similarly, in order to make sure that you could test out many different sized circles (and on different sized sheets of paper), make sure to set up your code so that you can change the size of the paper by changing just one (or maybe two) variables (instead of simply writing in '100' everywhere for the size of the paper), and that you can change only a few variable(s) if you want to change the location or size(radius) of the circle.
Example Output
Welcome To The MonteCarlo Circle Area Estimator!!
Max X: 100
Max Y: 100
Total Area of Surrounding Space: 10000
Basing our estimate on 1 randomly selected points
% of Randomly Picked Points Inside The Circle: 0
Estimated Total Area Of the Circle: 0
Actual Total Area Of the Circle: 314.159265358979
The estimate was off by 314.159265358979, which is -100% of the real circle
************************************************************
Max X: 100
Max Y: 100
Total Area of Surrounding Space: 10000
Basing our estimate on 10 randomly selected points
% of Randomly Picked Points Inside The Circle: 0
Estimated Total Area Of the Circle: 0
Actual Total Area Of the Circle: 314.159265358979
The estimate was off by 314.159265358979, which is -100% of the real circle
************************************************************
Max X: 100
Max Y: 100
Total Area of Surrounding Space: 10000
Basing our estimate on 100 randomly selected points
% of Randomly Picked Points Inside The Circle: 0
Estimated Total Area Of the Circle: 0
Actual Total Area Of the Circle: 314.159265358979
The estimate was off by 314.159265358979, which is -100% of the real circle
************************************************************
Max X: 100
Max Y: 100
Total Area of Surrounding Space: 10000
Basing our estimate on 500 randomly selected points
% of Randomly Picked Points Inside The Circle: 0.026
Estimated Total Area Of the Circle: 260
Actual Total Area Of the Circle: 314.159265358979
The estimate was off by 54.1592653589793, which is -17.2394295922144% of the rea
l circle
************************************************************
Max X: 100
Max Y: 100
Total Area of Surrounding Space: 10000
Basing our estimate on 1000 randomly selected points
% of Randomly Picked Points Inside The Circle: 0.024
Estimated Total Area Of the Circle: 240
Actual Total Area Of the Circle: 314.159265358979
The estimate was off by 74.1592653589793, which is -23.6056273158902% of the rea
l circle
************************************************************
Max X: 100
Max Y: 100
Total Area of Surrounding Space: 10000
Basing our estimate on 5000 randomly selected points
% of Randomly Picked Points Inside The Circle: 0.0262
Estimated Total Area Of the Circle: 262
Actual Total Area Of the Circle: 314.159265358979
The estimate was off by 52.1592653589793, which is -16.6028098198468% of the rea
l circle
************************************************************
Max X: 100
Max Y: 100
Total Area of Surrounding Space: 10000
Basing our estimate on 10000 randomly selected points
% of Randomly Picked Points Inside The Circle: 0.0301
Estimated Total Area Of the Circle: 301
Actual Total Area Of the Circle: 314.159265358979
The estimate was off by 13.1592653589793, which is -4.18872425867901% of the rea
l circle
************************************************************
Max X: 100
Max Y: 100
Total Area of Surrounding Space: 10000
Basing our estimate on 50000 randomly selected points
% of Randomly Picked Points Inside The Circle: 0.03042
Estimated Total Area Of the Circle: 304.2
Actual Total Area Of the Circle: 314.159265358979
The estimate was off by 9.95926535897934, which is -3.17013262289088% of the rea
l circle
************************************************************
Max X: 100
Max Y: 100
Total Area of Surrounding Space: 10000
Basing our estimate on 100000 randomly selected points
% of Randomly Picked Points Inside The Circle: 0.03225
Estimated Total Area Of the Circle: 322.5
Actual Total Area Of the Circle: 314.159265358979
The estimate was off by 8.34073464102067, which is 2.65493829427249% of the real
circle
************************************************************
Max X: 100
Max Y: 100
Radius of Circle: 10
Num Points Off by (%)
1 -100%
10 -100%
100 -100%
500 -17.2394295922144%
1000 -23.6056273158902%
5000 -16.6028098198468%
10000 -4.18872425867901%
50000 -3.17013262289088%
100000 2.65493829427249%
|
|
|
|
|