基于C#实现磁性吸附窗体

目录
  • 实践过程
    • 效果
    • 代码

实践过程

效果

代码

public partial class Frm_Libretto : Form
{
    public Frm_Libretto()
    {
        InitializeComponent();
    }

    #region 公共变量

    FrmClass Cla_FrmClass = new FrmClass();

    #endregion

    private void Frm_Libretto_Load(object sender, EventArgs e)
    {
        this.Top = FrmClass.Example_Play_Top;
        this.Left = FrmClass.Example_Play_Left + FrmClass.Example_Play_Width;
        Cla_FrmClass.FrmInitialize(this);
    }

    private void panel_Title_MouseDown(object sender, MouseEventArgs e)
    {
        FrmClass.CPoint = new Point(-e.X, -e.Y);
    }

    private void panel_Title_MouseMove(object sender, MouseEventArgs e)
    {
        FrmClass.Example_Assistant_AdhereTo = false;
        FrmClass.Example_Libretto_AdhereTo = false;
        Cla_FrmClass.FrmMove(this, e);
    }

    private void panel_Title_MouseUp(object sender, MouseEventArgs e)
    {
        Cla_FrmClass.FrmPlace(this);
    }
}
public partial class Frm_ListBox : Form
{
    public Frm_ListBox()
    {
        InitializeComponent();
    }

    #region  公共变量
    FrmClass Cla_FrmClass = new FrmClass();
    #endregion

    private void Frm_ListBox_Load(object sender, EventArgs e)
    {
        this.Left = FrmClass.Example_Play_Left;
        this.Top = FrmClass.Example_Play_Top + FrmClass.Example_Play_Height;
        Cla_FrmClass.FrmInitialize(this);
    }

    private void panel_Title_MouseDown(object sender, MouseEventArgs e)
    {
        FrmClass.CPoint = new Point(-e.X, -e.Y);
    }

    private void panel_Title_MouseMove(object sender, MouseEventArgs e)
    {
        FrmClass.Example_Assistant_AdhereTo = false;
        FrmClass.Example_List_AdhereTo = false;
        Cla_FrmClass.FrmMove(this, e);
    }

    private void panel_Title_MouseUp(object sender, MouseEventArgs e)
    {
        Cla_FrmClass.FrmPlace(this);
    }
}
public partial class Frm_Play : Form
{
    public Frm_Play()
    {
        InitializeComponent();
    }

    #region 公共变量

    FrmClass Cla_FrmClass = new FrmClass();
    public static Form F_List = new Form();
    public static Form F_Libretto = new Form();
    public static Form F_Screen = new Form();

    #endregion

    private void Frm_Play_Load(object sender, EventArgs e)
    {
        //窗体位置的初始化
        Cla_FrmClass.FrmInitialize(this);
    }

    private void panel_Title_MouseDown(object sender, MouseEventArgs e)
    {
        int Tem_Y = 0;
        if (e.Button == MouseButtons.Left) //按下的是否为鼠标左键
        {
            Cla_FrmClass.FrmBackCheck(); //检测各窗体是否连在一起
            Tem_Y = e.Y;
            FrmClass.FrmPoint = new Point(e.X, Tem_Y); //获取鼠标在窗体上的位置,用于磁性窗体
            FrmClass.CPoint = new Point(-e.X, -Tem_Y); //获取鼠标在屏幕上的位置,用于窗体的移动
            if (FrmClass.Example_List_AdhereTo) //如果与frm_ListBox窗体相连接
            {
                Cla_FrmClass.FrmDistanceJob(this, F_List); //计算窗体的距离差
                if (FrmClass.Example_Assistant_AdhereTo) //两个辅窗体是否连接在一起
                {
                    Cla_FrmClass.FrmDistanceJob(this, F_Libretto); //计算窗体的距离差
                }
            }

            if (FrmClass.Example_Libretto_AdhereTo) //如果与frm_Libretto窗体相连接
            {
                Cla_FrmClass.FrmDistanceJob(this, F_Libretto); //计算窗体的距离差
                if (FrmClass.Example_Assistant_AdhereTo) //两个辅窗体是否连接在一起
                {
                    Cla_FrmClass.FrmDistanceJob(this, F_List); //计算窗体的距离差
                }
            }
        }
    }

