我正在处理一个新项目。我有一个类可以将矩形绘制到 windows 窗体。我想把这个类嵌入到另一个类中。代码如下;
主代码将调用形状代码;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using sekilciz_uygulama;
namespace xml_test_v1
{
class Program
{
static void Main(string[] args)
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load("c:\\sw_xml_test_4.xml");
int rad=0;
string giris_text = Console.ReadLine().ToString();
Console.WriteLine(giris_text);
foreach(XmlNode node in xDoc.SelectNodes("network/switch"))
{
string ip_adress = node.SelectSingleNode("ip_adress").InnerText.ToString();
Console.WriteLine(ip_adress);
if (ip_adress.Contains(giris_text))
{
// call for shape code!!!
}
}}}}
创建形状的代码;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace sekilciz_uygulama
{
public class Sekilciz
{
public Rectangle[] skare;
private SolidBrush firca;
private int x,y, genislik, yukseklik;
public Sekilciz()
{
skare = new Rectangle[5];
firca = new SolidBrush(Color.Blue);
x = 500;
y = 200;
genislik= 100;
yukseklik =100;
for(int i=0; i< skare.Length;i++)
{
skare[i] = new Rectangle(x,y,genislik,yukseklik);
x-=150;
}
}
public void kareciz(Graphics duzlem)
{
foreach(Rectangle rec in skare)
{
duzlem.FillRectangle(firca,rec);
}
}
}
}