Renamed Class1 to BinLayoutView

This commit is contained in:
aj
2018-05-31 18:22:19 -04:00
parent 3fd5f336f0
commit c3f24df75e
4 changed files with 76 additions and 73 deletions

View File

@@ -0,0 +1,73 @@
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace CutToLength
{
class BinLayoutView : Control
{
public Bin Bin { get; set; }
private const int BorderPixels = 15;
private const int BinHeightPixels = 100;
private readonly HatchBrush hBrush = new HatchBrush(HatchStyle.DiagonalCross, Color.Pink, Color.Transparent);
public BinLayoutView()
{
SetStyle(ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (Bin == null)
return;
var displayWidth = Width - BorderPixels * 2.0f;
var maxHeight = Height - BorderPixels * 2.0f;
if (displayWidth <= 0) return;
if (maxHeight <= 0) return;
var displayHeight = maxHeight < BinHeightPixels ? maxHeight : BinHeightPixels;
var x = (Width - displayWidth) / 2.0f;
var y = (Height - displayHeight) / 2.0f;
var rect = new RectangleF(x, y, displayWidth, displayHeight);
var id = 1;
var scale = displayWidth / (float)Bin.Length;
if (Bin != null)
{
for (int i = 0; i < Bin.Items.Count; i++)
{
var item = Bin.Items[i];
var w = item.Length / Bin.Length * displayWidth;
var r = new RectangleF(x, y, (float)w, displayHeight);
e.Graphics.DrawRectangle(Pens.Blue, r.X, r.Y, r.Width, r.Height);
e.Graphics.DrawString(id++.ToString(), Font, Brushes.Blue, r, new StringFormat
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center
});
x += (float)item.Length * scale;
if (i < Bin.Items.Count - 1)
x += (float)Bin.Spacing;
}
}
var scrapRect = new RectangleF(x + 1, y, (float)Bin.RemainingLength * scale, displayHeight);
e.Graphics.FillRectangle(hBrush, scrapRect);
e.Graphics.DrawRectangle(Pens.Black, rect.X, rect.Y, rect.Width, rect.Height);
}
}
}

View File

@@ -1,70 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CutToLength
{
class Class1 : Control
{
public Bin Bin { get; set; }
private const int BorderPixels = 15;
private const int BinHeightPixels = 100;
public Class1()
{
SetStyle(ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
var displayWidth = Width - BorderPixels * 2.0f;
var maxHeight = Height - BorderPixels * 2.0f;
if (displayWidth <= 0) return;
if (maxHeight <= 0) return;
var displayHeight = maxHeight < BinHeightPixels ? maxHeight : BinHeightPixels;
var x = (Width - displayWidth) / 2.0f;
var y = (Height - displayHeight) / 2.0f;
var rect = new RectangleF(x, y, displayWidth, displayHeight);
var drawX = (float)x;
var id = 1;
var scale = displayWidth / Bin.Length;
var totalLength = 0.0;
if (Bin != null)
{
foreach (var item in Bin.Items)
{
var xc = item.Length
var w = item.Length / Bin.Length * displayWidth;
var r = new RectangleF(drawX, y, (float)w, displayHeight);
e.Graphics.DrawRectangle(Pens.Blue, r.X, r.Y, r.Width, r.Height);
e.Graphics.DrawString(id++.ToString(), Font, Brushes.Blue, r, new StringFormat
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center
});
drawX = r.Right;
}
}
var scrapRect = new RectangleF(drawX, y, rect.Right - drawX, displayHeight);
e.Graphics.FillRectangle(Brushes.Red, scrapRect);
e.Graphics.DrawRectangle(Pens.Black, rect.X, rect.Y, rect.Width, rect.Height);
}
}
}

View File

@@ -50,7 +50,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Class1.cs"> <Compile Include="BinLayoutView.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="Form1.cs"> <Compile Include="Form1.cs">

View File

@@ -36,7 +36,7 @@
this.remainingLengthDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.remainingLengthDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.utilizationDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.utilizationDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.binBindingSource = new System.Windows.Forms.BindingSource(this.components); this.binBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.class11 = new CutToLength.Class1(); this.class11 = new CutToLength.BinLayoutView();
this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.uIItemBindingSource = new System.Windows.Forms.BindingSource(this.components); this.uIItemBindingSource = new System.Windows.Forms.BindingSource(this.components);
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
@@ -160,7 +160,7 @@
#endregion #endregion
private System.Windows.Forms.DataGridView dataGridView1; private System.Windows.Forms.DataGridView dataGridView1;
private Class1 class11; private BinLayoutView class11;
private System.Windows.Forms.DataGridViewTextBoxColumn spacingDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn spacingDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn lengthDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn lengthDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn usedLengthDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn usedLengthDataGridViewTextBoxColumn;