    private void panel_Title_MouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left) //按下的是否为鼠标左键
        {
            Cla_FrmClass.FrmMove(this, e); //利用控件移动窗体
            if (FrmClass.Example_List_AdhereTo) //如果frm_ListBox窗体与主窗体连接
            {
                Cla_FrmClass.ManyFrmMove(this, e, F_List); //磁性窗体的移动
                Cla_FrmClass.FrmInitialize(F_List); //对frm_ListBox窗体的位置进行初始化
                if (FrmClass.Example_Assistant_AdhereTo) //如果两个子窗体连接在一起
                {
                    Cla_FrmClass.ManyFrmMove(this, e, F_Libretto);
                    Cla_FrmClass.FrmInitialize(F_Libretto);
                }
            }

            if (FrmClass.Example_Libretto_AdhereTo) //如果frm_Libretto窗体与主窗体连接
            {
                Cla_FrmClass.ManyFrmMove(this, e, F_Libretto);
                Cla_FrmClass.FrmInitialize(F_Libretto);
                if (FrmClass.Example_Assistant_AdhereTo)
                {
                    Cla_FrmClass.ManyFrmMove(this, e, F_List);
                    Cla_FrmClass.FrmInitialize(F_List);
                }
            }

            Cla_FrmClass.FrmInitialize(this);
        }
    }

    private void panel_Title_MouseUp(object sender, MouseEventArgs e)
    {
        Cla_FrmClass.FrmPlace(this);
    }

    private void Frm_Play_Shown(object sender, EventArgs e)
    {
        //显示列表窗体
        F_List = new Frm_ListBox();
        F_List.ShowInTaskbar = false;
        FrmClass.Example_ListShow = true;
        F_List.Show();
        //显示歌词窗体
        F_Libretto = new Frm_Libretto();
        F_Libretto.ShowInTaskbar = false;
        FrmClass.Example_LibrettoShow = true;
        F_Libretto.Show();
        F_Libretto.Left = this.Left + this.Width;
        F_Libretto.Top = this.Top;
        //各窗体位置的初始化
        Cla_FrmClass.FrmInitialize(F_List);
        Cla_FrmClass.FrmInitialize(F_Libretto);
    }

    private void panel_Close_Click(object sender, EventArgs e)
    {
        F_List.Close();
        F_List.Dispose();
        F_Libretto.Close();
        F_Libretto.Dispose();
        F_Screen.Close();
        F_Screen.Dispose();
        this.Close();
    }

    private void panel_Title_Click(object sender, EventArgs e)
    {
        F_List.Focus();
        F_Libretto.Focus();
        this.Focus();
    }
}
class FrmClass
{
    #region 磁性窗体-公共变量

    //记录窗体的隐藏与显示
    public static bool Example_ListShow = false;
    public static bool Example_LibrettoShow = false;
    public static bool Example_ScreenShow = false;

    //记录鼠标的当前位置
    public static Point CPoint; //添加命名空间using System.Drawing;
    public static Point FrmPoint;
    public static int Example_FSpace = 10; //设置窗体间的距离

    //Frm_Play窗体的位置及大小
    public static int Example_Play_Top = 0;
    public static int Example_Play_Left = 0;
    public static int Example_Play_Width = 0;
    public static int Example_Play_Height = 0;
    public static bool Example_Assistant_AdhereTo = false; //辅助窗体是否磁性在一起

    //Frm_ListBos窗体的位置及大小
    public static int Example_List_Top = 0;
    public static int Example_List_Left = 0;
    public static int Example_List_Width = 0;
    public static int Example_List_Height = 0;
    public static bool Example_List_AdhereTo = false; //辅助窗体是否与主窗体磁性在一起

