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


    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;
    }
    }
    }
  • 相关阅读:
    javascript的alert的使用
    UIGestureRecognizer对图像进行缩放、移动、旋转操作
    对开源库使用 AutoCAD 文件格式
    计算机图形学常用算法
    KMP字符串模式匹配详解
    C++面试题String函数实现
    c++虚函数解析
    c++内存分配
    win32编程入门
    C++中Int转换成String
  • 原文地址:https://www.cnblogs.com/ganb/p/2296438.html
Copyright © 2020-2023  润新知