• C# 如何在空间运行时调整控件位置和大小


    最近需要实现这个功能,结合网上搜索代码,实现了该功能。

    代码如下:

    代码
    private void L*****_MouseMove(object sender, MouseEventArgs e)
    {
    //((Control)sender).Cursor = Cursors.Hand;
    //bChangeSizeMode = false;
    if (!bMouseDown)
    {
    int right = ((Control)sender).Width;
    int bottom = ((Control)sender).Height;
    if (e.X > (right - 10) && e.Y > (bottom - 10))
    {
    ((Control)sender).Cursor
    = Cursors.SizeNWSE;
    bChangeSizeMode
    = true;
    }
    else if (e.X > (right - 10))
    {
    ((Control)sender).Cursor
    = Cursors.VSplit;
    bChangeSizeMode
    = true;
    }
    else if (e.Y > (bottom - 10))
    {
    ((Control)sender).Cursor
    = Cursors.HSplit;
    bChangeSizeMode
    = true;
    }
    else
    {
    ((Control)sender).Cursor
    = Cursors.SizeAll;
    bChangeSizeMode
    = false;
    }
    }

    if (bMouseDown && bMoveMode)
    {
    if (bChangeSizeMode)
    {
    if (e.Button == MouseButtons.Left)
    {
    if (((Control)sender).Cursor == Cursors.VSplit)
    {
    ((Control)sender).Width
    = e.X;
    }
    else if (((Control)sender).Cursor == Cursors.HSplit)
    {
    ((Control)sender).Height
    = e.Y;
    }
    else
    {
    ((Control)sender).Width
    = e.X;
    ((Control)sender).Height
    = e.Y;
    }
    ((Control)sender).Tag
    = ((Control)sender).Width + ":" + ((Control)sender).Height + ":" + ((Control)sender).Left + ":" + ((Control)sender).Top + ":" + ((Control)sender).Font.Size;
    }
    bLocationChanged
    = true;
    }
    else
    {
    //((Control)sender).Cursor = Cursors.Hand;//设置拖动时鼠标箭头
    if (e.Button == MouseButtons.Left)
    {
    Point mousePos
    = Control.MousePosition;
    mousePos.Offset(mouseOffset.X, mouseOffset.Y);
    //设置偏移
    ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
    ((Control)sender).Tag
    = ((Control)sender).Width + ":" + ((Control)sender).Height + ":" + ((Control)sender).Left + ":" + ((Control)sender).Top + ":" + ((Control)sender).Font.Size;
    }
    bLocationChanged
    = true;
    }
    }
    }
  • 相关阅读:
    BlockingQueue 原理 分析
    java引用 强引用,软引用,弱引用
    actomic cas无锁操作。
    MongoDB库设计原则及实践
    spring事物传播机制 事物隔离级别
    Hive UDAF介绍与开发
    [技术学习]js接口继承
    [技术学习]js继承
    [技术学习]正则表达式分析
    [技术学习]js正则表达式汇总
  • 原文地址:https://www.cnblogs.com/mantian/p/1826131.html
Copyright © 2020-2023  润新知