    //Frm_Libretto窗体的位置及大小
    public static int Example_Libretto_Top = 0;
    public static int Example_Libretto_Left = 0;
    public static int Example_Libretto_Width = 0;
    public static int Example_Libretto_Height = 0;
    public static bool Example_Libretto_AdhereTo = false; //辅助窗体是否与主窗体磁性在一起

    //窗体之间的距离差
    public static int Example_List_space_Top = 0;
    public static int Example_List_space_Left = 0;
    public static int Example_Libretto_space_Top = 0;
    public static int Example_Libretto_space_Left = 0;

    #endregion

    #region 检测各窗体是否连接在一起

    /// <summary>
    /// 检测各窗体是否连接在一起
    /// </summary>
    public void FrmBackCheck()
    {
        bool Tem_Magnetism = false;
        //Frm_ListBos与主窗体
        Tem_Magnetism = false;
        if ((Example_Play_Top - Example_List_Top) == 0)
            Tem_Magnetism = true;
        if ((Example_Play_Left - Example_List_Left) == 0)
            Tem_Magnetism = true;
        if ((Example_Play_Left - Example_List_Left - Example_List_Width) == 0)
            Tem_Magnetism = true;
        if ((Example_Play_Left - Example_List_Left + Example_List_Width) == 0)
            Tem_Magnetism = true;
        if ((Example_Play_Top - Example_List_Top - Example_List_Height) == 0)
            Tem_Magnetism = true;
        if ((Example_Play_Top - Example_List_Top + Example_List_Height) == 0)
            Tem_Magnetism = true;
        if (Tem_Magnetism)
            Example_List_AdhereTo = true;

        //Frm_Libretto与主窗体
        Tem_Magnetism = false;
        if ((Example_Play_Top - Example_Libretto_Top) == 0)
            Tem_Magnetism = true;
        if ((Example_Play_Left - Example_Libretto_Left) == 0)
            Tem_Magnetism = true;
        if ((Example_Play_Left - Example_Libretto_Left - Example_Libretto_Width) == 0)
            Tem_Magnetism = true;
        if ((Example_Play_Left - Example_Libretto_Left + Example_Libretto_Width) == 0)
            Tem_Magnetism = true;
        if ((Example_Play_Top - Example_Libretto_Top - Example_Libretto_Height) == 0)
            Tem_Magnetism = true;
        if ((Example_Play_Top - Example_Libretto_Top + Example_Libretto_Height) == 0)
            Tem_Magnetism = true;
        if (Tem_Magnetism)
            Example_Libretto_AdhereTo = true;

        //两个辅窗体
        Tem_Magnetism = false;
        if ((Example_List_Top - Example_Libretto_Top) == 0)
            Tem_Magnetism = true;
        if ((Example_List_Left - Example_Libretto_Left) == 0)
            Tem_Magnetism = true;
        if ((Example_List_Left - Example_Libretto_Left - Example_Libretto_Width) == 0)
            Tem_Magnetism = true;
        if ((Example_List_Left - Example_Libretto_Left + Example_Libretto_Width) == 0)
            Tem_Magnetism = true;
        if ((Example_List_Top - Example_Libretto_Top - Example_Libretto_Height) == 0)
            Tem_Magnetism = true;
        if ((Example_List_Top - Example_Libretto_Top + Example_Libretto_Height) == 0)
            Tem_Magnetism = true;
        if (Tem_Magnetism)
            Example_Assistant_AdhereTo = true;
    }

    #endregion

    #region 利用窗体上的控件移动窗体

    /// <summary>
    /// 利用控件移动窗体
    /// </summary>
    /// <param Frm="Form">窗体</param>
    /// <param e="MouseEventArgs">控件的移动事件</param>
    public void FrmMove(Form Frm, MouseEventArgs e) //Form或MouseEventArgs添加命名空间using System.Windows.Forms;
    {
        if (e.Button == MouseButtons.Left)
        {
            Point myPosittion = Control.MousePosition; //获取当前鼠标的屏幕坐标
            myPosittion.Offset(CPoint.X, CPoint.Y); //重载当前鼠标的位置
            Frm.DesktopLocation = myPosittion; //设置当前窗体在屏幕上的位置
        }
    }

