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

  • 相关阅读:
    栈:逆波兰表达式(后缀表达式)
    栈:实现综合计算器(中缀表达式)
    栈:数组模拟栈
    链表(Linked List):单向环形链表
    单链表常见面试题
    链表(Linked List):双向链表
    链表(Linked List): 单链表
    队列和环形队列
    稀疏数组
    Linux命令--pushd和popd
  • 原文地址:https://www.cnblogs.com/yply/p/10143414.html
Copyright © 2011-2022 走看看