public PictureBoxWithReference ModifyPicture(Image image, int x, int y, string value = null)// Adds Labels to images, Changes event handlers and changes the image themselves
        {
            int index = x * numRows + y;
            PictureBoxWithReference PanelToModify = (PictureBoxWithReference)ComponentList.Controls[index];

            ModifyComponentImage(image, value, ref PanelToModify);
            return(PanelToModify);
        }
        public void DrawSection(GeneralComponent component, int StartingX, int StartingY)
        {
            if (component.GetType() == 'b')
            {
                PictureBoxWithReference PictureBoxImage = ModifyPicture(Resources.Resistor, StartingX, StartingY, PrefixDouble(component.GetResistance(), 'Ω')); // This is the bit that draws the resistors based on positions worked out by the parrallel and series bits
                PictureBoxImage.AssosiatedComponent = component;
            }
            else if (component.GetType() == 'p')
            {
                List <GeneralComponent> ListForDrawing = component.GetCopyOfSubList();// Gets a copy of the current circuit from the PhysicsEngine Module

                // Starts From Current position and starts to draw a parrallel component
                // Draws the bottom line first as if it dosn't, It ovverides TOPRIGHTLEFT
                DrawBottomLine(StartingX + 1, StartingY, StartingX + component.xsize - 1);// If this wasn't there there would be gaps
                ModifyPicture(Resources.TopRightLeft, StartingX, StartingY).AssosiatedComponent = component;
                ModifyPicture(Resources.TopRightLeft, StartingX + component.xsize - 1, StartingY).AssosiatedComponent = component;


                DrawSection(ListForDrawing[0], StartingX + 1, StartingY);

                //Starts going through the vertical list of components to be drawn in parrallel
                for (int i = 1; i < ListForDrawing.Count; i++)
                {
                    //If the y Size of The Component that Has to be drawn previously is larger than 1, extra extentions are drawn
                    for (int x = 1; x < ListForDrawing[i - 1].ysize; x++)
                    {
                        StartingY--;                                                                                                 //Moves the Y value up
                        ModifyPicture(Resources.Down, StartingX, StartingY).AssosiatedComponent = component;                         //Draws a vertical Straight Line
                        ModifyPicture(Resources.Down, StartingX + (component.xsize - 1), StartingY).AssosiatedComponent = component; //Draws the corresponding line on the other side
                    }
                    StartingY--;                                                                                                     //Itterates the Y one more
                    if (i == ListForDrawing.Count - 1)                                                                               // If this is the last component in the List, Draw a different joining wire
                    {
                        ModifyPicture(Resources.RightBottom, StartingX, StartingY).AssosiatedComponent = component;
                        ModifyPicture(Resources.LeftBottom, StartingX + (component.xsize - 1), StartingY).AssosiatedComponent = component;
                    }
                    else
                    {
                        ModifyPicture(Resources.TopRightBottom, StartingX, StartingY).AssosiatedComponent = component;//If not then Just branch for the next component
                        ModifyPicture(Resources.TopLeftBottom, StartingX + (component.xsize - 1), StartingY).AssosiatedComponent = component;
                    }
                    DrawBottomLine(StartingX + 1, StartingY, StartingX + component.xsize - 1);
                    DrawSection(ListForDrawing[i], StartingX + 1, StartingY);// Goes up the parrallel component and draws the next section
                }
            }
            else if (component.GetType() == 's')
            {
                List <GeneralComponent> ListForDrawing = component.GetCopyOfSubList(); // Gets a copy of the current circuit from the PhysicsEngine Module
                foreach (GeneralComponent subComponent in ListForDrawing)              // Goes through each series component
                {
                    if (subComponent.GetName() != "IntRes")
                    {
                        DrawSection(subComponent, StartingX, StartingY); //Draws each one
                        StartingX += subComponent.xsize;                 // Increments The starting X so it is in the correct position for next component.
                    }
                }
            }
        }
        public void ImageResizer(object sender, EventArgs e) // Resizes the text under a component so it is consistant (Dosn't really work as intended)
        {
            PictureBoxWithReference ToBeResized = sender as PictureBoxWithReference;

            if (ToBeResized != null)
            {
                int height = ToBeResized.Height;
                int width  = ToBeResized.Width;
                ToBeResized.Controls[0].Height = Convert.ToInt32(height * 0.3);// Scales the label size a bit arbitarily
                ToBeResized.Controls[0].Width  = Convert.ToInt32(width * 0.5);
            }
        }
Example #4
0
        public override void ModifyComponentImage(Image image, string AssignedValue, ref PictureBoxWithReference ImagePictureBox)
        {
            ImagePictureBox.Controls.Clear();
            ImagePictureBox.Image   = image;
            ImagePictureBox.Resize -= ImageResizer; // This removes any previous event handler bc for some reason having more than one breaks stuff
            if (AssignedValue != null)              // If the Image has data that needs displaying e.g. voltage or current or resistance A label is added to the list of controls of the picture
            {
                Label ValueOfComponent = new Label();
                ValueOfComponent.Text      = AssignedValue;
                ValueOfComponent.BackColor = Color.Transparent; // Transparent so underneath component can be seen
                ValueOfComponent.Dock      = DockStyle.Fill;
                ValueOfComponent.TextAlign = ContentAlignment.MiddleCenter;
                ValueOfComponent.Click    += new EventHandler(ComponentClick);
                ImagePictureBox.Controls.Add(ValueOfComponent);

                ImagePictureBox.Resize += ImageResizer; // Image Resizer is the event handler I created to make sure everything stays the right size
            }
        }