Click here to Skip to main content
16,017,193 members
Home / Discussions / C#
   

C#

 
QuestionHttpWebRequest Timeout Problem Pin
surfman193-Sep-05 4:30
surfman193-Sep-05 4:30 
AnswerRe: HttpWebRequest Timeout Problem Pin
Andy Brummer3-Sep-05 14:21
sitebuilderAndy Brummer3-Sep-05 14:21 
GeneralRe: HttpWebRequest Timeout Problem Pin
surfman193-Sep-05 14:36
surfman193-Sep-05 14:36 
GeneralRe: HttpWebRequest Timeout Problem Pin
Andy Brummer3-Sep-05 17:03
sitebuilderAndy Brummer3-Sep-05 17:03 
GeneralRe: HttpWebRequest Timeout Problem Pin
surfman194-Sep-05 1:23
surfman194-Sep-05 1:23 
QuestionCurciut problem Pin
Niklas Ulvinge3-Sep-05 3:30
Niklas Ulvinge3-Sep-05 3:30 
AnswerRe: Curciut problem Pin
rudy.net3-Sep-05 5:21
rudy.net3-Sep-05 5:21 
GeneralRe: Curciut problem Pin
Niklas Ulvinge3-Sep-05 5:33
Niklas Ulvinge3-Sep-05 5:33 
Form1.Designer.cs:
namespace NiklasUlvinge.ChipsEater
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.Windows.Forms.TreeNode treeNode1 = new System.Windows.Forms.TreeNode("Cord");
            System.Windows.Forms.TreeNode treeNode2 = new System.Windows.Forms.TreeNode("Transistor");
            System.Windows.Forms.TreeNode treeNode3 = new System.Windows.Forms.TreeNode("Battery");
            System.Windows.Forms.TreeNode treeNode4 = new System.Windows.Forms.TreeNode("lowest", new System.Windows.Forms.TreeNode[] {
            treeNode1,
            treeNode2,
            treeNode3});
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.toolStrip1 = new System.Windows.Forms.ToolStrip();
            this.splitContainer1 = new System.Windows.Forms.SplitContainer();
            this.treeItems = new System.Windows.Forms.TreeView();
            this.PB = new System.Windows.Forms.PictureBox();
            this.splitContainer1.Panel1.SuspendLayout();
            this.splitContainer1.Panel2.SuspendLayout();
            this.splitContainer1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.PB)).BeginInit();
            this.SuspendLayout();
            // 
            // menuStrip1
            // 
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(608, 24);
            this.menuStrip1.TabIndex = 0;
            this.menuStrip1.Text = "menuStrip1";
            // 
            // toolStrip1
            // 
            this.toolStrip1.Location = new System.Drawing.Point(0, 24);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.Size = new System.Drawing.Size(608, 25);
            this.toolStrip1.TabIndex = 1;
            this.toolStrip1.Text = "toolStrip1";
            // 
            // splitContainer1
            // 
            this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.splitContainer1.Location = new System.Drawing.Point(0, 49);
            this.splitContainer1.Name = "splitContainer1";
            // 
            // splitContainer1.Panel1
            // 
            this.splitContainer1.Panel1.Controls.Add(this.treeItems);
            // 
            // splitContainer1.Panel2
            // 
            this.splitContainer1.Panel2.Controls.Add(this.PB);
            this.splitContainer1.Size = new System.Drawing.Size(608, 376);
            this.splitContainer1.SplitterDistance = 83;
            this.splitContainer1.TabIndex = 3;
            this.splitContainer1.Text = "splitContainer1";
            // 
            // treeItems
            // 
            this.treeItems.Dock = System.Windows.Forms.DockStyle.Fill;
            this.treeItems.Location = new System.Drawing.Point(0, 0);
            this.treeItems.Name = "treeItems";
            treeNode1.Name = "NodeLst0";
            treeNode1.Text = "Cord";
            treeNode1.ToolTipText = "A simple current wire";
            treeNode2.Name = "NodeLst1";
            treeNode2.Text = "Transistor";
            treeNode2.ToolTipText = "A transistor";
            treeNode3.Name = "NodeLst2";
            treeNode3.Text = "Battery";
            treeNode3.ToolTipText = "A simple battery";
            treeNode4.Name = "NodeLst";
            treeNode4.Text = "lowest";
            treeNode4.ToolTipText = "The lowest things of circuts";
            this.treeItems.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
            treeNode4});
            this.treeItems.ShowRootLines = false;
            this.treeItems.Size = new System.Drawing.Size(83, 376);
            this.treeItems.TabIndex = 0;
            // 
            // PB
            // 
            this.PB.Dock = System.Windows.Forms.DockStyle.Fill;
            this.PB.Location = new System.Drawing.Point(0, 0);
            this.PB.Name = "PB";
            this.PB.Size = new System.Drawing.Size(521, 376);
            this.PB.TabIndex = 1;
            this.PB.TabStop = false;
            this.PB.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PB_MouseMove);
            this.PB.Paint += new System.Windows.Forms.PaintEventHandler(this.PB_Paint);
            this.PB.MouseClick += new System.Windows.Forms.MouseEventHandler(this.PB_MouseClick);
            this.PB.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PB_MouseUp);
            this.PB.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PB_MouseDown);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(608, 425);
            this.Controls.Add(this.splitContainer1);
            this.Controls.Add(this.toolStrip1);
            this.Controls.Add(this.menuStrip1);
            this.MainMenuStrip = this.menuStrip1;
            this.Name = "Form1";
            this.Text = "Form1";
            this.splitContainer1.Panel1.ResumeLayout(false);
            this.splitContainer1.Panel2.ResumeLayout(false);
            this.splitContainer1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.PB)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStrip toolStrip1;
        private System.Windows.Forms.SplitContainer splitContainer1;
        private System.Windows.Forms.PictureBox PB;
        private System.Windows.Forms.TreeView treeItems;
    }
}

