#region Using
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Windows.Forms;
#endregion
namespace Wankuma.WindowsForms
{
///
/// 常に箱を描画するコントロール
///
public class WankumaBox : System.Windows.Forms.UserControl
{
#region 自動生成
///
/// 必要なデザイナ変数です。
///
private System.ComponentModel.Container components = null;
///
/// コンストラクタ
///
public WankumaBox()
{
// この呼び出しは、Windows.Forms フォーム デザイナで必要です。
InitializeComponent();
// TODO: InitializeComponent 呼び出しの後に初期化処理を追加します。
SetStyle(ControlStyles.ResizeRedraw, true);
}
///
/// 使用されているリソースに後処理を実行します。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region コンポーネント デザイナで生成されたコード
///
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
///
private void InitializeComponent()
{
//
// WankumaBox
//
this.Name = "WankumaBox";
}
#endregion
#endregion
#region メンバ
#region private float _線幅 = 1.0F;
///
/// 線幅のメンバ
///
private float _線幅 = 1.0F;
#endregion
#region public float 線幅
///
/// 描画する線幅を指定する
///
[DefaultValue(1.0F)]
public float 線幅
{
set
{
if ( value < 1.0 )
{
this._線幅 = 1.0F;
}
else
{
this._線幅 = value;
}
}
get
{
return this._線幅;
}
}
#endregion
#region public bool _右描画 = false;
///
/// 右を描画するかどうかのメンバ
///
public bool _右描画 = false;
#endregion
#region public bool 右描画
///
/// 右下を描画するかどうか
///
[DefaultValue(false)]
public bool 右描画
{
set
{
this._右描画 = value;
}
get
{
return this._右描画;
}
}
#endregion
#region public bool _下描画 = false;
///
/// 右下を描画するかどうかのメンバ
///
public bool _下描画 = false;
#endregion
#region public bool 下描画
///
/// 右下を描画するかどうか
///
[DefaultValue(false)]
public bool 下描画
{
set
{
this._下描画 = value;
}
get
{
return this._下描画;
}
}
#endregion
#endregion
#region protected override void OnPaint(PaintEventArgs e)
///
/// 描画処理
///
///
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
using ( SolidBrush sb = new SolidBrush(this.ForeColor) )
{
//xy等を調べる
float x = e.Graphics.VisibleClipBounds.X;
float y = e.Graphics.VisibleClipBounds.Y;
float width = e.Graphics.VisibleClipBounds.Width;
float height = e.Graphics.VisibleClipBounds.Height;
float x2 = width - this._線幅 < x ? x : width - this._線幅;
float y2 = height - this._線幅 < y ? y : height - this._線幅;
float width2 = x + this._線幅 > width ? width : x + this._線幅;
float height2 = y + this._線幅 > height ? height : y + this._線幅;
//線を描画する
//左辺
e.Graphics.FillRectangle(sb, x, y, x + width2, height);
//上辺
e.Graphics.FillRectangle(sb, x, y, width, height2);
if ( this._右描画 == true )
{
//右辺
e.Graphics.FillRectangle(sb, x2, y, width, height);
}
if ( this._下描画 == true )
{
//下辺
e.Graphics.FillRectangle(sb, x, y2, width, height);
}
}
}
#endregion
}
}