차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 다음 판 | 이전 판 | ||
| tech:sizable_panel_csharp [2013/03/06 11:24] – 새로 만듦 14.32.18.124 | tech:sizable_panel_csharp [2016/07/12 00:56] (현재) – 바깥 편집 127.0.0.1 | ||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| + | {{tag> | ||
| + | ======Sizable Panel Csharp====== | ||
| + | |||
| + | |||
| + | * 출처: [[http:// | ||
| + | |||
| + | <code csharp>// | ||
| + | //Add a new class to your project and paste the code shown below. | ||
| + | // | ||
| + | //Drop the new control from the top of the toolbox onto your form. | ||
| + | //by Hans Passant. | ||
| + | // http:// | ||
| + | using System; | ||
| + | using System.Drawing; | ||
| + | using System.Windows.Forms; | ||
| + | |||
| + | public class SizeablePanel : Panel { | ||
| + | private const int cGripSize = 20; | ||
| + | private bool mDragging; | ||
| + | private Point mDragPos; | ||
| + | |||
| + | public SizeablePanel() { | ||
| + | this.DoubleBuffered = true; | ||
| + | this.SetStyle(ControlStyles.ResizeRedraw, | ||
| + | this.BackColor = Color.White; | ||
| + | } | ||
| + | |||
| + | protected override void OnPaint(PaintEventArgs e) { | ||
| + | ControlPaint.DrawSizeGrip(e.Graphics, | ||
| + | new Rectangle(this.ClientSize.Width - cGripSize, this.ClientSize.Height - cGripSize, cGripSize, cGripSize)); | ||
| + | base.OnPaint(e); | ||
| + | } | ||
| + | |||
| + | private bool IsOnGrip(Point pos) { | ||
| + | return pos.X >= this.ClientSize.Width - cGripSize && | ||
| + | pos.Y >= this.ClientSize.Height - cGripSize; | ||
| + | } | ||
| + | |||
| + | protected override void OnMouseDown(MouseEventArgs e) { | ||
| + | mDragging = IsOnGrip(e.Location); | ||
| + | mDragPos = e.Location; | ||
| + | base.OnMouseDown(e); | ||
| + | } | ||
| + | |||
| + | protected override void OnMouseUp(MouseEventArgs e) { | ||
| + | mDragging = false; | ||
| + | base.OnMouseUp(e); | ||
| + | } | ||
| + | |||
| + | protected override void OnMouseMove(MouseEventArgs e) { | ||
| + | if (mDragging) { | ||
| + | this.Size = new Size(this.Width + e.X - mDragPos.X, | ||
| + | this.Height + e.Y - mDragPos.Y); | ||
| + | mDragPos = e.Location; | ||
| + | } | ||
| + | else if (IsOnGrip(e.Location)) this.Cursor = Cursors.SizeNWSE; | ||
| + | else this.Cursor = Cursors.Default; | ||
| + | base.OnMouseMove(e); | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ^ 누구나 수정하실 수 있습니다. [[http:// | ||
| + | |||