Program.cs:
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace NiklasUlvinge.ChipsEater
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new Form1());
        }
    }
}

strom.cs
namespace NiklasUlvinge.ChipsEater
{
    struct Strom
    {
        public float l, r;

        public Strom(float left, float right)
        {
            l=left;
            r = right;
        }

        public static Strom operator +(Strom a, Strom b)
        {
            return new Strom(a.l + b.l, a.r + b.r);
        }

        public static bool operator ==(Strom a, Strom b)
        {
            if (a.l == b.l && a.r == b.r)
                return true;
            else
                return false;
        }
        public static bool operator !=(Strom a, Strom b)
        {
            return !(a == b);
        }
    }
}

the new item.cs file:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;

namespace NiklasUlvinge.ChipsEater
{
    abstract class Item
    {
        //var's
        public Item[][] input;
        public int x;
        public int y;

        public abstract Strom LeftOutput
        {
            get;
        }
        public abstract Strom RightOutput
        {
            get;
        }
        public abstract Point[] Snap
        {
            get;
        }

        protected Item(int X, int Y)
        {
            x = X;
            y = Y;
            input = new Item[1][];
        }

        //abstract funcs
        public abstract void function();
        public abstract void draw(Graphics g);
        //funcs
        public void addBothInput(int index, Item Input)
        {
            Input.addInput(1 - index, this);

            this.addInput(index, Input);
        }
        private void addInput(int index, Item Input)
        {
            index = input.Length & index;

            Item[] inp = input[index];

            Item[] titem;

            if (inp == null)
            {
                titem = new Item[1];
            }
            else
                titem = new Item[inp.Length];

            for (int i = 0; i < titem.Length - 1; i++)
            {
                titem[i] = inp[i];
            }
            titem[titem.Length - 1] = Input;
            input[index] = titem;
        }
        public Strom combinedInput(int index)
        {
            Strom r = new Strom(0, 0);
            if (input[index] == null)
                return new Strom(0, 0);
            else
            {
                for (int i = 0; i < input[index].Length; i++)
                {
                    if (index == 0)
                        r += input[index][i].LeftOutput;
                    else
                        r += input[index][i].RightOutput;
                }
                return r;
            }
        }

        //const
        protected Brush surf = Brushes.LightGray;
        protected Pen side = Pens.DarkGray;
        protected Pen loff = Pens.Black;
        protected Pen lon = Pens.Red;
    }

    class Null : Item
    {

        public override Strom LeftOutput
        {
            get
            {
                return new Strom(0, 0);
            }
        }
        public override Strom RightOutput
        {
            get
            {
                return new Strom(0, 0);
            }
        }
        public override Point[] Snap
        {
            get
            {
                return new Point[0];
            }
        }

        public Null(int X, int Y)
            : base(X, Y)
        {
        }

        public override void function()
        {
            throw new Exception("The method or operation is not implemented.");
        }
        public override void draw(Graphics g)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    }

    class Transistor : Item
    {
        protected float[] output;
        public Null theNull = new Null(-50, -50);


        public override Strom LeftOutput
        {
            get
            {
                return new Strom(0, 0);
            }
        }
        public override Strom RightOutput
        {
            get
            {
                return new Strom(0, 0);
            }
        }
        public override Point[] Snap
        {
            get
            {
                return new Point[3] {
                    new Point(x - 16, y - 1),
                    new Point(x + 3, y - 16),
                    new Point(x + 3, y + 16)};
            }
        }

        public Transistor(int X, int Y) : base(X, Y)
        {
            input = new Item[4][];
            output = new float[1];
        }

        public override void function()
        {
        }
        public override void draw(Graphics g)
        {
            IntPtr intp;
            //get the right image...
            if (combinedInput(0) == new Strom(0, 0))
                if (combinedInput(1) == new Strom(0, 0))
                    if (output[0] == 0)
                        intp = Properties.Resources.trans000.GetHbitmap();
                    else
                        intp = Properties.Resources.trans001.GetHbitmap();
                else
                    if (output[0] == 0)
                        intp = Properties.Resources.trans010.GetHbitmap();
                    else
                        intp = Properties.Resources.trans011.GetHbitmap();
            else
                if (combinedInput(1) == new Strom(0, 0))
                    if (output[0] == 0)
                        intp = Properties.Resources.trans100.GetHbitmap();
                    else
                        intp = Properties.Resources.trans101.GetHbitmap();
                else
                    if (output[0] == 0)
                        intp = Properties.Resources.trans110.GetHbitmap();
                    else
                        intp = Properties.Resources.trans111.GetHbitmap();

            g.DrawImage(Image.FromHbitmap(intp), x - Image.FromHbitmap(intp).Size.Width / 2, y - Image.FromHbitmap(intp).Size.Height / 2);
        }
    }

    class Cord : Item
    {
        public int x2, y2;
        public Null theNull = new Null(-50, -50);

        public override Strom LeftOutput
        {
            get
            {
                return combinedInput(1);
            }
        }
        public override Strom RightOutput
        {
            get
            {
                return combinedInput(0);
            }
        }
        public override Point[] Snap
        {
            get
            {
                return new Point[2] {
                    new Point(x, y),
                    new Point(x2, y2) };
            }
        }
        
        public Cord(int X1, int Y1)
            : base(X1, Y1)
        {
            input = new Item[2][];
        }

        public override void function()
        {
        }
        public override void draw(Graphics g)
        {
            g.DrawLine(combinedInput(0) == new Strom(0,0) ? loff : lon,
                x, y, x2, y2);
        }
        public override string ToString()
        {
            return "L: l" + combinedInput(1).l + " r" + combinedInput(1).l + "R: l" + combinedInput(0).l + " r" + combinedInput(0).l;
        }
    }

