zoukankan      html  css  js  c++  java
  • winform 以不规则图形背景显示窗体

    一:创建一个winform窗体,把BackgroundImage引入一个不规则的图片,设置属性BackgroundImageLayout为Stretch

    二:主要代码

    using System;
    using System.Drawing;
    using System.Media;
    using System.Runtime.InteropServices;
    using System.Security.Permissions;
    using System.Windows.Forms;
    
    namespace TestDemo
    {public partial class Form1 : Form
        {
            bool beginMove = false;
            int currentXPosition;
            int currentYPosition;
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                this.TransparencyKey = Color.White;             //设置默认透明色
                this.BackColor = this.TransparencyKey;          //设置当前窗体的背景色为透明
                this.FormBorderStyle = FormBorderStyle.None;    //隐藏窗体边框
            }
    
            private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                //窗体拖拽
                beginMove = true;
                currentXPosition = MousePosition.X;
                currentYPosition = MousePosition.Y;
                this.Refresh();
            }
    
            private void Form1_MouseLeave(object sender, EventArgs e)
            {
                //设置初始状态
                currentXPosition = 0;
                currentYPosition = 0;
                beginMove = false;
            }
    
            private void Form1_MouseMove(object sender, MouseEventArgs e)
            {
                if (beginMove)
                {
                    //根据鼠标X坐标确定窗体X坐标
                    this.Left += MousePosition.X - currentXPosition;
                    //根据鼠标Y坐标确定窗体Y坐标
                    this.Top += MousePosition.Y - currentYPosition;
                    currentXPosition = MousePosition.X;
                    currentYPosition = MousePosition.Y;
                }
               
            }
            private void Form1_MouseUp(object sender, MouseEventArgs e)
            {
                beginMove = false;
            }
            private void Form1_Click(object sender, EventArgs e)
            {
                try
                {
                    SoundPlayer player = new SoundPlayer();
                    player.SoundLocation = Application.StartupPath + "\BIGBANG.wav";
                    player.Load();
                    player.Play();
                }
                catch (Exception ex)
                {
    
                    MessageBox.Show(ex.Message);
                }
            }
        }
    }

    三:下载地址   

    点击下载 提取码:yd14

  • 相关阅读:
    java正则表达式语法详解及其使用代码实例 (转)
    【SpringMVC学习09】SpringMVC与前台的json数据交互 (转)
    SpringMVC基于代码的配置方式(零配置,无web.xml)
    倒车入库操作要求
    R通过RJDBC连接外部数据库 (转)
    卡尔曼滤波——11.预测峰值
    卡尔曼滤波——10.均值漂移
    卡尔曼滤波——6.评估高斯分布
    神经网络入门——16实现一个反向传播
    神经网络入门——15反向传播
  • 原文地址:https://www.cnblogs.com/yply/p/10143414.html
Copyright © 2011-2022 走看看