1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace WinSkinned
{
public partial class frmSkinned : Form
{
private Point mouseOffset;
private Boolean isMouseDown = false;
private Bitmap bmp;
private Rectangle rectBmp;
private Button btnClose;
public frmSkinned()
{
InitializeComponent();
bmp=WinSkinned.Properties.Resources.barretache;
rectBmp = new Rectangle(20, this.Top+this.Width/2, bmp.Width, bmp.Height);
//ajout d' un bouton positionne sur l'image coin droit
//meme hauteur image
btnClose = new Button();
btnClose.Text = "Close";
btnClose.Size=new Size(40,20);
btnClose.Location = new Point(rectBmp.Right - btnClose.Width, rectBmp.Top);
this.Controls.Add(btnClose);
//handler du bouton
btnClose.Click+=new EventHandler(btnClose_Click);
}
private void btnClose_Click(object sender,System.EventArgs e)
{
this.Close();
}
private void frmSkinned_Paint(object sender, PaintEventArgs e)
{
GraphicsPath path = new GraphicsPath();
Rectangle rectPath = new Rectangle(0, 0, this.Width, this.Height );
path.AddEllipse(0, 0, rectPath.Width, rectPath.Height);
e.Graphics.FillPath(Brushes.Aquamarine, path);
e.Graphics.DrawPath(new Pen(Brushes.Black, 2.0F), path);
e.Graphics.DrawImage(bmp, rectBmp.Left,rectBmp.Top , bmp.Width, bmp.Height);
// le region est une "area" definie par le path
// c'est la "area visible & clickable" d'un controle
this.Region = new Region(path);
}
private void frmSkinned_MouseDown(object sender, MouseEventArgs e)
{
Point ptMove = e.Location;
if (e.Button == MouseButtons.Left && rectBmp.IsEmpty==false)
{
if (rectBmp.Contains(ptMove))
{
int xOffset = -e.X;
int yOffset = -e.Y ;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}
}
private void frmSkinned_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{
Point mousePos= Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
this.Location = mousePos;
}
}
private void frmSkinned_MouseUp(object sender, MouseEventArgs e)
{
// Changes the isMouseDown field so that the form does
// not move unless the user is pressing the left mouse button.
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}
}
} |
Partager