make a NetShape class for drawing simple shapes on networks. For making a background look like a map or something.
This commit is contained in:
parent
1453aa27be
commit
e9fe9095b6
@ -117,6 +117,7 @@
|
||||
</Compile>
|
||||
<Compile Include="NB.cs" />
|
||||
<Compile Include="NBSettings.cs" />
|
||||
<Compile Include="NetShape.cs" />
|
||||
<Compile Include="NetTest.cs" />
|
||||
<Compile Include="NetTestEditor.cs">
|
||||
<SubType>Form</SubType>
|
||||
|
@ -29,6 +29,7 @@ namespace EduNetworkBuilder
|
||||
finished //There was an appropriate reason this packet finished. It stopped
|
||||
}
|
||||
public enum VLANTagType { Tagged, Untagged, Forbidden }
|
||||
public enum NetShapeType { none, circle, rectangle, filled_circle, filled_rectangle }
|
||||
public enum LinkType { normal, wireless, broken }
|
||||
public enum PacketType { none, ping_request, ping_answer, arp_request, arp_answer, dhcp_request,
|
||||
dhcp_answer, vpn_packet, tun_packet, tracert_request, tracert_reply }
|
||||
|
88
EduNetworkBuilder/NetShape.cs
Normal file
88
EduNetworkBuilder/NetShape.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Drawing;
|
||||
using System.Xml;
|
||||
|
||||
namespace EduNetworkBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// For drawing shapes on a network. Rectangles, circles. Filled or not
|
||||
/// </summary>
|
||||
public class NetShape
|
||||
{
|
||||
public NetShapeType MyShape = NetShapeType.none;
|
||||
public Rectangle InArea;
|
||||
public Color WhatColor = Color.Empty;
|
||||
|
||||
public NetShape(NetShapeType What, Rectangle Where, Color color)
|
||||
{
|
||||
MyShape = What;
|
||||
InArea = Where;
|
||||
WhatColor = color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw the specified shape on the image
|
||||
/// </summary>
|
||||
/// <param name="baseImage"></param>
|
||||
public void Draw(Image baseImage)
|
||||
{
|
||||
Graphics G = Graphics.FromImage(baseImage);
|
||||
Pen coloredPen = new Pen(WhatColor);
|
||||
Brush coloredBrush = new SolidBrush(WhatColor);
|
||||
switch(MyShape)
|
||||
{
|
||||
case NetShapeType.circle:
|
||||
G.DrawEllipse(coloredPen, InArea);
|
||||
break;
|
||||
case NetShapeType.filled_circle:
|
||||
G.FillEllipse(coloredBrush,InArea);
|
||||
break;
|
||||
case NetShapeType.rectangle:
|
||||
G.DrawRectangle(coloredPen, InArea);
|
||||
break;
|
||||
case NetShapeType.filled_rectangle:
|
||||
G.FillRectangle(coloredBrush, InArea);
|
||||
break;
|
||||
}
|
||||
G.Dispose();
|
||||
}
|
||||
|
||||
public void Load(XmlNode theNode)
|
||||
{
|
||||
foreach (XmlNode Individual in theNode.ChildNodes)
|
||||
{
|
||||
XmlNodeType myNodetype = Individual.NodeType;
|
||||
if (myNodetype == XmlNodeType.Element)
|
||||
{
|
||||
switch (Individual.Name.ToLower())
|
||||
{
|
||||
case "what":
|
||||
MyShape = NB.TryParseEnum<NetShapeType>(Individual.InnerText, NetShapeType.none);
|
||||
break;
|
||||
case "where":
|
||||
RectangleConverter converter = new RectangleConverter();
|
||||
InArea = (Rectangle)converter.ConvertFromString(Individual.InnerText);
|
||||
break;
|
||||
case "color":
|
||||
WhatColor = Color.FromName(Individual.InnerText);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Save(XmlWriter writer)
|
||||
{
|
||||
writer.WriteStartElement("shape");
|
||||
writer.WriteElementString("what", MyShape.ToString());
|
||||
RectangleConverter converter = new RectangleConverter();
|
||||
writer.WriteElementString("where", converter.ConvertToString(InArea));
|
||||
writer.WriteElementString("color", WhatColor.ToString());
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user