|
I don't know what to serilize an array is but you forget to include
using System.IO;
And I got some errors wich I fixed with making the class I used [Serializable]
I really just want to save the data to a file...
And after a little fixing it worked. Thanks
Niklas Ulvinge aka IDK
|
|
|
|
|
I got an error. If I saved an array of 8 objects it loads 9 and the last one is null.
That's bad.
Niklas Ulvinge aka IDK
|
|
|
|
|
That's not a lot to go on. I have no idea what your source code looks like. If you'd like to include it (code that builds the array, serializes it and deserializes it, along with the type you're trying to serialize in the array), I can have a look.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
It's huge... I'll only post some parts of it...
The code for each class is huge, I hope the structure is enough
Item.cs:
namespace NiklasUlvinge.ChipsEater
{
[Serializable]
abstract class Item
[Serializable]
class Void : Item
[Serializable]
class Cord : Item
[Serializable]
class Ground : Item
[Serializable]
class theGround : Item
...
}
form1.cs:
namespace NiklasUlvinge.ChipsEater
{
public partial class Form1 : Form
{
#region FileHandling
private void OpenFile_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog(this);
FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read, FileShare.None);
byte[] data = new byte[fs.Length];
fs.Read(data, 0, (int)fs.Length);
items = (Item[])BinaryConverter.DeserializeThat(data);
fs.Flush();
fs.Close();
SetParent();
PB.Refresh();
}
private void SaveFile_Click(object sender, EventArgs e)
{
saveFileDialog1.ShowDialog(this);
FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.Write, FileShare.None);
byte[] data = BinaryConverter.SerializeThis(items);
fs.Write(data, 0, data.Length);
fs.Flush();
fs.Close();
}
#endregion
private void toolStripButtonClear_Click(object sender, EventArgs e)
{
items = new Item[1] { new theGround(items) };
SetParent();
PB.Refresh();
}
private void addItem(Item item)
{
Item[] titem = new Item[items.Length + 1];
for (int i = 0; i < items.Length; i++)
{
titem[i] = items[i];
}
titem[items.Length] = item;
items = titem;
SetParent();
if (item.x - PB.Width > hScrollBar1.Maximum)
hScrollBar1.Maximum = item.x - PB.Width;
if (item.y - PB.Height > vScrollBar1.Maximum)
vScrollBar1.Maximum = item.y - PB.Height;
}
private Item getItem(int x, int y)
{
for (int i = 0; i < items.Length; i++)
{
if (Math.Abs(items[i].x - x) < items[i].Width)
if (Math.Abs(items[i].y - y) < items[i].Height)
if (items[i].GetType() != new Cord(-50, -50, items).GetType())
return items[i];
}
return null;
}
public void SetParent()
{
for (int i = 0; i < items.Length; i++)
{
items[i].parent = items;
}
}
}
}
Hope this was enough, I only included the most neccesary parts...
Niklas Ulvinge aka IDK
|
|
|
|
|
I can't really tell for sure, but my guess would be that in your addItem method you're creating an array where the last item (set to the value of the 'item' parameter) is null.
Have you inserted a breakpoint in your code just prior to serialization (in SaveFile_Click ) to inspect your array and ensure that the length is what you expect it to be, and that all the elements in the array are non-null?
If you want, just email the source to me.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
-- modified at 12:42 Saturday 17th September, 2005
|
|
|
|
|
I couldn't find any error in the any of the file funcs...
I then made some UI improvements and now the error is gone!
Thank you for your help.
It's a circuit simulator, but it's not that good yet. It got some foults... It's the Kirchkorvs (or whatever he's called, I can't remember) rule that's not working as it should.
turbochimp wrote:
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
That's funny...
Niklas Ulvinge aka IDK
|
|
|
|
|
I wasn't really aiming at providing you with a completed application - just some sample code.
If you don't know what serialization is, I would suggest reading about it before using it - it's in the MSDN documentation under "Serialization".
Glad to have helped.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Hi
I'me working on a tapi project with tapi3.dll. I successfully created calls with ITAddress etc. Now I tried to call the method TranslateAddress from the class ITAddressTranslation, which is an abstract class. Unfortunately without success.
Now the question: Does anybody know how I can use this method? How do I have to instantiate the class ITAddressTranslation in order to get this method?
Thanks Fredy
|
|
|
|
|
hi,can anyone tell me a way of voice chat in c#,i will be very thankful to u.
|
|
|
|
|
Hi,
I want to filter the rows of the DataTable using the DataTables's Select() method.
I have a DataTime column in the DataTable. My Search Criteria should check that
DateTime Column's Hour value with the present System Time's Hour value
and
DateTime Column's Minute value with the present System Time's Minute value.
What functions/methods can i specify to extract the Hour, Minute from the DateTime column of the DataTable?
The following is the code:
string lstr = string.Empty;
lstr = "datename(hh,getdate())= datename(hh,schedule_time) and datename(mi,getdate())= datename(mi,schedule_time)";
DataRow[] dr = mds.Tables[0].Select(lstr);
Thanks in advance.
-- modified at 6:50 Friday 16th September, 2005
|
|
|
|
|
hey all,
am getting image using SHGetFileInfo for form Image, but when i put it onto a toolbarbutton i get black where it should be transparent.
i tried to convert to bitmap before putting icon into the imagelist but still no good.
any ideas pls?
<br />
private void CreateNewMDIChild(string path)<br />
{<br />
EditorPane pane = new EditorPane(path);<br />
pane.MdiParent = this;<br />
pane.Show();<br />
<br />
this.documentImageList.Images.Add(pane.Icon);<br />
<br />
ToolBarButton button = new ToolBarButton(pane.FileName);<br />
button.ToolTipText = pane.Path; <br />
button.ImageIndex = MdiChildren.Length - 1;<br />
this.mdiChildrenToolbar.Buttons.Add(button);<br />
<br />
UpdateButtonPushState(button);<br />
}<br />
kind regards,
g00fy
|
|
|
|
|
Hi,
Check for the size of the Image/Icon and the Image Size selected for the ImageList control. Both the size should match inorder to display the icon properly
Best Regards,
|
|
|
|
|
yes they are same => 16, 16, transparentColor = transparent, ColorDepth => Depth8Bit
one thing i have noticed debugging is that the depth of the icon of the form, is 0 which is not same as imagelist.
regards,
g00fy
|
|
|
|
|
Hi!
Could be the rather well-known "32bpp images in an ImageList lose transparency" bug.
You'll find a lot of stuff/suggestions/discussions when you google for "imagelist transparency bug".
Regards,
mav
|
|
|
|
|
Hi
I'm trying to start a timer event from another event. A event is activated from an external button through the parallellport.
This works perfect. I can fire almost anything, but not the timer. I want to start a countdown when i press the external button. The timer starts if I start it from a formbutton.
Please help.
//Nicklas
Here is part of my code:
public delegate void PortDataHandler(object sender, MyDataEventArgs e);
private System.Threading.ThreadStart threadStart;
private System.Threading.Thread thread;
public event PortDataHandler OnPortDataChange;
Timer timer1 = new Timer();
private void Form1_Load(object sender, System.EventArgs e)
{
drive();
}
private void drive()
{
//my timer
timer1.Tick += new EventHandler(Ticker);
timer1.Interval = 1000;
//my event
OnPortDataChange += new PortDataHandler(my_Handler);
this.threadStart = new System.Threading.
ThreadStart(Application_Tick);
this.thread = new System.Threading.Thread(threadStart);
this.thread.Start();
}
public class MyDataEventArgs : EventArgs
{
public readonly int TheNumber;
public MyDataEventArgs(int num)
{
TheNumber = num;
}
}
public void Application_Tick()
{
while ((Input(889)==120))
{
}
OnPortDataChange(this, new MyDataEventArgs(Input(889)));
drive();
}
void Ticker(object sender, EventArgs e)
{
//do something every second
}
public void my_counter()
{
label1.Text="now you are here";
timer1.Start(); //the timer don't start from here
}
public void my_Handler(object sender, MyDataEventArgs e)
{
this.label2.Text="You pressed the button!!";
my_counter();
//PlaySound( "C:/mina mappar/project programming/play2/sound.wav", 0, 1 );
//timer1.start(); //timer dont start here
private void button1_Click(object sender, System.EventArgs e)
{
//label1.Text="vanliga knappen";
this.thread.Abort();
this.Close();
//OnPortDataChange(this, new MyDataEventArgs(Input(889)));
}
private void button2_Click(object sender, System.EventArgs e)
{
timer1.Start(); //the timer start here????????? but not where i want.
}
}
}
|
|
|
|
|
Hi!
It might have to do with the type of timer you use.
You just wrote Timer , but from the Tick event I guess it's the System.Windows.Forms.Timer class.
This kind of timer depends on your UI thread's message pump to work, so this could be the problem (depends on the rest of your program).
Try using System.Timers.Timer instead.
Regards,
mav
|
|
|
|
|
Can anyone explain me more about CLR ??
|
|
|
|
|
|
Hi, I am looking for a way to merge video file together on-the-fly, I have find some demo activeX control doing it, but it's always by recompressing the whole video, so it take ages. I'd like to do it the way most shareware (like "Easy Video Joiner") do it, without decompressing the frame.
Any help or info could help me.
Thansk you a lot in advance.
|
|
|
|
|
How do I use the less than sign in documentation
e.g. I want
/// <returns>0 (equal), 1 (s1>s2), -1 (s1 < s2)
but VS.Net thinks the < sign is opening another documentation tag. Is there some way to escape the character so that it doesn't do this?
|
|
|
|
|
< = & lt ; > = & gt ;
no spaces from & to ; just did this so cp wouldnt see it as < = <
hth
goofy
|
|
|
|
|
Thanks although initially I thought I had to include the < and = parts as well so this was confusing. So the actual replacement for
less than (<) is
& lt ;
without the space.
thanks again
Claire
|
|
|
|
|
yes that is it,
anytime
regards,
g00fy
|
|
|
|
|
Below i have posted the code for my little project, my problem is located at the line looking like this
"tempArray[iCounter++] = btnArray[iButtonIndex];"
and i'm getting this error:
Property or indexer 'ButtonArray.ButtonArray.this[int]' cannot be assigned to -- it is read only
What i'm trying to do is this, once i have removed an object from btnArray, i want to copy the remaining stuff of btnArray to tempArray in order to re-arrange the elements. This should be done through the CopyArray().
However i can't figure out why im getting a readonly error, can anyone please help me out?
Thanks alot in advance!
-----------------------------------------------------------------
CODE FOR FORM1.CS BELOW
-----------------------------------------------------------------
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
using ButtonArray;<br />
<br />
namespace ButtonArray<br />
{<br />
public class Form1 : System.Windows.Forms.Form<br />
{<br />
private System.Windows.Forms.Button btnAdd;<br />
private System.Windows.Forms.Button btnRemove;<br />
private System.Windows.Forms.Button btnRemoveX;<br />
private System.Windows.Forms.TextBox txtRemoveX;<br />
<br />
public int iRemoveX;<br />
<br />
ButtonArray btnArray;<br />
ButtonArray tempArray;<br />
<br />
private System.ComponentModel.Container components = null;<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if (components != null) <br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}<br />
<br />
#region Windows Form Designer generated code<br />
private void InitializeComponent()<br />
{<br />
this.btnAdd = new System.Windows.Forms.Button();<br />
this.btnRemove = new System.Windows.Forms.Button();<br />
this.btnRemoveX = new System.Windows.Forms.Button();<br />
this.txtRemoveX = new System.Windows.Forms.TextBox();<br />
this.SuspendLayout();<br />
this.btnAdd.Location = new System.Drawing.Point(192, 8);<br />
this.btnAdd.Name = "btnAdd";<br />
this.btnAdd.Size = new System.Drawing.Size(96, 23);<br />
this.btnAdd.TabIndex = 0;<br />
this.btnAdd.Text = "Add Button";<br />
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);<br />
this.btnRemove.Location = new System.Drawing.Point(192, 40);<br />
this.btnRemove.Name = "btnRemove";<br />
this.btnRemove.Size = new System.Drawing.Size(96, 23);<br />
this.btnRemove.TabIndex = 1;<br />
this.btnRemove.Text = "Remove Button";<br />
this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click);<br />
this.btnRemoveX.Location = new System.Drawing.Point(192, 104);<br />
this.btnRemoveX.Name = "btnRemoveX";<br />
this.btnRemoveX.Size = new System.Drawing.Size(96, 23);<br />
this.btnRemoveX.TabIndex = 2;<br />
this.btnRemoveX.Text = "Remove X";<br />
this.btnRemoveX.Click += new System.EventHandler(this.btnRemoveX_Click);<br />
this.txtRemoveX.Location = new System.Drawing.Point(192, 136);<br />
this.txtRemoveX.Name = "txtRemoveX";<br />
this.txtRemoveX.Size = new System.Drawing.Size(96, 20);<br />
this.txtRemoveX.TabIndex = 3;<br />
this.txtRemoveX.Text = "";<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.ClientSize = new System.Drawing.Size(292, 266);<br />
this.Controls.Add(this.txtRemoveX);<br />
this.Controls.Add(this.btnRemoveX);<br />
this.Controls.Add(this.btnRemove);<br />
this.Controls.Add(this.btnAdd);<br />
this.Name = "Form1";<br />
this.Text = "Form1";<br />
this.Load += new System.EventHandler(this.Form1_Load);<br />
this.ResumeLayout(false);<br />
<br />
btnArray = new ButtonArray(this);<br />
tempArray = new ButtonArray(this);<br />
<br />
}<br />
#endregion<br />
<br />
[STAThread]<br />
static void Main() <br />
{<br />
Application.Run(new Form1());<br />
}<br />
<br />
private void Form1_Load(object sender, System.EventArgs e)<br />
{<br />
<br />
}<br />
<br />
private void aButton_Click(object sender, System.EventArgs e)<br />
{<br />
<br />
}<br />
<br />
private void btnAdd_Click(object sender, System.EventArgs e)<br />
{<br />
btnArray.AddNewButton();<br />
btnArray[0].BackColor = System.Drawing.Color.Red;<br />
}<br />
<br />
private void btnRemove_Click(object sender, System.EventArgs e)<br />
{<br />
<br />
if(btnArray.Count > 0)<br />
{<br />
btnArray.Remove(btnArray.Count-1);<br />
}<br />
else <br />
{<br />
MessageBox.Show("ARRAY IS EMPTY");<br />
}
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
private void btnRemoveX_Click(object sender, System.EventArgs e)<br />
{<br />
try<br />
{ <br />
iRemoveX = Convert.ToInt32(txtRemoveX.Text);<br />
<br />
if(btnArray.Count > 0)<br />
{<br />
btnArray.Remove(iRemoveX);<br />
}<br />
else <br />
{<br />
MessageBox.Show("(REMOVE) ARRAY IS EMPTY");<br />
}<br />
}<br />
<br />
catch(Exception ex)<br />
{<br />
MessageBox.Show("ERROR: " + ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error,MessageBoxDefaultButton.Button1); <br />
}<br />
}<br />
<br />
private void CopyArray()<br />
{<br />
try<br />
{<br />
if(btnArray.Count > 0)<br />
{<br />
int iCounter;<br />
for (int iButtonIndex = 0; iButtonIndex < btnArray.Count; iButtonIndex++)<br />
{<br />
if (btnArray[iButtonIndex] != null)<br />
{<br />
tempArray[iCounter++] = btnArray[iButtonIndex];<br />
iCounter++;<br />
}<br />
}<br />
}<br />
else<br />
{<br />
MessageBox.Show("(COPY) ARRAY IS EMPTY");<br />
}<br />
<br />
}<br />
catch(Exception ex)<br />
{<br />
MessageBox.Show("ERROR: " + ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error,MessageBoxDefaultButton.Button1);<br />
}<br />
}<br />
<br />
private void ShowArray()<br />
{<br />
}<br />
}<br />
}
----------------------------------------------------------------
CODE FOR BUTTONARRAY.CS BELOW
----------------------------------------------------------------
using System;<br />
<br />
namespace ButtonArray<br />
{<br />
public class ButtonArray : System.Collections.CollectionBase<br />
{<br />
private readonly System.Windows.Forms.Form HostForm;<br />
<br />
public System.Windows.Forms.Button AddNewButton()<br />
{<br />
System.Windows.Forms.Button aButton = new System.Windows.Forms.Button();<br />
<br />
this.List.Add(aButton);<br />
<br />
HostForm.Controls.Add(aButton);<br />
<br />
aButton.Top = Count * 25;<br />
aButton.Left = 100;<br />
aButton.Tag = this.Count;<br />
aButton.Text = "Button " + this.Count.ToString();<br />
<br />
<br />
aButton.Click += new System.EventHandler(ClickHandler);<br />
<br />
return aButton;<br />
}<br />
public ButtonArray(System.Windows.Forms.Form host)<br />
{<br />
HostForm = host;<br />
this.AddNewButton();<br />
}<br />
<br />
public System.Windows.Forms.Button this [int Index]<br />
{<br />
get<br />
{<br />
return (System.Windows.Forms.Button) this.List[Index];<br />
}<br />
}<br />
<br />
public void Remove(int iRemoveX)<br />
{<br />
if (this.Count > 0)<br />
{<br />
<br />
HostForm.Controls.Remove(this[iRemoveX]);<br />
this.List.RemoveAt(this.Count -1);<br />
}<br />
}<br />
<br />
public void ClickHandler(Object sender, System.EventArgs e)<br />
{<br />
System.Windows.Forms.MessageBox.Show("You have clicked button " + <br />
((System.Windows.Forms.Button) sender).Tag.ToString());<br />
}<br />
}<br />
}
|
|
|
|
|
Please only post the code that is relevant for the question.
---
b { font-weight: normal; }
|
|
|
|
|