Blog Archive
Tuesday, July 7, 2009
numericupdown trouble do not show decimal value.
{
string value = numericUpDown1.Value.ToString();
int numOfDecimalPlaces = 0;
if (value.Contains("."))
{
string[] splitString = value.Split(new char[] { '.' });
numOfDecimalPlaces = splitString[1].Length;
}
numericUpDown1.DecimalPlaces = numOfDecimalPlaces;
}
ref : http://www.dreamincode.net/forums/showtopic81889.htm
Monday, July 6, 2009
Xml Read and attibute read
xml file :
<customers>
<customer age="19" gender="female">
<name>Kevin Anders</name>
<phone>555.555.5555</phone>
</customer>
<customer age="22" gender="male">
<name>Staci Richard</name>
<phone>555.122.1552</phone>
</customer>
</customers>
using System;
using System.Xml;
namespace XML
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load("test.xml");
XmlNodeList customers = doc.SelectNodes("//customer");
foreach (XmlNode customer in customers)
{
Console.WriteLine("Age = {0}, Gender = {1}", customer.Attributes["age"].Value, customer.Attributes["gender"].Value);
}
Console.ReadLine();
}
}
}
XML :
XML :
<?xml version="1.0" encoding="ISO-8859-1"?>
<Setting>
<General_Properties>
<imagesXML value="images.xml"/>
<direction value="horizontal" />
<minThumbWidth value="50" />
<minThumbHeight value="50" />
<maxThumbWidth value="120" />
<maxThumbHeight value="120" />
<spacing value="5" />
<expandingDirection value="center" />
<imagesEasingSpeed value="70" />
<imagesInfluence value="200" />
<backgroundColor value="0xeeeeee" />
<dockWidth value="570" />
<dockHeight value="200" />
<startingPixel value="0" />
<gotoStartingPixelOnRollOut value="false" />
</General_Properties>
</Setting>
using System;
using System.Xml;
namespace XML
{
///
/// Summary description for Class1.
///
class Class1
{
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load("settings.xml");
XmlNodeList imagesXML = doc.SelectNodes("//imagesXML");
foreach (XmlNode name in imagesXML)
{
Console.WriteLine("Value {0}", name.Attributes["value"].Value);
}
///
XmlNodeList direction = doc.SelectNodes("//direction");
foreach (XmlNode name in direction)
{
Console.WriteLine("Value {0}", name.Attributes["value"].Value);
}
Console.ReadLine();
}
}
}
XmlTextReader.GetAttribute Method (String)
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlTextReader reader = null;
try
{
//Load the reader with the XML file.
reader = new XmlTextReader("attrs.xml");
//Read the ISBN attribute.
reader.MoveToContent();
string isbn = reader.GetAttribute("ISBN");
Console.WriteLine("The ISBN value: " + isbn);
}
finally
{
if (reader != null)
reader.Close();
}
}
} // End class
The example uses the file, attrs.xml, as input.
<book genre='novel' ISBN='1-861003-78' pubdate='1987'>
</book>
ref : http://msdn.microsoft.com/en-us/library/3c932kx5.aspx