    #endregion

    #region 计算窗体之间的距离差

    /// <summary>
    /// 计算窗体之间的距离差
    /// </summary>
    /// <param Frm="Form">窗体</param>
    /// <param Follow="Form">跟随窗体</param>
    public void FrmDistanceJob(Form Frm, Form Follow)
    {
        switch (Follow.Name)
        {
            case "Frm_ListBox":
            {
                Example_List_space_Top = Follow.Top - Frm.Top;
                Example_List_space_Left = Follow.Left - Frm.Left;
                break;
            }
            case "Frm_Libretto":
            {
                Example_Libretto_space_Top = Follow.Top - Frm.Top;
                Example_Libretto_space_Left = Follow.Left - Frm.Left;
                break;
            }
        }
    }

    #endregion

    #region 磁性窗体的移动

    /// <summary>
    /// 磁性窗体的移动
    /// </summary>
    /// <param Frm="Form">窗体</param>
    /// <param e="MouseEventArgs">控件的移动事件</param>
    /// <param Follow="Form">跟随窗体</param>
    public void
        ManyFrmMove(Form Frm, MouseEventArgs e, Form Follow) //Form或MouseEventArgs添加命名空间using System.Windows.Forms;
    {
        if (e.Button == MouseButtons.Left)
        {
            int Tem_Left = 0;
            int Tem_Top = 0;
            Point myPosittion = Control.MousePosition; //获取当前鼠标的屏幕坐标
            switch (Follow.Name)
            {
                case "Frm_ListBox":
                {
                    Tem_Top = Example_List_space_Top - FrmPoint.Y;
                    Tem_Left = Example_List_space_Left - FrmPoint.X;
                    break;
                }
                case "Frm_Libretto":
                {
                    Tem_Top = Example_Libretto_space_Top - FrmPoint.Y;
                    Tem_Left = Example_Libretto_space_Left - FrmPoint.X;
                    break;
                }
            }

            myPosittion.Offset(Tem_Left, Tem_Top);
            Follow.DesktopLocation = myPosittion;
        }
    }

    #endregion

    #region 对窗体的位置进行初始化

    /// <summary>
    /// 对窗体的位置进行初始化
    /// </summary>
    /// <param Frm="Form">窗体</param>
    public void FrmInitialize(Form Frm)
    {
        switch (Frm.Name)
        {
            case "Frm_Play":
            {
                Example_Play_Top = Frm.Top;
                Example_Play_Left = Frm.Left;
                Example_Play_Width = Frm.Width;
                Example_Play_Height = Frm.Height;
                break;
            }
            case "Frm_ListBox":
            {
                Example_List_Top = Frm.Top;
                Example_List_Left = Frm.Left;
                Example_List_Width = Frm.Width;
                Example_List_Height = Frm.Height;
                break;
            }
            case "Frm_Libretto":
            {
                Example_Libretto_Top = Frm.Top;
                Example_Libretto_Left = Frm.Left;
                Example_Libretto_Width = Frm.Width;
                Example_Libretto_Height = Frm.Height;
                break;
            }
        }
    }

    #endregion

    #region 存储各窗体的当前信息

    /// <summary>
    /// 存储各窗体的当前信息
    /// </summary>
    /// <param Frm="Form">窗体</param>
    /// <param e="MouseEventArgs">控件的移动事件</param>
    public void FrmPlace(Form Frm)
    {
        FrmInitialize(Frm);
        FrmMagnetism(Frm);
    }

    #endregion

    #region 窗体的磁性设置

