zoukankan      html  css  js  c++  java
  • 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;
    }
    }
    }
  • 相关阅读:
    [论文理解] MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
    [论文理解] Connectionist Text Proposal Network
    [期末复习] 数据结构期末复习
    [机器视觉] 实际场景字提取
    [论文理解]Deep Residual Learning for Image Recognition
    [学习笔记] AD笔记
    [OpenMP] 并行计算入门
    [Docker] Docker安装和简单指令
    python初级装饰器编写
    web页面简单布局的修改,测试中的应用
  • 原文地址:https://www.cnblogs.com/mantian/p/1826131.html
Copyright © 2011-2022 走看看