C#无边框窗体实现以及拖动代码

实现效果:

代码:

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

namespace NoBorderForm
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    Point mouseOff;//鼠标移动位置变量
    bool leftFlag;//标记是否为左键
    private void Form1_MouseDown(object sender, MouseEventArgs e)
    {
      if (e.Button == MouseButtons.Left)
      {
        mouseOff = new Point(-e.X, -e.Y); //得到变量的值
        leftFlag = true;         //点击左键按下时标注为true;
      }
    }

    private void Form1_MouseMove(object sender, MouseEventArgs e)
    {
      if (leftFlag)
      {
        Point mouseSet = Control.MousePosition;
        mouseSet.Offset(mouseOff.X, mouseOff.Y); //设置移动后的位置
        Location = mouseSet;
      }
    }

    private void Form1_MouseUp(object sender, MouseEventArgs e)
    {
      if (leftFlag)
      {
        leftFlag = false;//释放鼠标后标注为false;
      }
    }

    private void button1_Click(object sender, EventArgs e)
    {
      DialogResult dr = MessageBox.Show("yes/no", "exit", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
      if (dr == DialogResult.Yes)
      {
        this.Close();
      }
      else
      {
        return;
      }
    }

    private void button2_Click(object sender, EventArgs e)
    {
      this.WindowState = FormWindowState.Minimized;
    }

    private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {

    }

    private void Form1_Click(object sender, EventArgs e)
    {

    }

    private void panel1_Click(object sender, EventArgs e)
    {

    }

    private void textBox1_Click(object sender, EventArgs e)
    {

    }

    private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
      System.Diagnostics.Process.Start("http://www.baidu.com");
    }

    private void button4_Click(object sender, EventArgs e)
    {

    }
  }
}

您可能感兴趣的文章:

  • C# 改变无边框窗体尺寸大小的方法
  • C# 无边框窗体之窗体移动实现代码
  • C# 无边框窗体边框阴影效果的简单实现
  • C#中无边框窗体移动的简单实例
(0)

相关推荐

  • C# 无边框窗体边框阴影效果的简单实现

    通过下面代码在构造函数中调用方法 SetShadow(); 即可实现无边框窗体的阴影效果了 需要添加命名空间 using System.Runtime.InteropServices; 复制代码 代码如下: private const int CS_DropSHADOW = 0x20000;        private const int GCL_STYLE = (-26); [DllImport("user32.dll", CharSet = CharSet.Auto)]     

  • C# 无边框窗体之窗体移动实现代码

    点击窗体任意位置移动窗体: 需要添加命名空间: using System.Runtime.InteropServices; 复制代码 代码如下: private const int WM_NCLBUTTONDOWN = 0x00A1;private  const int HTCAPTION = 2;[DllImport("user32.dll", CharSet = CharSet.Unicode)]public static extern IntPtr SendMessage(Int

  • C#中无边框窗体移动的简单实例

    首先建一个Windows应用程序将Form1的 FormBorderStyle属性设置为Noe 复制代码 代码如下: Point mouseOff;//鼠标移动位置变量        bool leftFlag;//标记是否为左键        private void Form1_MouseDown(object sender, MouseEventArgs e)        {            if (e.Button == MouseButtons.Left)           

  • C# 改变无边框窗体尺寸大小的方法

    复制代码 代码如下: Code highlighting produced by Actipro CodeHighlighter (freeware)const int HTLEFT = 10;const int HTRIGHT = 11;const int HTTOP = 12;const int HTTOPLEFT = 13;const int HTTOPRIGHT = 14;const int HTBOTTOM = 15;const int HTBOTTOMLEFT = 0x10;cons

  • C#无边框窗体实现以及拖动代码

    实现效果: 代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace NoBorderForm { p

  • python用WxPython库实现无边框窗体和透明窗体实现方法详解

    wxPython是Python语言的一套优秀的GUI图形库.允许Python程序员很方便的创建完整的.功能键全的GUI用户界面. wxPython是作为优秀的跨平台GUI库wxWidgets的Python封装和Python模块的方式提供给用户的. 下面的2个实例代码是实现wxPython窗体特殊效果演示大家可以研究下 wxPython无边框窗体实现代码如下: import wx class Frame(wx.Frame): def __init__(self):#,pos=(0,0) wx.Fr

  • python实现无边框进度条的实例代码

    上python课程时需要设计一个系统,想着为系统加一个启动动画,所以做成了图片加进度条的形式. 本文旨在用python实现无边框的进度条,并在其基础上加了图片,体现了某程序加载动画的效果 实现说明 1.进度条的部分用到了tkinter中的画布组件 2.图片无边框显示用到了PYQT5中的QMainWindow, QApplication (由于水平有限,只好用两个不同的库来实现) 源代码 import sys from PyQt5.QtCore import Qt from PyQt5.QtWid

  • PyQt5实现无边框窗口的标题拖动和窗口缩放

    网上找了半天都找不到好用的PyQt5无边框窗口的实现,借鉴部分前辈的窗口拖放代码,自己实现了一下无边框窗口,问题可能还有一点,慢慢改吧 先做个笔记 py文件 #!/usr/bin/env python #-*- coding:utf-8 -*- from PyQt5.QtWidgets import QWidget, QLabel, QPushButton, QVBoxLayout from PyQt5.QtCore import Qt, QPoint from PyQt5.QtGui impo

  • C# 实现窗口无边框,可拖动效果

    具体代码如下所示: #region 无边框拖动效果 [DllImport("user32.dll")]//拖动无窗体的控件 public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); public const int

  • WPF设置窗体可以使用鼠标拖动大小的方法

    本文实例讲述了WPF设置窗体可以使用鼠标拖动大小的方法.分享给大家供大家参考.具体实现方法如下: 复制代码 代码如下: private void Window_Loaded(object sender, RoutedEventArgs e) {     // 获取窗体句柄     IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle; // 获得窗体的 样式     int oldstyle = Nat

随机推荐