09/13일 작

This commit is contained in:
chikyun.kim
2018-09-14 11:43:45 +09:00
parent 235be47d42
commit 695d53aae7
172 changed files with 33045 additions and 30763 deletions

View File

@@ -1,52 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StaffLayoutCtl
{
public partial class grid
{
public class CGrid
{
public System.Drawing.RectangleF Rect { get; set; }
public int Row { get; set; }
public int Col { get; set; }
public int IDX { get; set; }
public CGrid(int idx_)
{
this.IDX = idx_;
}
}
public class CItem
{
public System.Drawing.RectangleF Rect { get; set; }
public Boolean Select { get; set; }
public int Row { get; set; }
public int Col { get; set; }
public int ColSpan { get; set; }
public int RowSpan { get; set; }
public string Text { get; set; }
public System.Drawing.Color bgColor { get; set; }
public System.Drawing.Color fgColor { get; set; }
public CItem()
{
if (ColSpan == 0) ColSpan = 1;
if (RowSpan == 0) RowSpan = 1;
bgColor = System.Drawing.Color.White;
fgColor = System.Drawing.Color.Black;
}
public CItem(int r,int c, int rs=1,int cs=1,string text="",int bg=-1,int fg=-1)
{
this.Row = r;
this.Col = c;
this.RowSpan = rs;
this.ColSpan = cs;
this.Text = text;
if (bg != -1) this.bgColor = System.Drawing.Color.FromArgb(bg);
if (fg != -1) this.fgColor = System.Drawing.Color.FromArgb(fg);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StaffLayoutCtl
{
public partial class grid
{
public class CGrid
{
public System.Drawing.RectangleF Rect { get; set; }
public int Row { get; set; }
public int Col { get; set; }
public int IDX { get; set; }
public CGrid(int idx_)
{
this.IDX = idx_;
}
}
public class CItem
{
public System.Drawing.RectangleF Rect { get; set; }
public Boolean Select { get; set; }
public int Row { get; set; }
public int Col { get; set; }
public int ColSpan { get; set; }
public int RowSpan { get; set; }
public string Text { get; set; }
public System.Drawing.Color bgColor { get; set; }
public System.Drawing.Color fgColor { get; set; }
public CItem()
{
if (ColSpan == 0) ColSpan = 1;
if (RowSpan == 0) RowSpan = 1;
bgColor = System.Drawing.Color.White;
fgColor = System.Drawing.Color.Black;
}
public CItem(int r,int c, int rs=1,int cs=1,string text="",int bg=-1,int fg=-1)
{
this.Row = r;
this.Col = c;
this.RowSpan = rs;
this.ColSpan = cs;
this.Text = text;
if (bg != -1) this.bgColor = System.Drawing.Color.FromArgb(bg);
if (fg != -1) this.fgColor = System.Drawing.Color.FromArgb(fg);
}
}
}
}

View File

@@ -1,36 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 어셈블리의 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
[assembly: AssemblyTitle("StaffLayoutCtl")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StaffLayoutCtl")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하십시오.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("f2c91e2c-49ab-4997-987a-d7e455279f27")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 버전이 자동으로
// 지정되도록 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 어셈블리의 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
[assembly: AssemblyTitle("StaffLayoutCtl")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StaffLayoutCtl")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하십시오.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("f2c91e2c-49ab-4997-987a-d7e455279f27")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 버전이 자동으로
// 지정되도록 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -1,63 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B832738C-74DD-4CE2-8A29-98D0BCBB9EA4}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>StaffLayoutCtl</RootNamespace>
<AssemblyName>StaffLayoutCtl</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="grid.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="grid.Designer.cs">
<DependentUpon>grid.cs</DependentUpon>
</Compile>
<Compile Include="Item.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B832738C-74DD-4CE2-8A29-98D0BCBB9EA4}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>StaffLayoutCtl</RootNamespace>
<AssemblyName>StaffLayoutCtl</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="grid.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="grid.Designer.cs">
<DependentUpon>grid.cs</DependentUpon>
</Compile>
<Compile Include="Item.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -1,36 +1,36 @@
namespace StaffLayoutCtl
{
partial class grid
{
/// <summary>
/// 필수 디자이너 변수입니다.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 사용 중인 모든 리소스를 정리합니다.
/// </summary>
/// <param name="disposing">관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}
namespace StaffLayoutCtl
{
partial class grid
{
/// <summary>
/// 필수 디자이너 변수입니다.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 사용 중인 모든 리소스를 정리합니다.
/// </summary>
/// <param name="disposing">관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

View File

@@ -1,336 +1,336 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace StaffLayoutCtl
{
public partial class grid : Control
{
public Boolean DeveloperMode = true;
private Point GridCount = new Point(30, 20);
private CGrid[,] gridrect = null;
public grid()
{
InitializeComponent();
// Set Optimized Double Buffer to reduce flickering
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
// Redraw when resized
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.Resize += arLabel_Resize;
this.MouseDown += grid_MouseDown;
this.MouseMove += grid_MouseMove;
this.MouseUp += grid_MouseUp;
gridrect = new CGrid[GridCount.X, GridCount.Y];
}
void grid_MouseUp(object sender, MouseEventArgs e)
{
Boolean bOK = false;
if(mousedn && mouseDrag && selectindex != -1 && diffrect != RectangleF.Empty)
{
if(Math.Abs(mousediff.X) >= 10 && Math.Abs(mousediff.Y) >= 10)
{
//좌측코드가 속한 row,col 값으로 이동한다.
for(int i = 0; i<= gridrect.GetUpperBound(0);i++)
{
for (int j = 0; j <= gridrect.GetUpperBound(1); j++)
{
var grid = this.gridrect[i, j];
if(grid.Rect.Contains( diffrect.Location ))
{
var item = this.Items[selectindex];
item.Row = grid.Row;
item.Col = grid.Col;
bOK = true;
break;
}
}
if (bOK) break;
}
}
}
mousedn = false;
mouseDrag = false;
this.Invalidate();
}
void grid_MouseMove(object sender, MouseEventArgs e)
{
mousepos = e.Location;
if (mousedn) mouseDrag = true;
else mouseDrag = false;
//선택개체 위로 오면 마우스 모양을 변경한다.
if (selectindex < 0)
{
if (this.Cursor != Cursors.Arrow)
{
this.Cursor = Cursors.Arrow;
this.Invalidate();
}
}
else
{
var item = Items[selectindex];
//중앙부에 있다면 이동형 핸드를
//외곽에 있다면 크기 조정용 을 표시한다.
//크기조정용 영역을 게산한다.
RectangleF rectt = new RectangleF(item.Rect.Left, item.Rect.Top - 10, item.Rect.Width, 20);
RectangleF rectb = new RectangleF(item.Rect.Left, item.Rect.Bottom - 10, item.Rect.Height, 20);
RectangleF rectl = new RectangleF(item.Rect.Left - 10, item.Rect.Top, 20, item.Rect.Height);
RectangleF rectr = new RectangleF(item.Rect.Right - 10, item.Rect.Top, 20, item.Rect.Height);
if (rectt.Contains(e.Location))
{
if (this.Cursor != Cursors.PanNorth)
{
this.Cursor = Cursors.PanNorth;
this.Invalidate();
}
}
else if (rectb.Contains(e.Location))
{
if (this.Cursor != Cursors.PanSouth)
{
this.Cursor = Cursors.PanSouth;
this.Invalidate();
}
}
else if (rectl.Contains(e.Location))
{
if (this.Cursor != Cursors.PanWest)
{
this.Cursor = Cursors.PanWest;
this.Invalidate();
}
}
else if (rectr.Contains(e.Location))
{
if (this.Cursor != Cursors.PanEast)
{
this.Cursor = Cursors.PanEast;
this.Invalidate();
}
}
else if (item.Rect.Contains(e.Location))
{
if (this.Cursor != Cursors.Hand)
{
this.Cursor = Cursors.Hand;
this.Invalidate();
}
}
else
{
if (this.Cursor != Cursors.Arrow)
{
this.Cursor = Cursors.Arrow;
this.Invalidate();
}
else
{
if (mousedn)
{
}
}
}
this.Invalidate(); //화면이 업데이트되도록 함
}
}
Boolean mouseDrag = false;
Boolean mousedn = false;
Point mousednpos = Point.Empty;
Point mousepos = Point.Empty;
int selectindex = -1;
void grid_MouseDown(object sender, MouseEventArgs e)
{
mousedn = true;
//save down point
mousednpos = e.Location;
//선택된 아이템을 찾아야한다.
Boolean selected = false;
int r = 0;
int c = 0;
for (int i = 0; i < Items.Count; i++)
{
var item = Items[i];
if (item.Rect.Contains(e.Location))
{
selectindex = i;
selected = true;
r = item.Row;
c = item.Col;
selectRect = item.Rect;
//다른 아이템의 선택을 해제한다.
Console.WriteLine(string.Format("select item : {0}/{1}", item.Row, item.Col));
break;
}
}
if (selected)
{
foreach (var item in Items)
{
if (item.Row == r && item.Col == c) item.Select = true;
else item.Select = false;
}
}
else
{
selectindex = -1;
var selitem = Items.Where(t => t.Select);
foreach (var item in selitem)
item.Select = false;
}
Invalidate();
}
void arLabel_Resize(object sender, EventArgs e)
{
Make_Grid();
Invalidate();
}
Point mousediff = Point.Empty;
RectangleF diffrect = RectangleF.Empty;
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
Draw_Grid(pe.Graphics);
Draw_Item(pe.Graphics);
if (mouseDrag && mousedn && selectindex != -1 && mousednpos != Point.Empty)
{
mousediff = new Point(mousepos.X - mousednpos.X, mousepos.Y - mousednpos.Y);
//이동영역을
diffrect = new RectangleF(selectRect.Left + mousediff.X,
selectRect.Top + mousediff.Y,
selectRect.Width, selectRect.Height);
using(SolidBrush sb = new SolidBrush(Color.FromArgb(100,Color.Gray)))
{
pe.Graphics.FillRectangle(sb, diffrect);
}
pe.Graphics.DrawRectangle(Pens.DimGray, diffrect.Left, diffrect.Top, diffrect.Width, diffrect.Height);
}
Draw_Debug(pe.Graphics);
}
void Draw_Debug(Graphics g)
{
System.Text.StringBuilder sb = new StringBuilder();
sb.AppendLine("diff = " + mousediff.ToString());
sb.AppendLine("drag : " + mouseDrag.ToString());
sb.AppendLine("mouse down : " + mousedn.ToString() + ", " + mousednpos.ToString());
sb.AppendLine("mouse pos : " + this.mousepos.ToString());
sb.AppendLine("select index : " + this.selectindex.ToString() + "," + this.selectRect.ToString());
sb.AppendLine("sel rect : " + this.selectRect.ToString());
sb.AppendLine("diff rect : " + this.diffrect.ToString());
sb.AppendLine("cell size : " + cellSize.ToString());
using (Font f = new Font("Consolas", 20f))
{
g.DrawString(sb.ToString(), f, Brushes.Black, 50 - 1, 50 - 1);
g.DrawString(sb.ToString(), f, Brushes.Black, 50 - 1, 50 + 1);
g.DrawString(sb.ToString(), f, Brushes.Black, 50 + 1, 50 - 1);
g.DrawString(sb.ToString(), f, Brushes.Black, 50 + 1, 50 + 1);
g.DrawString(sb.ToString(), f, Brushes.Red, 50, 50);
}
}
public List<CItem> Items = new List<CItem>();
RectangleF selectRect = RectangleF.Empty;
SizeF cellSize = SizeF.Empty;
void Draw_Item(Graphics g)
{
if (DeveloperMode)
{
//demo item
Items.Clear();
Items.Add(new CItem(r: 1, c: 1, rs: 2, cs: 2, text: "김치균", bg: Color.White.ToArgb()));
Items.Add(new CItem(4, 4, 1, 1, "박성민"));
Items.Add(new CItem(6, 6, 10, 3, "고진일"));
Items.Add(new CItem(7, 7, 2, 2, "테스트"));
Items[1].Select = true;
}
int idx = 0;
foreach (var item in Items)
{
float x = item.Col * cellSize.Width;
float y = item.Row * cellSize.Height;
float w = item.ColSpan * cellSize.Width;
float h = item.RowSpan * cellSize.Height;
RectangleF rectf = new RectangleF(x, y, w, h);
g.FillRectangle(Brushes.Yellow, rectf);
item.Rect = rectf;
if (item.Select)
{
g.DrawRectangle(new Pen(Color.Blue, 4f),
rectf.Left, rectf.Top, rectf.Width, rectf.Height);
//크기조정을 위한 좌우 화살표가 필요하다.
}
string data = idx.ToString();
if (item.Text != "'") data = item.Text;
g.DrawString(data + item.Select.ToString(), this.Font, Brushes.Black, x, y);
idx += 1;
}
}
void Make_Grid()
{
float gw = DisplayRectangle.Width / GridCount.Y;
float gh = DisplayRectangle.Height / GridCount.X;
cellSize = new SizeF(gw, gh);
for (int i = 0; i < GridCount.X; i++)
{
for (int j = 0; j < GridCount.Y; j++)
{
int idx = (i * GridCount.Y) + j;
RectangleF rect = new RectangleF(j * gw, i * gh, gw, gh); ;
this.gridrect[i, j] = new CGrid(idx);
this.gridrect[i, j].Rect = rect;
this.gridrect[i, j].Row = i;
this.gridrect[i, j].Col = j;
}
}
}
void Draw_Grid(Graphics g)
{
if(gridrect[0,0]== null) Make_Grid();
for (int i = 0; i <= gridrect.GetUpperBound(0); i++)
{
for (int j = 0; j <= gridrect.GetUpperBound(1); j++)
{
var grid = this.gridrect[i, j];
g.DrawRectangle(Pens.Black, grid.Rect.Left, grid.Rect.Top, grid.Rect.Width, grid.Rect.Height);
g.DrawString(grid.IDX.ToString(), this.Font, Brushes.Blue, grid.Rect.Left, grid.Rect.Top);
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace StaffLayoutCtl
{
public partial class grid : Control
{
public Boolean DeveloperMode = true;
private Point GridCount = new Point(30, 20);
private CGrid[,] gridrect = null;
public grid()
{
InitializeComponent();
// Set Optimized Double Buffer to reduce flickering
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
// Redraw when resized
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.Resize += arLabel_Resize;
this.MouseDown += grid_MouseDown;
this.MouseMove += grid_MouseMove;
this.MouseUp += grid_MouseUp;
gridrect = new CGrid[GridCount.X, GridCount.Y];
}
void grid_MouseUp(object sender, MouseEventArgs e)
{
Boolean bOK = false;
if(mousedn && mouseDrag && selectindex != -1 && diffrect != RectangleF.Empty)
{
if(Math.Abs(mousediff.X) >= 10 && Math.Abs(mousediff.Y) >= 10)
{
//좌측코드가 속한 row,col 값으로 이동한다.
for(int i = 0; i<= gridrect.GetUpperBound(0);i++)
{
for (int j = 0; j <= gridrect.GetUpperBound(1); j++)
{
var grid = this.gridrect[i, j];
if(grid.Rect.Contains( diffrect.Location ))
{
var item = this.Items[selectindex];
item.Row = grid.Row;
item.Col = grid.Col;
bOK = true;
break;
}
}
if (bOK) break;
}
}
}
mousedn = false;
mouseDrag = false;
this.Invalidate();
}
void grid_MouseMove(object sender, MouseEventArgs e)
{
mousepos = e.Location;
if (mousedn) mouseDrag = true;
else mouseDrag = false;
//선택개체 위로 오면 마우스 모양을 변경한다.
if (selectindex < 0)
{
if (this.Cursor != Cursors.Arrow)
{
this.Cursor = Cursors.Arrow;
this.Invalidate();
}
}
else
{
var item = Items[selectindex];
//중앙부에 있다면 이동형 핸드를
//외곽에 있다면 크기 조정용 을 표시한다.
//크기조정용 영역을 게산한다.
RectangleF rectt = new RectangleF(item.Rect.Left, item.Rect.Top - 10, item.Rect.Width, 20);
RectangleF rectb = new RectangleF(item.Rect.Left, item.Rect.Bottom - 10, item.Rect.Height, 20);
RectangleF rectl = new RectangleF(item.Rect.Left - 10, item.Rect.Top, 20, item.Rect.Height);
RectangleF rectr = new RectangleF(item.Rect.Right - 10, item.Rect.Top, 20, item.Rect.Height);
if (rectt.Contains(e.Location))
{
if (this.Cursor != Cursors.PanNorth)
{
this.Cursor = Cursors.PanNorth;
this.Invalidate();
}
}
else if (rectb.Contains(e.Location))
{
if (this.Cursor != Cursors.PanSouth)
{
this.Cursor = Cursors.PanSouth;
this.Invalidate();
}
}
else if (rectl.Contains(e.Location))
{
if (this.Cursor != Cursors.PanWest)
{
this.Cursor = Cursors.PanWest;
this.Invalidate();
}
}
else if (rectr.Contains(e.Location))
{
if (this.Cursor != Cursors.PanEast)
{
this.Cursor = Cursors.PanEast;
this.Invalidate();
}
}
else if (item.Rect.Contains(e.Location))
{
if (this.Cursor != Cursors.Hand)
{
this.Cursor = Cursors.Hand;
this.Invalidate();
}
}
else
{
if (this.Cursor != Cursors.Arrow)
{
this.Cursor = Cursors.Arrow;
this.Invalidate();
}
else
{
if (mousedn)
{
}
}
}
this.Invalidate(); //화면이 업데이트되도록 함
}
}
Boolean mouseDrag = false;
Boolean mousedn = false;
Point mousednpos = Point.Empty;
Point mousepos = Point.Empty;
int selectindex = -1;
void grid_MouseDown(object sender, MouseEventArgs e)
{
mousedn = true;
//save down point
mousednpos = e.Location;
//선택된 아이템을 찾아야한다.
Boolean selected = false;
int r = 0;
int c = 0;
for (int i = 0; i < Items.Count; i++)
{
var item = Items[i];
if (item.Rect.Contains(e.Location))
{
selectindex = i;
selected = true;
r = item.Row;
c = item.Col;
selectRect = item.Rect;
//다른 아이템의 선택을 해제한다.
Console.WriteLine(string.Format("select item : {0}/{1}", item.Row, item.Col));
break;
}
}
if (selected)
{
foreach (var item in Items)
{
if (item.Row == r && item.Col == c) item.Select = true;
else item.Select = false;
}
}
else
{
selectindex = -1;
var selitem = Items.Where(t => t.Select);
foreach (var item in selitem)
item.Select = false;
}
Invalidate();
}
void arLabel_Resize(object sender, EventArgs e)
{
Make_Grid();
Invalidate();
}
Point mousediff = Point.Empty;
RectangleF diffrect = RectangleF.Empty;
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
Draw_Grid(pe.Graphics);
Draw_Item(pe.Graphics);
if (mouseDrag && mousedn && selectindex != -1 && mousednpos != Point.Empty)
{
mousediff = new Point(mousepos.X - mousednpos.X, mousepos.Y - mousednpos.Y);
//이동영역을
diffrect = new RectangleF(selectRect.Left + mousediff.X,
selectRect.Top + mousediff.Y,
selectRect.Width, selectRect.Height);
using(SolidBrush sb = new SolidBrush(Color.FromArgb(100,Color.Gray)))
{
pe.Graphics.FillRectangle(sb, diffrect);
}
pe.Graphics.DrawRectangle(Pens.DimGray, diffrect.Left, diffrect.Top, diffrect.Width, diffrect.Height);
}
Draw_Debug(pe.Graphics);
}
void Draw_Debug(Graphics g)
{
System.Text.StringBuilder sb = new StringBuilder();
sb.AppendLine("diff = " + mousediff.ToString());
sb.AppendLine("drag : " + mouseDrag.ToString());
sb.AppendLine("mouse down : " + mousedn.ToString() + ", " + mousednpos.ToString());
sb.AppendLine("mouse pos : " + this.mousepos.ToString());
sb.AppendLine("select index : " + this.selectindex.ToString() + "," + this.selectRect.ToString());
sb.AppendLine("sel rect : " + this.selectRect.ToString());
sb.AppendLine("diff rect : " + this.diffrect.ToString());
sb.AppendLine("cell size : " + cellSize.ToString());
using (Font f = new Font("Consolas", 20f))
{
g.DrawString(sb.ToString(), f, Brushes.Black, 50 - 1, 50 - 1);
g.DrawString(sb.ToString(), f, Brushes.Black, 50 - 1, 50 + 1);
g.DrawString(sb.ToString(), f, Brushes.Black, 50 + 1, 50 - 1);
g.DrawString(sb.ToString(), f, Brushes.Black, 50 + 1, 50 + 1);
g.DrawString(sb.ToString(), f, Brushes.Red, 50, 50);
}
}
public List<CItem> Items = new List<CItem>();
RectangleF selectRect = RectangleF.Empty;
SizeF cellSize = SizeF.Empty;
void Draw_Item(Graphics g)
{
if (DeveloperMode)
{
//demo item
Items.Clear();
Items.Add(new CItem(r: 1, c: 1, rs: 2, cs: 2, text: "김치균", bg: Color.White.ToArgb()));
Items.Add(new CItem(4, 4, 1, 1, "박성민"));
Items.Add(new CItem(6, 6, 10, 3, "고진일"));
Items.Add(new CItem(7, 7, 2, 2, "테스트"));
Items[1].Select = true;
}
int idx = 0;
foreach (var item in Items)
{
float x = item.Col * cellSize.Width;
float y = item.Row * cellSize.Height;
float w = item.ColSpan * cellSize.Width;
float h = item.RowSpan * cellSize.Height;
RectangleF rectf = new RectangleF(x, y, w, h);
g.FillRectangle(Brushes.Yellow, rectf);
item.Rect = rectf;
if (item.Select)
{
g.DrawRectangle(new Pen(Color.Blue, 4f),
rectf.Left, rectf.Top, rectf.Width, rectf.Height);
//크기조정을 위한 좌우 화살표가 필요하다.
}
string data = idx.ToString();
if (item.Text != "'") data = item.Text;
g.DrawString(data + item.Select.ToString(), this.Font, Brushes.Black, x, y);
idx += 1;
}
}
void Make_Grid()
{
float gw = DisplayRectangle.Width / GridCount.Y;
float gh = DisplayRectangle.Height / GridCount.X;
cellSize = new SizeF(gw, gh);
for (int i = 0; i < GridCount.X; i++)
{
for (int j = 0; j < GridCount.Y; j++)
{
int idx = (i * GridCount.Y) + j;
RectangleF rect = new RectangleF(j * gw, i * gh, gw, gh); ;
this.gridrect[i, j] = new CGrid(idx);
this.gridrect[i, j].Rect = rect;
this.gridrect[i, j].Row = i;
this.gridrect[i, j].Col = j;
}
}
}
void Draw_Grid(Graphics g)
{
if(gridrect[0,0]== null) Make_Grid();
for (int i = 0; i <= gridrect.GetUpperBound(0); i++)
{
for (int j = 0; j <= gridrect.GetUpperBound(1); j++)
{
var grid = this.gridrect[i, j];
g.DrawRectangle(Pens.Black, grid.Rect.Left, grid.Rect.Top, grid.Rect.Width, grid.Rect.Height);
g.DrawString(grid.IDX.ToString(), this.Font, Brushes.Blue, grid.Rect.Left, grid.Rect.Top);
}
}
}
}
}

View File

@@ -1,5 +1,9 @@
D:\Source\GroupWare\EET_GroupWare_180704_0000\Sub\StaffLayoutCtl\bin\Debug\StaffLayoutCtl.dll
D:\Source\GroupWare\EET_GroupWare_180704_0000\Sub\StaffLayoutCtl\bin\Debug\StaffLayoutCtl.pdb
D:\Source\GroupWare\EET_GroupWare_180704_0000\Sub\StaffLayoutCtl\obj\Debug\StaffLayoutCtl.dll
D:\Source\GroupWare\EET_GroupWare_180704_0000\Sub\StaffLayoutCtl\obj\Debug\StaffLayoutCtl.pdb
D:\Source\GroupWare\EET_GroupWare_180704_0000\Sub\StaffLayoutCtl\obj\Debug\StaffLayoutCtl.csprojResolveAssemblyReference.cache
D:\Source\GroupWare\EET_GroupWare_180704_0000\Sub\StaffLayoutCtl\bin\Debug\StaffLayoutCtl.dll
D:\Source\GroupWare\EET_GroupWare_180704_0000\Sub\StaffLayoutCtl\bin\Debug\StaffLayoutCtl.pdb
D:\Source\GroupWare\EET_GroupWare_180704_0000\Sub\StaffLayoutCtl\obj\Debug\StaffLayoutCtl.dll
D:\Source\GroupWare\EET_GroupWare_180704_0000\Sub\StaffLayoutCtl\obj\Debug\StaffLayoutCtl.pdb
D:\Source\GroupWare\EET_GroupWare_180704_0000\Sub\StaffLayoutCtl\obj\Debug\StaffLayoutCtl.csprojResolveAssemblyReference.cache
D:\Source\GroupWare\EET_GroupWare_180713_0000\Sub\StaffLayoutCtl\bin\Debug\StaffLayoutCtl.dll
D:\Source\GroupWare\EET_GroupWare_180713_0000\Sub\StaffLayoutCtl\bin\Debug\StaffLayoutCtl.pdb
D:\Source\GroupWare\EET_GroupWare_180713_0000\Sub\StaffLayoutCtl\obj\Debug\StaffLayoutCtl.dll
D:\Source\GroupWare\EET_GroupWare_180713_0000\Sub\StaffLayoutCtl\obj\Debug\StaffLayoutCtl.pdb