将无边界表单拖到屏幕顶部时;如果Y坐标为负,则将其设置回0。我要执行的操作是将窗体拖动到顶部上方,其中Y坐标将为负,这与您在图的其他两侧相同屏幕。
这是我尝试过的:
public class MerkmalRow
{
public string Name { get; set; }
public string Wert { get; set; }
public MerkmalRow(string name, string wert)
{
Name = name;
Wert = wert;
}
}
public class MerkmalSet
{
public List<MerkmalRow> Merkmalls;
public void AddNewRow(MerkmalRow newRow)
{
if (Merkmalls == null)
Merkmalls = new List<MerkmalRow>();
Merkmalls.Add(newRow);
}
public void RemoveAllInstancesOfDuplicates()
{
var withoutAllInstancesOfDuplicates = new List<MerkmalRow>();
foreach (MerkmalRow entry in Merkmalls)
{
if (Merkmalls.Count(row =>
string.Equals(row.Name, entry.Name) &&
string.Equals(row.Wert, entry.Wert)) == 1)
{
withoutAllInstancesOfDuplicates.Add(entry);
}
}
Merkmalls = null;
Merkmalls = withoutAllInstancesOfDuplicates;
}
}
这是我考虑了一段时间后能想到的最好的方法。问题在于,当释放鼠标并完成表格移动时,public partial class BorderlessForm : Form
{
public BorderlessForm()
{
InitializeComponent();
}
private bool _isNegative;
private Point _negative;
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
protected override void OnMouseDown(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) {
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
protected override void OnResizeEnd(EventArgs e)
{
if (_isNegative) {
Location = _negative;
}
//base.OnResizeEnd(e);
}
protected override void OnMove(EventArgs e)
{
if (Location.Y < 0) {
_isNegative = true;
_negative = Location;
}
else {
_isNegative = false;
}
//base.OnMove(e);
}
}
会在OnMove
之前被调用,然后OnResizeEnd
会被设置回false。至少,我认为这是正在发生的事情。
我有正确的主意,还是有更好的方法来解决这个问题?
答案 0 :(得分:0)
因此,我对isaeid所说的内容进行了更多的思考,并提出了解决方案。仍然不确定这是否是最好的解决方法,但这是:
close
答案 1 :(得分:0)
您可以更改一些此类事件:
protected override void OnResizeEnd(EventArgs e)
{
if (_isNegative)
{
Location = _negative;
}
oldRight = this.Right;
oldBottom = this.Bottom;
//base.OnResizeEnd(e);
}
protected override void OnMove(EventArgs e)
{
if ( this.Right == oldRight || this.Bottom == oldBottom)
return;
if (Location.Y < 0)
{
_isNegative = true;
_negative = Location;
}
else
{
_isNegative = false;
}
//base.OnMove(e);
}
当窗口的顶部或左侧发生变化时,dotnet确定窗口的位置发生变化并调用onmove事件,我考虑窗口的右侧或底部是否未更改,因此窗口的位置未更改。
也添加此代码:
int oldBottom, oldRight;
private void BorderlessForm_Load(object sender, EventArgs e)
{
oldRight = this.Right;
oldBottom = this.Bottom;
}