一个不规则窗口界面的示例(原创)

www.wenhui.org 10/23/2002 CSharp vs Java

椭圆开窗体

using System;
using System.Drawing;
using System.Windows.Forms;

class EllipseClass : Form
{
    private Rectangle ellipseBounds = new Rectangle(new Point(0, 0), new Size(100, 50));
    private Brush solidAzureBrush = Brushes.Yellow;
    private Point m_pOffset = new Point(0, 0);

    public EllipseClass()
    {
        this.Text = "不规则图形";
        this.StartPosition = FormStartPosition.CenterScreen;
        this.BackColor = Color.Red;
        this.FormBorderStyle = FormBorderStyle.None;
        this.TransparencyKey = Color.Red;
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        Graphics dc = e.Graphics;
        dc.FillEllipse(solidAzureBrush, ellipseBounds);
    }

    protected override void OnMouseDown(MouseEventArgs e)
    {
        base.OnMouseDown(e);
        m_pOffset = new Point(e.X, e.Y);
        //Console.WriteLine("Down X:{0} ,Y:{1}",m_pOffset.X,m_pOffset.Y); 
    }

    protected override void OnMouseMove(MouseEventArgs e)
    {
        base.OnMouseMove(e);
        if (e.Button == MouseButtons.Left)
        {
            Point mousePos = Control.MousePosition;
            //Console.WriteLine("Move X:{0} ,Y:{1}",mousePos.X,mousePos.Y); 
            this.Location = new Point(mousePos.X - m_pOffset.X, mousePos.Y - m_pOffset.Y);
            //Console.WriteLine("Location X:{0} ,Y:{1}",this.Location.X,this.Location.Y); 
        }
    }

    public static void Main()
    {
        Application.Run(new EllipseClass());
    }
}
原作者:痕迹
来 源:本站
共有356位读者阅读过此文
Contributors: FHL