Skip to content

Instantly share code, notes, and snippets.

@kamizyo7
Last active December 29, 2015 04:21
Show Gist options
  • Save kamizyo7/2ecf62fc6b7f57b38719 to your computer and use it in GitHub Desktop.
Save kamizyo7/2ecf62fc6b7f57b38719 to your computer and use it in GitHub Desktop.
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 DesktopMaskot2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string path = @"C:\Users\User\Pictures\4234442.png";
show(path);
}
private void show(string path)
{
this.FormBorderStyle = FormBorderStyle.None;
size_change(path);
this.BackgroundImage = Image.FromFile(path);
this.TransparencyKey = Color.Black;
}
private void size_change(string path)
{
System.Drawing.Bitmap bmpSrc = new System.Drawing.Bitmap(path);
int width = bmpSrc.Width;
int height = bmpSrc.Height;
this.Size = new Size(width, height);
}
private Point lastMousePosition;
private bool mouseCapture;
private void Form1_MouseDown(object sender,MouseEventArgs e)
{
if(e.Button != MouseButtons.Left)
{
return;
}
this.lastMousePosition = Control.MousePosition;
this.mouseCapture = true;
}
private void Form1_MouseMove(object sender,MouseEventArgs e)
{
if(this.mouseCapture == false)
{
return;
}
Point mp = Control.MousePosition;
int offsetX = mp.X - this.lastMousePosition.X;
int offsetY = mp.Y - this.lastMousePosition.Y;
this.Location = new Point(this.Left + offsetX, this.Top + offsetY);
this.lastMousePosition = mp;
}
private void Form1_MouseUp(object sender,MouseEventArgs e)
{
if(e.Button != MouseButtons.Left)
{
return;
}
this.mouseCapture = false;
}
private void Form1_MouseCaptureChanged(object sender,EventArgs e)
{
if(this.mouseCapture == true && this.Capture == false)
{
this.mouseCapture = false;
}
}
private void Form1_MouseClick(object sender,MouseEventArgs e)
{
string wave_path = @"C:\Users\User\Documents\w\testty.wav";
PlaySound(wave_path);
}
private System.Media.SoundPlayer player = null;
private void PlaySound(string waveFile)
{
if (player != null)
StopSound();
player = new System.Media.SoundPlayer(waveFile);
player.Play();
}
private void StopSound()
{
if(player != null)
{
player.Stop();
player.Dispose();
player = null;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment