• 一个关于工具条可以移动和在四周停留的测试


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace qi
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }
    bool flag=false;
    bool ok = false;
    int fangshi = 0;
    Graphics mygf;
    Pen mypen = new Pen(Color.Red);
    Color mycl = new Color();
    int width, height;
    private void Form1_MouseMove(object sender, MouseEventArgs e)
    {
    if (flag)
    {
    mygf.Clear(mycl);
    mygf.DrawRectangle(mypen, e.X - width, e.Y - 5, width, height);
    if (e.X < 20 && e.Y > 20 && e.Y < (this.Size.Height - 20))
    {
    mygf.Clear(mycl);
    mygf.DrawRectangle(mypen, 0, 0, 20, this.Size.Height);
    fangshi = 1;
    }
    else if (e.Y < 20 && e.X < (this.Size.Width - 20))
    {
    mygf.Clear(mycl);
    mygf.DrawRectangle(mypen, 0, 0, this.Size.Width, 20);
    fangshi = 2;
    }

    else if (e.Y < (this.Size.Height - 20) && e.X > (this.Size.Width - 40))
    {
    mygf.Clear(mycl);
    mygf.DrawRectangle(mypen, this.Size.Width - 35, 0, 30, this.Size.Height);
    fangshi = 3;
    }
    else if (e.Y > (this.Size.Height - 55))
    {
    mygf.Clear(mycl);
    mygf.DrawRectangle(mypen, 0, (this.Size.Height - 55), this.Size.Width, 20);
    fangshi = 4;
    }
    else
    fangshi = 0;

    }
    }

    private void toolStrip1_MouseDown(object sender, MouseEventArgs e)
    {
    toolStrip1.Visible = false;
    flag = true;
    }

    private void Form1_MouseUp(object sender, MouseEventArgs e)
    {
    if (flag)
    {
    toolStrip1.Location = new Point(e.X - width, e.Y - 5);

    switch (fangshi)
    {
    case 0:
    toolStrip1.Dock = DockStyle.None;
    break;
    case 1:
    toolStrip1.Dock = DockStyle.Left;
    break;
    case 2:
    toolStrip1.Dock = DockStyle.Top;
    break;
    case 3:
    toolStrip1.Dock = DockStyle.Right;
    break;
    case 4:
    toolStrip1.Dock = DockStyle.Bottom;
    break;
    }
    }
    toolStrip1.Visible = true;
    mygf.Clear(mycl);
    flag = false;
    fangshi = 0;
    }

    private void Form1_Load(object sender, EventArgs e)
    {
    mycl = this.BackColor;
    mygf = this.CreateGraphics();
    width = toolStrip1.Size.Width;
    height = toolStrip1.Size.Height;
    }
    }
    }
  • 相关阅读:
    Pycharm软件更换pip默认安装源为国内安装源
    电商网站名词item>SKU与SPU
    Linux通过端口号查看使用进程结束进程
    window系统下的pycharm对虚拟机中的Ubuntu系统操作MySQL数据库
    JAVA项目常用的异常处理情况总结
    公文流转系统(未完成)
    《程序员修炼之道》读后感(三)
    Java文件操作递归遍历文件目录
    Java Web初试连接数据库完成学生信息录入
    JavaJFrame窗口实现新课程添加
  • 原文地址:https://www.cnblogs.com/ganb/p/2296438.html
Copyright © 2020-2023  润新知