110,536
社区成员
发帖
与我相关
我的任务
分享
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Paint += Form1_Paint;
}
void Form1_Paint(object sender, PaintEventArgs e)
{
Draw(e.Graphics, 80, 100, 340);
Draw(e.Graphics, 80, 200, 30);
Draw(e.Graphics, 80, 300, 30);
}
public void Draw(Graphics g, int x, int y, int angle)
{
var width = 30;
var space = 10;
Pen pen = new Pen(Color.Red, 1);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
for (var i = 0; i < 15; i++)
{
if (i == 10)
{
var positionX = i * (space + width) + x;
g.TranslateTransform(positionX, y); // 先平移坐标原点
g.RotateTransform(angle); // 再旋转
}
Rectangle rec = new Rectangle();
// 旋转后x,y的坐标要相对新原点的(0,0)来计算,也就是拐弯处的(x,y)
rec.Y = i >= 10 ? 0 : y;
rec.X = (i >= 10 ? i - 10 : i) * (space + width) + (i >= 10 ? space : x);
rec.Width = width;
rec.Height = width;
g.DrawRectangle(pen, rec);
}
g.ResetTransform();
}
}
// 画底图
private void DrawBaseMap(Rectangle rect, Image img, float angle, Rectangle turnRect)
{
Graphics graphics = this.pictureBoxBack.CreateGraphics();
//使绘图质量最高,即消除锯齿
//graphics.SmoothingMode = SmoothingMode.AntiAlias;
//graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
//graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.SmoothingMode = SmoothingMode.HighQuality; //高质量
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; //高像素偏移质量
if (angle > 0)
{
graphics.TranslateTransform(turnRect.X, turnRect.Y);
graphics.RotateTransform(angle);
rect = new Rectangle(rect.X - turnRect.X, rect.Y, rect.Width, rect.Height);
}
graphics.DrawImage(img, rect);
graphics.Dispose();
}
int UpCount = 0;
int DownCount = 0;
Rectangle UpTurnRect = new Rectangle();
Rectangle DownTurnRect = new Rectangle();
private void UpdataStorage(Rectangle upZone, Rectangle downZone, List<Storage> storages)
{
List<Storage> upstorage = storages.FindAll(delegate(Storage s)
{
return s.Position == StoragePosition.UP;
});
int storeCount = upstorage.Count;
int count = 1;
int offset = 10;
float angle = 0;
if (0 != storeCount)
{
int startX = upZone.Right - offset;
int startY_UP = upZone.Top;
//double btnHeight = upZone.Height;
int btnWidth = (upZone.Width - offset) / storeCount;
int btnHeight = btnWidth;
foreach (Storage s in upstorage)
{
Bitmap b = null;
string des = string.Empty;
switch (s.Status)
{
case StorageStatus.Empty:
b = new Bitmap(Properties.Resources.map_empty);
des = "空闲";
break;
case StorageStatus.Full:
b = new Bitmap(Properties.Resources.map_full);
des = "占用";
break;
case StorageStatus.Working:
b = new Bitmap(Properties.Resources.map_working);
des = "作业中";
break;
}
Rectangle rect = new Rectangle(startX - count * btnWidth,startY_UP,btnWidth - 4,btnHeight);
if (s.IsTurn)
{
if (0 == UpCount)
UpTurnRect = rect;
angle = 40;
UpCount++;
}
else
angle = 0;
DrawBaseMap(rect, b, angle, UpTurnRect);
count++;
}
}
List<Storage> downstorage = storages.FindAll(delegate(Storage s)
{
return s.Position == StoragePosition.Down;
});
count = 1;
storeCount = downstorage.Count;
if (0 != storeCount)
{
int startX = downZone.Right - offset;
int startY_Down = downZone.Top;
//int btnHeight = downZone.Height;
int btnWidth = (downZone.Width - offset) / storeCount;
int btnHeight = btnWidth;
foreach (Storage s in downstorage)
{
Bitmap b = null;
string des = string.Empty;
switch (s.Status)
{
case StorageStatus.Empty:
b = new Bitmap(Properties.Resources.map_empty);
des = "空闲";
break;
case StorageStatus.Full:
b = new Bitmap(Properties.Resources.map_full);
des = "占用";
break;
case StorageStatus.Working:
b = new Bitmap(Properties.Resources.map_working);
des = "作业中";
break;
}
Rectangle rect = new Rectangle(startX - count * btnWidth, startY_Down, btnWidth - 4, btnHeight);
if (s.IsTurn)
{
if (0 == DownCount)
DownTurnRect = rect;
angle = 40;
DownCount++;
}
else
angle = 0;
DrawBaseMap(rect, b, angle, DownTurnRect);
count++;
}
}
}