您的位置:首页 > 移动开发 > 微信开发

winform窗体 小程序【移动窗体和阴影】

2017-05-05 12:52 417 查看

 

 

窗体无边框设置后无法移动,引用API 使其获得功能

移动

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

namespace WindowsFormsApplication2
{
public partial class Form4 : Form
{
//窗体移动API
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
[DllImport("user32")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, IntPtr lParam);
private const int WM_SETREDRAW = 0xB;

public Form4()
{
InitializeComponent();
}

private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
}

//鼠标进入时发生
private void pictureBox2_MouseEnter(object sender, EventArgs e)
{
pictureBox2.BackgroundImage = Image.FromFile(@"e:/c2.png"); //改变背景图
}                                               // @  --字符串的原样输出,加不加都像
//e:/c2.png --图片的地址

//鼠标离开时时发生 -- 刚开始默认图片是c1.png
private void pictureBox2_MouseLeave(object sender, EventArgs e)
{
pictureBox2.BackgroundImage = Image.FromFile(@"e:/c1.png");
}

//鼠标按下时发生
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
pictureBox2.BackgroundImage = Image.FromFile(@"e:/c3.png");
}

//点击时发生
private void pictureBox2_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;   //最大化

// this.Close();      关闭
}

}
}
View Code

 

背景图片的设置

pictureBox1.BackgroundImage = Image.FromFile(" 图片路径地址 " );

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: