Click here to Skip to main content
15,920,602 members
Home / Discussions / C#
   

C#

 
QuestionSmart document security Pin
WillemM16-Sep-05 3:47
WillemM16-Sep-05 3:47 
QuestionCalculating dates from tables and displaying results Pin
AdamskiR16-Sep-05 3:02
AdamskiR16-Sep-05 3:02 
QuestionObjects to bytes... Pin
Niklas Ulvinge16-Sep-05 2:47
Niklas Ulvinge16-Sep-05 2:47 
AnswerRe: Objects to bytes... Pin
turbochimp16-Sep-05 17:03
turbochimp16-Sep-05 17:03 
GeneralRe: Objects to bytes... Pin
Niklas Ulvinge16-Sep-05 21:07
Niklas Ulvinge16-Sep-05 21:07 
GeneralRe: Objects to bytes... Pin
Niklas Ulvinge16-Sep-05 21:25
Niklas Ulvinge16-Sep-05 21:25 
GeneralRe: Objects to bytes... Pin
turbochimp17-Sep-05 6:25
turbochimp17-Sep-05 6:25 
GeneralRe: Objects to bytes... Pin
Niklas Ulvinge17-Sep-05 6:32
Niklas Ulvinge17-Sep-05 6:32 
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
GeneralRe: Objects to bytes... Pin
turbochimp17-Sep-05 6:42
turbochimp17-Sep-05 6:42 
GeneralRe: Objects to bytes... Pin
Niklas Ulvinge17-Sep-05 7:00
Niklas Ulvinge17-Sep-05 7:00 
GeneralRe: Objects to bytes... Pin
turbochimp17-Sep-05 6:23
turbochimp17-Sep-05 6:23 
QuestionHow to call ITAddressTranslation method Pin
Fredy16-Sep-05 1:08
Fredy16-Sep-05 1:08 
QuestionC# and voice chat Pin
pakFari16-Sep-05 1:07
pakFari16-Sep-05 1:07 
QuestionDateTime search with Data Tables "Select" Method Pin
16-Sep-05 0:50
suss16-Sep-05 0:50 
Questionimage on toolbarbutton Pin
g00fyman16-Sep-05 0:46
g00fyman16-Sep-05 0:46 
AnswerRe: image on toolbarbutton Pin
Subrahmanyam K16-Sep-05 1:01
Subrahmanyam K16-Sep-05 1:01 
GeneralRe: image on toolbarbutton Pin
g00fyman16-Sep-05 1:07
g00fyman16-Sep-05 1:07 
AnswerRe: image on toolbarbutton Pin
mav.northwind16-Sep-05 5:05
mav.northwind16-Sep-05 5:05 
QuestionThread and timer problem Pin
NicklasRing15-Sep-05 23:41
NicklasRing15-Sep-05 23:41 
AnswerRe: Thread and timer problem Pin
mav.northwind16-Sep-05 21:50
mav.northwind16-Sep-05 21:50 
QuestionCLR Pin
Anonymous15-Sep-05 23:37
Anonymous15-Sep-05 23:37 
AnswerRe: CLR Pin
Guffa15-Sep-05 23:57
Guffa15-Sep-05 23:57 
QuestionJoin video on-the-fly Pin
karnalta15-Sep-05 23:36
karnalta15-Sep-05 23:36 
QuestionHow to use &lt; sign in comments? Pin
Dr Reedo15-Sep-05 23:09
Dr Reedo15-Sep-05 23:09 
AnswerRe: How to use < sign in comments? Pin
g00fyman15-Sep-05 23:17
g00fyman15-Sep-05 23:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.