参考: C# 无边框窗体的移动,任务栏右键菜单,调整大小
方法一 if (e.Button == MouseButtons.Left)
{ this.Size = new Size(this.PointToClient(MousePosition).X, this.PointToClient(MousePosition).Y); }方法二#region 控制改变窗体大小
const int WM_NCHITTEST = 0x0084;
const int HTLEFT = 10; //左边界
const int HTRIGHT = 11; //右边界
const int HTTOP = 12; //上边界
const int HTTOPLEFT = 13; //左上角
const int HTTOPRIGHT = 14; //右上角
const int HTBOTTOM = 15; //下边界
const int HTBOTTOMLEFT = 0x10; //左下角
const int HTBOTTOMRIGHT = 17; //右下角
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case WM_NCHITTEST:
{
Point vPoint = new Point((int)m.LParam & 0xFFFF,
(int)m.LParam >> 16 & 0xFFFF);
vPoint = PointToClient(vPoint);
//判断:仅当当前窗体状态不是最大化时,相关鼠标事件生效
if (this.WindowState != FormWindowState.Maximized)
{
if (vPoint.X <= 5)
{
if (vPoint.Y <= 5)
{
m.Result = (IntPtr)HTTOPLEFT;
}
else if (vPoint.Y >= ClientSize.Height - 5)
{
m.Result = (IntPtr)HTBOTTOMLEFT;
}
else
{
m.Result = (IntPtr)HTLEFT;
}
}
else if (vPoint.X >= ClientSize.Width - 5)
{
if (vPoint.Y <= 5)
{
m.Result = (IntPtr)HTTOPRIGHT;
}
else if (vPoint.Y >= ClientSize.Height - 5)
{
m.Result = (IntPtr)HTBOTTOMRIGHT;
}
else
{
m.Result = (IntPtr)HTRIGHT;
}
}
else if (vPoint.Y <= 5)
{
m.Result = (IntPtr)HTTOP;
}
else if (vPoint.Y >= ClientSize.Height - 5)
{
m.Result = (IntPtr)HTBOTTOM;
}
}
break;
}
}
}
#endregion
方法一 if (e.Button == MouseButtons.Left)
{ this.Size = new Size(this.PointToClient(MousePosition).X, this.PointToClient(MousePosition).Y); }方法二#region 控制改变窗体大小
const int WM_NCHITTEST = 0x0084;
const int HTLEFT = 10; //左边界
const int HTRIGHT = 11; //右边界
const int HTTOP = 12; //上边界
const int HTTOPLEFT = 13; //左上角
const int HTTOPRIGHT = 14; //右上角
const int HTBOTTOM = 15; //下边界
const int HTBOTTOMLEFT = 0x10; //左下角
const int HTBOTTOMRIGHT = 17; //右下角
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case WM_NCHITTEST:
{
Point vPoint = new Point((int)m.LParam & 0xFFFF,
(int)m.LParam >> 16 & 0xFFFF);
vPoint = PointToClient(vPoint);
//判断:仅当当前窗体状态不是最大化时,相关鼠标事件生效
if (this.WindowState != FormWindowState.Maximized)
{
if (vPoint.X <= 5)
{
if (vPoint.Y <= 5)
{
m.Result = (IntPtr)HTTOPLEFT;
}
else if (vPoint.Y >= ClientSize.Height - 5)
{
m.Result = (IntPtr)HTBOTTOMLEFT;
}
else
{
m.Result = (IntPtr)HTLEFT;
}
}
else if (vPoint.X >= ClientSize.Width - 5)
{
if (vPoint.Y <= 5)
{
m.Result = (IntPtr)HTTOPRIGHT;
}
else if (vPoint.Y >= ClientSize.Height - 5)
{
m.Result = (IntPtr)HTBOTTOMRIGHT;
}
else
{
m.Result = (IntPtr)HTRIGHT;
}
}
else if (vPoint.Y <= 5)
{
m.Result = (IntPtr)HTTOP;
}
else if (vPoint.Y >= ClientSize.Height - 5)
{
m.Result = (IntPtr)HTBOTTOM;
}
}
break;
}
}
}
#endregion
解决方案 »
- 怎么做 EXE 程序 !!知道的 请进门 谢谢··
- 奇怪! WPF的 HeaderStyle 颜色 Binding 失效问题
- VS2008调试如何在dll中设置断点
- 使用Lucene_Net查询分断的索引文件.
- 为什么DataGrid在更新时更新不了,显示编辑失败
- 警告 1 程序集“bin\Debug\Dbconfig.dll”被错误地指定为一个文件。 1.0
- WPF界面显示的字体显得很虚,有没有解决办法啊?
- C#中怎么实现listbox的右键点击时item的选中问题,
- 请帮我把一小段c++代码转换为类库,我在c#里面调用!
- DataAdapter.fill方法填充数据时怎样用一个进度条反映数据填充的进度?
- linq表达式问题
- 将Excel表格中的数据(每一行中其中一列包含图片)批量导入到SQL Server的表中,并在winform的窗体上可以显示这些信息(包括图片)
版主你试过没有? 我说的没有边框即是设置窗口 FormBorderStyle = None。答非所问,不知道别乱讲行么?
版主你试过没有? 我说的没有边框即是设置窗口 FormBorderStyle = None。答非所问,不知道别乱讲行么?
那问题在哪里你自己都找出来了。修改成resize即可。
if (e.Button == MouseButtons.Left)
{ this.Size = new Size(this.PointToClient(MousePosition).X, this.PointToClient(MousePosition).Y); }方法二#region 控制改变窗体大小
const int WM_NCHITTEST = 0x0084;
const int HTLEFT = 10; //左边界
const int HTRIGHT = 11; //右边界
const int HTTOP = 12; //上边界
const int HTTOPLEFT = 13; //左上角
const int HTTOPRIGHT = 14; //右上角
const int HTBOTTOM = 15; //下边界
const int HTBOTTOMLEFT = 0x10; //左下角
const int HTBOTTOMRIGHT = 17; //右下角
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case WM_NCHITTEST:
{
Point vPoint = new Point((int)m.LParam & 0xFFFF,
(int)m.LParam >> 16 & 0xFFFF);
vPoint = PointToClient(vPoint);
//判断:仅当当前窗体状态不是最大化时,相关鼠标事件生效
if (this.WindowState != FormWindowState.Maximized)
{
if (vPoint.X <= 5)
{
if (vPoint.Y <= 5)
{
m.Result = (IntPtr)HTTOPLEFT;
}
else if (vPoint.Y >= ClientSize.Height - 5)
{
m.Result = (IntPtr)HTBOTTOMLEFT;
}
else
{
m.Result = (IntPtr)HTLEFT;
}
}
else if (vPoint.X >= ClientSize.Width - 5)
{
if (vPoint.Y <= 5)
{
m.Result = (IntPtr)HTTOPRIGHT;
}
else if (vPoint.Y >= ClientSize.Height - 5)
{
m.Result = (IntPtr)HTBOTTOMRIGHT;
}
else
{
m.Result = (IntPtr)HTRIGHT;
}
}
else if (vPoint.Y <= 5)
{
m.Result = (IntPtr)HTTOP;
}
else if (vPoint.Y >= ClientSize.Height - 5)
{
m.Result = (IntPtr)HTBOTTOM;
}
}
break;
}
}
}
#endregion
这两个方法我都试过了,第一个方法似乎只能缩小,无法放大。 第二个方法主要是不知道 状态栏那个小三角形响应鼠标拖拽的消息是哪一个。
……理解力还有问题,我表达的不清楚么?
前提就是FormBorderStyle = None,你还设置resize前提就是我不想要边框好么。
……理解力还有问题,我表达的不清楚么?
前提就是FormBorderStyle = None,你还设置resize前提就是我不想要边框好么。
不要边框用SetWindowLong设置Flat风格就可以了。
设置一下Panel的Anchor为Bottom和Right,这样它就一直在右下角,并随窗体的变化而变化using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;namespace NoBorderFormResize
{
/// <summary>
/// Description of MainForm.
/// </summary>
public class MainForm : Form
{
/// <summary>
/// Designer variable used to keep track of non-visual components.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Disposes resources used by the form.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panel1
//
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.panel1.BackColor = System.Drawing.Color.Yellow;
this.panel1.Cursor = System.Windows.Forms.Cursors.SizeNWSE;
this.panel1.Location = new System.Drawing.Point(264, 240);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(20, 20);
this.panel1.TabIndex = 0;
this.panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Panel1MouseMove);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.LightCyan;
this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.panel1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "MainForm";
this.Text = "NoBorderFormResize";
this.ResumeLayout(false);
}
private System.Windows.Forms.Panel panel1;
public MainForm()
{
InitializeComponent();
}
void Panel1MouseMove(object sender, MouseEventArgs e)
{ if (e.Button == MouseButtons.Left)
{
this.Size = new Size(this.PointToClient(MousePosition).X, this.PointToClient(MousePosition).Y);
}
}
}
}
if (e.Button == MouseButtons.Left)
{ this.Size = new Size(this.PointToClient(MousePosition).X, this.PointToClient(MousePosition).Y); }方法二#region 控制改变窗体大小
const int WM_NCHITTEST = 0x0084;
const int HTLEFT = 10; //左边界
const int HTRIGHT = 11; //右边界
const int HTTOP = 12; //上边界
const int HTTOPLEFT = 13; //左上角
const int HTTOPRIGHT = 14; //右上角
const int HTBOTTOM = 15; //下边界
const int HTBOTTOMLEFT = 0x10; //左下角
const int HTBOTTOMRIGHT = 17; //右下角
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case WM_NCHITTEST:
{
Point vPoint = new Point((int)m.LParam & 0xFFFF,
(int)m.LParam >> 16 & 0xFFFF);
vPoint = PointToClient(vPoint);
//判断:仅当当前窗体状态不是最大化时,相关鼠标事件生效
if (this.WindowState != FormWindowState.Maximized)
{
if (vPoint.X <= 5)
{
if (vPoint.Y <= 5)
{
m.Result = (IntPtr)HTTOPLEFT;
}
else if (vPoint.Y >= ClientSize.Height - 5)
{
m.Result = (IntPtr)HTBOTTOMLEFT;
}
else
{
m.Result = (IntPtr)HTLEFT;
}
}
else if (vPoint.X >= ClientSize.Width - 5)
{
if (vPoint.Y <= 5)
{
m.Result = (IntPtr)HTTOPRIGHT;
}
else if (vPoint.Y >= ClientSize.Height - 5)
{
m.Result = (IntPtr)HTBOTTOMRIGHT;
}
else
{
m.Result = (IntPtr)HTRIGHT;
}
}
else if (vPoint.Y <= 5)
{
m.Result = (IntPtr)HTTOP;
}
else if (vPoint.Y >= ClientSize.Height - 5)
{
m.Result = (IntPtr)HTBOTTOM;
}
}
break;
}
}
}
#endregion
这两个方法我都试过了,第一个方法似乎只能缩小,无法放大。 第二个方法主要是不知道 状态栏那个小三角形响应鼠标拖拽的消息是哪一个。
#region 本程序中用到的API函数
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();//用来释放被当前线程中某个窗口捕获的光标
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwdn,int wMsg,int mParam,int lParam);//向指定的窗体发送Windows消息
#endregion #region 本程序中需要声明的变量
public const int WM_SYSCOMMAND = 0x0112;//该变量表示将向Windows发送的消息类型
public const int SC_MOVE = 0xF010;//该变量表示发送消息的附加消息
public const int HTCAPTION = 0x0002;//该变量表示发送消息的附加消息
#endregion private void ExitContext_Click(object sender, EventArgs e)
{
Application.Exit();//退出本程序
} private void Frm_Main_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();//用来释放被当前线程中某个窗口捕获的光标
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);//向Windows发送拖动窗体的消息
}