参考: 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

解决方案 »

  1.   

    只要FormBorderStyle=Sizable并且没有最大化,就可以改变大小,和是不是有边框以及有没有那个符号没有关系。
      

  2.   


    版主你试过没有? 我说的没有边框即是设置窗口 FormBorderStyle = None。答非所问,不知道别乱讲行么?
      

  3.   


    版主你试过没有? 我说的没有边框即是设置窗口 FormBorderStyle = None。答非所问,不知道别乱讲行么?
    那问题在哪里你自己都找出来了。修改成resize即可。
      

  4.   


                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
    这两个方法我都试过了,第一个方法似乎只能缩小,无法放大。 第二个方法主要是不知道 状态栏那个小三角形响应鼠标拖拽的消息是哪一个。
      

  5.   


    ……理解力还有问题,我表达的不清楚么?
    前提就是FormBorderStyle = None,你还设置resize前提就是我不想要边框好么。 
      

  6.   


    ……理解力还有问题,我表达的不清楚么?
    前提就是FormBorderStyle = None,你还设置resize前提就是我不想要边框好么。 
    不要边框用SetWindowLong设置Flat风格就可以了。
      

  7.   

    我这里有个自己办法。不知道是否适合你,设置窗体的FormBorderStyle属性为SizableToolWindow,ControlBox值为False,然后把窗体的Text清空。就是Text不设置任何值,这样子边框就会消失。状态栏的拖动效果不会消失,
      

  8.   

    第一种方法放大缩小都可以的。
    设置一下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
    这两个方法我都试过了,第一个方法似乎只能缩小,无法放大。 第二个方法主要是不知道 状态栏那个小三角形响应鼠标拖拽的消息是哪一个。
      

  9.   

    能够拖动的无边框窗体
    #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发送拖动窗体的消息
            }