私の仕事は、画面の上部または下部または左または右の部分に貼り付けることができる粘着性のあるフォームを作ることです。したがって、画面の左右に貼り付ける場合は、最大の高さと固定幅が必要です。上部または下部に貼り付ける場合は、固定された高さと最大幅(画面幅の100%)を持たなければなりません。私はC#4.0でそれを作ることができますか?たぶん適切な市販のソリューションがありますか?画面の罫線に貼り付けることができるフォームを作る方法
UPDATE1
[OK]を、それは窓を固執する良いリンクです。大きなthx!今、私はマウスと移動で選択されている間、フォームの幅と高さの設定に問題があります。私はResizeBegin後に火災ResizeEndイベントをいけないので...しかし、私は上記のような方法は、私が何かを実現することができます - それは50×50ピクセルにリサイズされていない理由
namespace WordLearn
{
public partial class FormWord : Form
{
private const int SnapDist = 70;
private int currWidth = 0;
private int currHeight = 0;
public FormWord()
{
InitializeComponent();
}
private bool DoSnap(int pos, int edge)
{
int delta = pos - edge;
return delta > 0 && delta <= SnapDist;
}
protected override void OnResizeEnd(EventArgs e)
{
base.OnResizeEnd(e);
Boolean key = false;
Screen scn = Screen.FromPoint(this.Location);
if (DoSnap(this.Left, scn.WorkingArea.Left))
{
key = true;
this.Width = 200;
this.Height = scn.WorkingArea.Height;
this.Left = scn.WorkingArea.Left;
}
if (DoSnap(this.Top, scn.WorkingArea.Top))
{
key = true;
this.Height = 200;
this.Width = scn.WorkingArea.Width;
this.Top = scn.WorkingArea.Top;
}
if (DoSnap(scn.WorkingArea.Right, this.Right))
{
key = true;
this.Width = 200;
this.Height = scn.WorkingArea.Height;
this.Left = scn.WorkingArea.Right - this.Width;
}
if (DoSnap(scn.WorkingArea.Bottom, this.Bottom))
{
key = true;
this.Height = 200;
this.Width = scn.WorkingArea.Width;
this.Top = scn.WorkingArea.Bottom - this.Height;
}
if (!key)
{
this.Width = currWidth;
this.Height = currHeight;
}
}
protected override void OnResizeBegin(EventArgs e)
{
base.OnResizeBegin(e);
currWidth = this.Width;
currHeight = this.Height;
this.Width = 50;
this.Height = 50;
}
}
}
は、私が理解できますか?
アップデート2
だから、今私は、次のコードを持っています。このコードはスクリーンの端に貼り付けます。しかし、私は、私がやろう
namespace WordLearn
{
public partial class FormWord : Form
{
private const int stickDist = 100;
private Screen scn = null;
private int maxW = 0;
private int maxH = 0;
private int fixedW = 300;
private int fixedH = 300;
public FormWord()
{
InitializeComponent();
}
private void FormWord_Load(object sender, EventArgs e)
{
this.scn = Screen.FromPoint(this.Location);
maxW = scn.WorkingArea.Width;
maxH = scn.WorkingArea.Height;
Point p = new Point(0, 0);
this.Size = new Size(fixedW, maxH);
this.Location = p;
}
private void FormWord_Move(object sender, EventArgs e)
{
if (maxH != 0 && maxW != 0 && this.Location.X != 0 && this.Location.Y != 0 && this.Location.X != maxW-fixedW && this.Location.Y != maxH - fixedH)
{
label1.Text = this.Location.X.ToString() + ":" + this.Location.Y.ToString();
if (this.Location.Y < stickDist)
{
Point p = new Point(0, 0);
this.Size = new Size(maxW, fixedH);
this.Location = p;
}
else if ((this.Location.Y + this.Height) > (maxH - stickDist))
{
Point p = new Point(0, (maxH - fixedH));
this.Size = new Size(maxW, fixedH);
this.Location = p;
}else if (this.Location.X < stickDist)
{
Point p = new Point(0, 0);
this.Size = new Size(fixedW, maxH);
this.Location = p;
}
else if ((this.Location.X + this.Width) > (maxW - stickDist))
{
Point p = new Point((maxW - fixedW), 0);
this.Size = new Size(fixedW, maxH);
this.Location = p;
}
}
}
private void FormWord_ResizeBegin(object sender, EventArgs e)
{
this.Size = new Size(200,200);
int x = 0;
int y = 0;
if (this.Location.Y == 0)
{
y = stickDist * 2;
}
else
{
y = this.Location.Y - stickDist * 2;
}
if (this.Location.X == 0)
{
x = stickDist * 2;
}
else
{
x = this.Location.X - stickDist * 2;
}
this.Location = new Point(x, y);
Cursor.Position = new Point(x + 2, y + 2);
}
}
}
...このフォームは、彼が大きな随分ウィンドウを移動した場合、ユーザはit.Becauseを引き離すしようとすると、それは次のルールによって再び貼ります(サイズ(200200)への)サイズを変更したいですFormWord_ResizeBegin voidでサイズ変更されますが、動作しません。私はそれが働くのを助けることができますか?
最大化されたウィンドウの動作に影響を与えますか? – SLaks
ウィンドウの幅が最大になっている場合は、画面の右端と左端の両方に固定されます。フォームで何をしたいのですか? –
上端または下端に貼り付けるときに必要な最大幅と固定高さを書きました。 – dizpers