    class Battery : Item
    {
        public Null theNull = new Null(-50, -50);


        public override Strom LeftOutput
        {
            get
            {
                return new Strom(100,-100);
            }
        }
        public override Strom RightOutput
        {
            get
            {
                return new Strom(-100, 100);
            }
        }
        public override Point[] Snap
        {
            get
            {
                return new Point[2] {
                    new Point(x - 5, y),
                    new Point(x + 5, y) };
            }
        }

        public Battery(int X, int Y)
            : base(X, Y)
        {
            input = new Item[2][];
        }

        public override void function()
        {
        }
        public override void draw(Graphics g)
        {
            g.DrawLine(lon, x - 2, y - 10, x - 2, y + 10);
            g.DrawLine(lon, x + 2, y - 6, x + 2, y + 6);
            g.DrawLine(lon, x - 2, y, x - 5, y);
            g.DrawLine(lon, x + 2, y, x + 5, y);
        }
        public override string ToString()
        {
            return "L: l" + combinedInput(1).l + " r" + combinedInput(1).l + "R: l" + combinedInput(0).l + " r" + combinedInput(0).l;
        }
    }
}


Niklas Ulvinge aka IDK
QuestionNow, how to extract low nibble and high nibble from a byte? Pin
bouli3-Sep-05 3:15
bouli3-Sep-05 3:15 
AnswerRe: Now, how to extract low nibble and high nibble from a byte? Pin
Colin Angus Mackay3-Sep-05 3:21
Colin Angus Mackay3-Sep-05 3:21 
AnswerRe: Now, how to extract low nibble and high nibble from a byte? Pin
Guffa3-Sep-05 6:09
Guffa3-Sep-05 6:09 
QuestionPlease Heeeeeeeeelp: Problem with Pinvoke??? Pin
E6AD3-Sep-05 2:46
E6AD3-Sep-05 2:46 
Questionlooping statement Pin
Anonymous3-Sep-05 1:53
Anonymous3-Sep-05 1:53 
QuestionRe: looping statement Pin
Guffa3-Sep-05 2:10
Guffa3-Sep-05 2:10 
AnswerRe: looping statement Pin
Libor Tinka3-Sep-05 2:42
Libor Tinka3-Sep-05 2:42 
AnswerRe: looping statement Pin
Colin Angus Mackay3-Sep-05 3:23
Colin Angus Mackay3-Sep-05 3:23 
QuestionMy C++ MFC-app into a dll -&gt; to be used in .NET app&#8230; Pin
anderslundsgard3-Sep-05 1:25
anderslundsgard3-Sep-05 1:25 
QuestionHow to concatenate 2 nibbles in 1 byte? Pin
bouli3-Sep-05 1:22
bouli3-Sep-05 1:22 
AnswerRe: How to concatenate 2 nibbles in 1 byte? Pin
Guffa3-Sep-05 2:10
Guffa3-Sep-05 2:10 
GeneralRe: How to concatenate 2 nibbles in 1 byte? Pin
bouli3-Sep-05 2:11
bouli3-Sep-05 2:11 
AnswerRe: How to concatenate 2 nibbles in 1 byte? Pin
leppie3-Sep-05 2:11
leppie3-Sep-05 2:11 
GeneralRe: How to concatenate 2 nibbles in 1 byte? Pin
bouli3-Sep-05 2:12
bouli3-Sep-05 2:12 
AnswerRe: How to concatenate 2 nibbles in 1 byte? Pin
Anonymous3-Sep-05 2:13
Anonymous3-Sep-05 2:13 
GeneralRe: How to concatenate 2 nibbles in 1 byte? Pin
bouli3-Sep-05 2:16
bouli3-Sep-05 2:16 
QuestionNeed help! - accessing disposed object Pin
Libor Tinka3-Sep-05 0:35
Libor Tinka3-Sep-05 0:35 

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.