|
Ah - to get the length of 20 pixels, you would indeed have to use trig to get the x and y, unless it was a 3,4,5 triangle. ( where one side is 3*i, one is 4*i and the hypotenuse is 5*i ).
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
you would indeed have to use trig to get the x and y
lol, I think thats the question I originally asked. I noticed 1 thing:
float opp = (float)Math.Sign(DegToRad(this.angle))*interval;
using Math.Sign instead of Math.Sin - who could get those two mixed up using intellisense...
Anyway, still doesnt work, was wondering if anyone could spot the obvious error.
|
|
|
|
|
I've create an object:
class myClass{
int value;
string name;
}
now i've created an arraylist of it
ArrayList[] myArray = new ArrayList[4];
now i create multiarray of it:
for(int i=0; i<4; i++){
myArray[i] = new ArrayList[7];
}
now i assign value in this way
...
myClass myClassRef = new myClass();
myClassRef.name = "James";
myArray[2][4] = myClassRef;
...
ok now i want to save all myArray inside a text file and then read back again a new myNewArray.
How? Can you show me a bit of code?
I choose arraylist becouse it is not definited the dimension.
I don't want to use XML becouse C# is a full self sufficient language!
Tnx to all.
|
|
|
|
|
Add a custom serializer and deserializer to the class, then. Something like:
class myClass{<br />
<br />
public int value;<br />
public string name;<br />
<br />
public MyClass() {}<br />
<br />
public MyClass(string serializedData) {<br />
int pos = serializedData.FirstIndexOf(' ');<br />
this.value = int.Parse(serializedData.Substring(0, pos));<br />
this.name = serializedData.SubString(pos + 1);<br />
}<br />
<br />
public string Serialize() {<br />
return this.value.ToString() + " " + this.name;<br />
}<br />
<br />
}
Then just loop through the arrays and write the serialized string of each object to the file (using WriteLine).
When you wish to recreate the arrays, read each line and use the deserializer constructor to recreate each object.
---
b { font-weight: normal; }
|
|
|
|
|
tnx for your answer but it is not the way i choose...
|
|
|
|
|
What way did you choose, then?
---
b { font-weight: normal; }
|
|
|
|
|
Sasuko wrote:
I don't want to use XML becouse C# is a full self sufficient language!
Huh? So you won't use SQL because C# is a "full sufficient language!"? XML is designed for storing data, C# is not, so what's the point in staying away from XML?
You can use Binary serialization if you want to, just serialize the arraylist using BinaryFormatter and deserialize it back.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
You can use Binary serialization if you want to, just serialize the arraylist using BinaryFormatter and deserialize it back.
Yes that is the way, but i need example of code.
|
|
|
|
|
Check out these two functions for serializing and deserializing data using a BinaryFormatter. It serializes a hashtable but can be replaced by an arraylist and should work just fine.
static void Serialize() <br />
{<br />
Hashtable addresses = new Hashtable();<br />
addresses.Add("Jeff", "123 Main Street, Redmond, WA 98052");<br />
addresses.Add("Fred", "987 Pine Road, Phila., PA 19116");<br />
addresses.Add("Mary", "PO Box 112233, Palo Alto, CA 94301");<br />
<br />
FileStream fs = new FileStream("DataFile.dat", FileMode.Create);<br />
<br />
BinaryFormatter formatter = new BinaryFormatter();<br />
try <br />
{<br />
formatter.Serialize(fs, addresses);<br />
}<br />
catch (SerializationException e) <br />
{<br />
Console.WriteLine("Failed to serialize. Reason: " + e.Message);<br />
throw;<br />
}<br />
finally <br />
{<br />
fs.Close();<br />
}<br />
}<br />
<br />
<br />
static void Deserialize() <br />
{<br />
Hashtable addresses = null;<br />
<br />
FileStream fs = new FileStream("DataFile.dat", FileMode.Open);<br />
try <br />
{<br />
BinaryFormatter formatter = new BinaryFormatter();<br />
<br />
addresses = (Hashtable) formatter.Deserialize(fs);<br />
}<br />
catch (SerializationException e) <br />
{<br />
Console.WriteLine("Failed to deserialize. Reason: " + e.Message);<br />
throw;<br />
}<br />
finally <br />
{<br />
fs.Close();<br />
}<br />
<br />
foreach (DictionaryEntry de in addresses) <br />
{<br />
Console.WriteLine("{0} lives at {1}.", de.Key, de.Value);<br />
}<br />
}
Elvis (a.k.a Azerax)
Life is Music listen to it before it fades
|
|
|
|
|
Hello,
I would like to mask the text box such that it would only be for the money amounts, and it would have $ sign in front. So for input in textbox:
4500
Masked to: $ 4,500
Any ideas?
Thank you.
|
|
|
|
|
You could just format the number before you display it.
double x = 4500.00;
textBox2.Text= x.ToString("c");
output = $4,500.00
|
|
|
|
|
This the modification version of MaskedTextControl from
User Interfaces in C# book
using System;
using System.Windows.Forms;
public class MaskedTextBox : TextBox
{
private string mask;
public string Mask
{
get
{
return mask;
}
set
{
mask = value;
this.Text = "";
}
}
Protected override void OnKeyPress(KeyPressEventArgs e)
{
if (Mask != "")
{
e.Handled = true;
string newText = this.Text;
bool finished = false;
for (int i = this.SelectionStart; i < mask.Length; i++)
{
switch (mask[i].ToString())
{
case "#" :
if (Char.IsDigit(e.KeyChar) )
{
if(this.TextLength<mask.Length)
{
newText += e.KeyChar.ToString();
finished = true;
break;
}
else
{
newText=newText.Remove(i,this.SelectionLength);
newText=newText.Insert(i,e.KeyChar.ToString());
finished = true;
break;
}
}
else
{
return;
}
default :
newText += mask[i];
break;
}
if (finished)
{ break; }
}
this.Text = newText;
this.SelectionStart = this.Text.Length;
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
e.Handled = true;
}
}
In the Form Load event add the following
maskTextBox.Mask = "$###,###";
MCAD
|
|
|
|
|
There seems to be an error:
if(this.TextLength {
in this line, the IF statement is not completed, or am I reading it incorectly? Is it:
if (this.TextLength != 0)
Another thing, to make the amount bigger, do I just increase the mask line: "$###,###,###....", or there is a better way?
Thank you
|
|
|
|
|
sorry some thing wrong was happend
replace if(this.TextLength {
<br />
with<pre><code><br />
if(this.TextLength<mask.Length)
This prevent the user form enter number longer than mask lenght
zaboboa wrote:
Another thing, to make the amount bigger, do I just increase the mask line: "$###,###,###....", or there is a better way?
Yes you cab write mask like $###,###,### or even
$(###)(###),(###)
Note:this quick code so test it before you use it
and you may add another thibgs like backspace...
MCAD
|
|
|
|
|
You know, it will work better if you put this statement insted
if(this.TextLength == this.SelectionStart)
Of course for this mask to be perfect you have to add a Leave event, in case the user leaves the box, with the input like that $455,6
Thank you for your help, it gave me a big jumpstart.
|
|
|
|
|
zaboboa wrote:
Of course for this mask to be perfect you have to add a Leave event, in case the user leaves the box, with the input like that $455,6
And Copy and Paste there are many things you can add it
Go on
MCAD
|
|
|
|
|
has anyone come across an open source server in C# or any other language..
I need one....I'll convert it into C# if its not in C#
|
|
|
|
|
|
i have a XML file and i wish to remove a few nodes from it...I am using the XMLDocument class...How can i do this without loading it into a dataset or something..
|
|
|
|
|
What exaclty are you trying to do. Permanently remove nodes from the document? Copy nodes to nodes outside the document?
|
|
|
|
|
like..if i document that was like..
<phonebook>
<contact>
<firstname>A
<lastname>A
<phonenum>A
<titel>A
<nickname>A
<country>
<city>A
A
<zipcode>A
<job>A
<mail>A
<site>A
now suppose i want to remove the field called zipcode..
how do i do that?
|
|
|
|
|
<?xml version="1.0"?><br />
<!--Mohamed's Address Book - WRITING XML IN VB.NET--><br />
<!--AUTHOR - Mohamed Magdy--><br />
<phonebook><br />
<contact><br />
<firstname>A</firstname><br />
<lastname>A</lastname><br />
<phonenum>A</phonenum><br />
<titel>A</titel><br />
<nickname>A</nickname><br />
<country /><br />
<city>A</city><br />
<address>A</address><br />
<zipcode>A</zipcode><br />
<job>A</job><br />
<mail>A</mail><br />
<site>A</site><br />
</contact><br />
</phonebook>
|
|
|
|
|
i dunno why im unable to put xml text here
|
|
|
|
|
|
<?xml version="1.0"?>
<!--Mohamed's Address Book - WRITING XML IN VB.NET-->
<!--AUTHOR - Mohamed Magdy-->
<phonebook>
<contact>
<firstname>A</firstname>
<lastname>A</lastname>
<phonenum>A</phonenum>
<titel>A</titel>
<nickname>A</nickname>
<country />
<city>A</city>
<address>A</address>
<zipcode>A</zipcode>
<job>A</job>
<mail>A</mail>
<site>A</site>
</contact>
</phonebook>
I want to remove the node called zipcode
|
|
|
|