    /// <summary>
    /// 窗体的磁性设置
    /// </summary>
    /// <param Frm="Form">窗体</param>
    public void FrmMagnetism(Form Frm)
    {
        if (Frm.Name != "Frm_Play")
        {
            FrmMagnetismCount(Frm, Example_Play_Top, Example_Play_Left, Example_Play_Width, Example_Play_Height,
                "Frm_Play");
        }

        if (Frm.Name != "Frm_ListBos")
        {
            FrmMagnetismCount(Frm, Example_List_Top, Example_List_Left, Example_List_Width, Example_List_Height,
                "Frm_ListBos");
        }

        if (Frm.Name != "Frm_Libratto")
        {
            FrmMagnetismCount(Frm, Example_Libretto_Top, Example_Libretto_Left, Example_Libretto_Width,
                Example_Libretto_Height, "Frm_Libratto");
        }

        FrmInitialize(Frm);
    }

    #endregion

    #region 磁性窗体的计算

    /// <summary>
    /// 磁性窗体的计算
    /// </summary>
    /// <param Frm="Form">窗体</param>
    /// <param e="MouseEventArgs">控件的移动事件</param>
    public void FrmMagnetismCount(Form Frm, int top, int left, int width, int height, string Mforms)
    {
        bool Tem_Magnetism = false; //判断是否有磁性发生
        string Tem_MainForm = ""; //临时记录主窗体
        string Tem_AssistForm = ""; //临时记录辅窗体

        //上面进行磁性窗体
        if ((Frm.Top + Frm.Height - top) <= Example_FSpace && (Frm.Top + Frm.Height - top) >= -Example_FSpace)
        {
            //当一个主窗体不包含辅窗体时
            if ((Frm.Left >= left && Frm.Left <= (left + width)) ||
                ((Frm.Left + Frm.Width) >= left && (Frm.Left + Frm.Width) <= (left + width)))
            {
                Frm.Top = top - Frm.Height;
                if ((Frm.Left - left) <= Example_FSpace && (Frm.Left - left) >= -Example_FSpace)
                    Frm.Left = left;
                Tem_Magnetism = true;
            }

            //当一个主窗体包含辅窗体时
            if (Frm.Left <= left && (Frm.Left + Frm.Width) >= (left + width))
            {
                Frm.Top = top - Frm.Height;
                if ((Frm.Left - left) <= Example_FSpace && (Frm.Left - left) >= -Example_FSpace)
                    Frm.Left = left;
                Tem_Magnetism = true;
            }
        }

        //下面进行磁性窗体
        if ((Frm.Top - (top + height)) <= Example_FSpace && (Frm.Top - (top + height)) >= -Example_FSpace)
        {
            //当一个主窗体不包含辅窗体时
            if ((Frm.Left >= left && Frm.Left <= (left + width)) ||
                ((Frm.Left + Frm.Width) >= left && (Frm.Left + Frm.Width) <= (left + width)))
            {
                Frm.Top = top + height;
                if ((Frm.Left - left) <= Example_FSpace && (Frm.Left - left) >= -Example_FSpace)
                    Frm.Left = left;
                Tem_Magnetism = true;
            }

            //当一个主窗体包含辅窗体时
            if (Frm.Left <= left && (Frm.Left + Frm.Width) >= (left + width))
            {
                Frm.Top = top + height;
                if ((Frm.Left - left) <= Example_FSpace && (Frm.Left - left) >= -Example_FSpace)
                    Frm.Left = left;
                Tem_Magnetism = true;
            }
        }

        //左面进行磁性窗体
        if ((Frm.Left + Frm.Width - left) <= Example_FSpace && (Frm.Left + Frm.Width - left) >= -Example_FSpace)
        {
            //当一个主窗体不包含辅窗体时
            if ((Frm.Top > top && Frm.Top <= (top + height)) ||
                ((Frm.Top + Frm.Height) >= top && (Frm.Top + Frm.Height) <= (top + height)))
            {
                Frm.Left = left - Frm.Width;
                if ((Frm.Top - top) <= Example_FSpace && (Frm.Top - top) >= -Example_FSpace)
                    Frm.Top = top;
                Tem_Magnetism = true;
            }

            //当一个主窗体包含辅窗体时
            if (Frm.Top <= top && (Frm.Top + Frm.Height) >= (top + height))
            {
                Frm.Left = left - Frm.Width;
                if ((Frm.Top - top) <= Example_FSpace && (Frm.Top - top) >= -Example_FSpace)
                    Frm.Top = top;
                Tem_Magnetism = true;
            }
        }

        //右面进行磁性窗体
        if ((Frm.Left - (left + width)) <= Example_FSpace && (Frm.Left - (left + width)) >= -Example_FSpace)
        {
            //当一个主窗体不包含辅窗体时
            if ((Frm.Top > top && Frm.Top <= (top + height)) ||
                ((Frm.Top + Frm.Height) >= top && (Frm.Top + Frm.Height) <= (top + height)))
            {
                Frm.Left = left + width;
                if ((Frm.Top - top) <= Example_FSpace && (Frm.Top - top) >= -Example_FSpace)
                    Frm.Top = top;
                Tem_Magnetism = true;
            }

            //当一个主窗体包含辅窗体时
            if (Frm.Top <= top && (Frm.Top + Frm.Height) >= (top + height))
            {
                Frm.Left = left + width;
                if ((Frm.Top - top) <= Example_FSpace && (Frm.Top - top) >= -Example_FSpace)
                    Frm.Top = top;
                Tem_Magnetism = true;
            }
        }

        if (Frm.Name == "Frm_Play")
            Tem_MainForm = "Frm_Play";
        else
            Tem_AssistForm = Frm.Name;
        if (Mforms == "Frm_Play")
            Tem_MainForm = "Frm_Play";
        else
            Tem_AssistForm = Mforms;
        if (Tem_MainForm == "")
        {
            Example_Assistant_AdhereTo = Tem_Magnetism;
        }
        else
        {
            switch (Tem_AssistForm)
            {
                case "Frm_ListBos":
                    Example_List_AdhereTo = Tem_Magnetism;
                    break;
                case "Frm_Libratto":
                    Example_Libretto_AdhereTo = Tem_Magnetism;
                    break;
            }
        }
    }

    #endregion

    #region 恢复窗体的初始大小

    /// <summary>
    /// 恢复窗体的初始大小(当松开鼠标时,如果窗体的大小小于300*200,恢复初始状态)
    /// </summary>
    /// <param Frm="Form">窗体</param>
    public void FrmScreen_FormerlySize(Form Frm, int PWidth, int PHeight)
    {
        if (Frm.Width < PWidth || Frm.Height < PHeight)
        {
            Frm.Width = PWidth;
            Frm.Height = PHeight;
            //Example_Size = false;
        }
    }

    #endregion
}
static class Program
{
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Frm_Play());
    }
}

到此这篇关于基于C#实现磁性吸附窗体的文章就介绍到这了,更多相关C#磁性吸附窗体内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • C#实现简单的聊天窗体

    本文实例为大家分享了C#实现简单的聊天窗体的具体代码,供大家参考,具体内容如下 一.要使用(学习)到的知识点 1.textBox控件 (1)功能:允许用户输入文本,并提供多行编辑和密码字符掩码功能 (2)它右什么属性? ​ ①Multiline ​ 表示获取或设置一个值,该值指示这是否为多行textBox控件 textBox2.Multiline = true;//意思就是将textbox2设置为可以多行显示 ​ ②TabIndex ​ 表示获取或设置控件在其容器内的Tab键顺序 textBox

  • 深入理解C#窗体关闭事件

    目录 1.第一步 2.第二步 3.最后可以检查一下设计designer.cs的文件看看对不对 很多初学者都想把默认的C#关闭按钮事件弄明白,主要用在我想关闭窗口但是我还想在关闭前有一个提示,可是网上真的有太多的答案都是错的,今天在这里从头到尾给大家设置一下,希望可以帮到大家. 1.第一步 2.第二步 名号命名好后,双击这个名字就可以对这个事件进行编辑了,找不到的就可以进入.cs文件自己查看 private void frmMom_FormClosing(object sender, FormCl

  • C#模拟实现QQ窗体功能

    目录 案例简述 预备知识导图 功能结构 知识点分析 C#基础知识 Windows系统知识 控件和组件 案例简述 通过C#使用类似QQ窗体的功能,当窗体放置到屏幕的边缘,可以将窗体隐藏,当鼠标再次放置到屏幕边缘时,窗体可再次显示. 预备知识导图 功能结构 由于本案例主要通过窗体和鼠标位置句柄的比对,以及判断窗体在屏幕的位置,进行窗体的移动和隐藏.窗体的隐藏通过时间控件循环.涉及的功能如下 获取当前鼠标位置的句柄 获取当前窗体的句柄 比对鼠标位置所在控件的句柄和窗体句柄,进行窗体的移动 判断当前窗体

  • C#实现在窗体上的统计图效果

    本文实例为大家分享了C#实现在窗体上的统计图,供大家参考,具体内容如下 忽然要用到C#来制作统计图,起初不太清除怎么弄,看了一些代码实现统计图的文档.终于实现了条形图的设置,后来又需要饼状图.本来还是想自己画的后来才发现C#是有这种窗体控件的,控件画比我强太多了. 这是我自己做的条形图的函数: public static int width = 400, height = 400;//声明宽与高   Bitmap bitmap = new Bitmap(width, height);//创建一个

  • C#调用Windows的API实现窗体动画

    在VF.VB.PB的应用中,有些无法通过语言工具本身来完成的或者做得不理想的功能,我们会考虑通过Windows的API来完成. 在那个年代,熟悉API是一个编程者的基本功.那个时候网络信息也不发达,很多资料只能考购买书籍或者自己摸索来获取,每次掌握一个新的API应用内心里都有点小激动. Powerbuilder数据功能强大,但是界面功能尤其是动画功能比较弱,通过调用Windows的API实现窗体动画比较容易. 声明API调用: function boolean AnimateWindow ( l

  • 基于C#实现磁性吸附窗体

    目录 实践过程 效果 代码 实践过程 效果 代码 public partial class Frm_Libretto : Form { public Frm_Libretto() { InitializeComponent(); } #region 公共变量 FrmClass Cla_FrmClass = new FrmClass(); #endregion private void Frm_Libretto_Load(object sender, EventArgs e) { this.Top

  • javascript动画之磁性吸附效果篇

    前面的话 上一篇,我们介绍了javascript动画之模拟拖拽效果篇.但在实际应用中,常常需要为拖拽的元素限定范围.而通过限定范围,再增加一些辅助的措施,就可以实现磁性吸附的效果 范围限定 如果我们限定元素只可以在可视范围内移动,那么就需要对其进行范围限定 首先,先要搞清楚是可视区域限定被拖拽元素 左侧范围L0 = 0 右侧范围R0 = document.documentElement.clientWidth 上侧范围T0 = 0 下侧范围B0 = document.documentElemen

  • js实现磁性吸附的示例

    磁性吸附 目录 代码实例 与限定范围拖拽的差异 下载源码链接 代码实例 * { padding: 0; margin: 0; } #box1 { width: 500px; height: 500px; background: #999; position: relative; left: 100px; top: 100px; } #box { width: 100px; height: 100px; background: #334; position: absolute; cursor: m

  • javascript拖拽应用实例(二)

    经常在网站别人的网站的注册页中看到一个拖拽验证的效果,就是它的验证码刚开始不出来,而是有一个拖拽的条,你必须将这个拖拽条拖到底,验证码才出来,说了感觉跟没说一样,你还是不理解,好吧,我给个图你看看: 这个是在万网的注册页中所截的图,大概的效果就是,当拖动那个拖拽框时,如果拖拽框没有拖到最右边,则拖拽框会移动到初始位置,如果拖动到最右边,则拖拽框显示为对勾,中间的文字也变了,但是我试了一下,他的验证码的框没有出来,不知道是改了还是怎么的,我没有继续点击确定往下进行,那不是我们要讲的重点,我就在他的

  • Python中tkinter的用户登录管理的实现

    内容 编写一个用户登录管理程序,设计窗体的布局,制定密码规则和验证码规则.要求使用 Python 标准库 tkinter 编写基于GUI 的用户登录窗体.通过该窗体,用户输入用户名.密码和验证码等信息,确认登录后需要判断用户信息是否合法,并弹出对应的反馈信息.通过判断用户是否在用户信息中,以及输入密码是否与用户信息文件中用户名所对应的密码是否相同,来判断用户是否合法.此外,新用户还可以进行注册,注册需要输入用户名.密码.手机号和身份证号等信息.注册时密码需要遵循一定规则(长度不小于8且含有数字.

  • vue2结合element-ui的gantt图实现可拖拽甘特图

    目录 一.前言 二.主要功能 三.功能实现 四.实现效果 总结 一.前言 接到公司需求,要做一个可拖拽的甘特图来实现排期需求,官方的插件要付费还没有中文的官方文档可以看,就去找了各种开源的demo来看,功能上都不是很齐全,于是总结了很多demo,合在一起组成了一版较为完整的满足需求的甘特图. 二.主要功能 1.拖拽  拖拽功能是甘特图的主要功能,该demo实现了甘特图时间块上.下.左.右拖拽功能. 2.排序 拖拽后时间块进行排序,计算重叠区域大小确定插入位置. 3.时间选择 结合element-

  • Android实现带磁性的悬浮窗体效果

    本文实例讲述了Android实现带磁性的悬浮窗体效果.分享给大家供大家参考,具体如下: 带磁性的悬浮窗体,类似于360绿色小人 主要实现的是: 1.悬浮所有窗体之上 2.有吸引力,吸附于屏幕边上 3.有点击效果 下面我就实现上面三点,简单封装了个FloatView 先看下本次Demo的效果图,然后再看代码, 效果图: FloatView代码如下 package com.manymore13.flowwindowdemo; import android.content.Context; impor

  • 基于Java语言在窗体上实现飞机大战小游戏的完整步骤

    目录 小组项目 模块需求描述 总体开发思想 功能实现 1.登录与结束界面 2.播放音乐 3.子弹 运行测试 登陆界面 发射子弹 总结 小组项目 飞机大战:用 Java 语言在窗体上实现飞机大战小游戏,运行程序后,出现一个窗体,在窗体上用鼠标控制英雄机的移动,通过子弹打击敌机进行分数的计算,以及英雄机血量的计算等. 主要模块:登陆界面.音乐.子弹.敌机.英雄机.背景图.结束界面.BOSS 机.分数计算.血量计算. 负责模块:登陆界面.音乐.子弹.结束界面. 模块需求描述 登陆界面:运行程序后,弹出

  • vue基于websocket实现智能聊天及吸附动画效果

    目录 前言: 1.效果如下: 2.主要功能: 2.1.基于websocket实现聊天功能,封装了一个socket.js文件 2.2使用Jwchat插件实现类似QQ.微信电脑端的功能 2.3动画效果(如关闭打开时动画.吸附效果及其他效果) 3.实现步骤: 3.1.实现websocket聊天功能 3.2.在页面中的使用方法: 关闭连接 发送给后端的方法 4.使用Jwchat插件实现类似QQ.微信电脑端的功能 4.1步骤 5.动画效果 前言: 发现这篇文章写的有点多,我总结一下整体思路: 首先这个功能

  • 基于swing实现窗体拖拽和拉伸

    本文为大家分享了swing实现窗体拖拽和拉伸的具体代码,供大家参考,具体内容如下 当用setUndecorated(true) 后 JFrame去掉标题栏后就得自己写拖拽和拉伸功能了. 下面是效果图,我的截图软件不能够截取除系统默认光标外的光标,所以各个方向光标变化在图中没有体现 代码如下: import javax.swing.*; import java.awt.*; /** * 窗体拖拽和拉伸 */ public class winReSizeDemo { private JFrame j

随机推荐