liujie164 发表于 2008-6-24 10:22

C#程序模拟Vista界面效果

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Vista
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.AllPaintingInWmPaint|ControlStyles.OptimizedDoubleBuffer|ControlStyles.UserPaint,true);
            this.SetStyle(ControlStyles.SupportsTransparentBackColor,true);
        }
        private const int WM_NCHITTEST = 0x84;//132
        private const int HTCLIENT = 0x1;//1
        private const int HTCAPTION = 0x2;//2
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_NCHITTEST:
                    base.WndProc(ref m);
                    if ((int)m.Result == HTCLIENT)//1
                        m.Result = (IntPtr)HTCAPTION;//2
                    return;
                    break;
            }
            base.WndProc(ref m);
        }
        private Bitmap topleft = new Bitmap(System.AppDomain.CurrentDomain.BaseDirectory+"top_left.png");
        private Bitmap topmiddle = new Bitmap(System.AppDomain.CurrentDomain.BaseDirectory+"top.png");
        private Bitmap topright = new Bitmap(System.AppDomain.CurrentDomain.BaseDirectory+"top_right.png");
        private Bitmap left = new Bitmap(System.AppDomain.CurrentDomain.BaseDirectory+"left.png");
        private Bitmap right = new Bitmap(System.AppDomain.CurrentDomain.BaseDirectory+"right.png");
        private Bitmap bottomleft = new Bitmap(System.AppDomain.CurrentDomain.BaseDirectory+"bottom_left.png");
        private Bitmap bottommiddle = new Bitmap(System.AppDomain.CurrentDomain.BaseDirectory+"bottom.png");
        private Bitmap bottomright = new Bitmap(System.AppDomain.CurrentDomain.BaseDirectory + "bottom_right.png");
        private Image img;
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = Graphics.FromImage(img);
            g.Clear(Color.Black);
            g.CopyFromScreen(new Point(0,0),new Point(0,0),Screen.AllScreens[0].Bounds.Size,CopyPixelOperation.SourcePaint);
            Rectangle rectel = new Rectangle(0,0,this.Width,this.Height);
            Rectangle rec = new Rectangle(this.Location,this.Size);
            Bitmap bit = new Bitmap(this.Width,this.Height);
            Graphics grafic = Graphics.FromImage(bit);
            grafic.DrawImage(img,rectel,rec,GraphicsUnit.Pixel);
            BackgroundImage = bit;
            e.Graphics.DrawImage(topleft,new Rectangle(0,0,topleft.Width,topleft.Height),0,0,topleft.Width,topleft.Height,GraphicsUnit.Pixel);
            e.Graphics.DrawImage(topmiddle,topleft.Width,0,Width-topleft.Width-topright.Width+1,topmiddle.Height);
            e.Graphics.DrawImage(topright,Width-topright.Width,0,topright.Width,topright.Height);
            e.Graphics.DrawImage(left,0,topleft.Height,left.Width,Height-topleft.Height-bottomleft.Height);
            e.Graphics.DrawImage(right,Width-topright.Width,topright.Height,right.Width,Height-topright.Height-bottomright.Height);
            e.Graphics.DrawImage(bottomleft,0,Height-bottomleft.Height,bottomleft.Width,bottomleft.Height);
            e.Graphics.DrawImage(bottommiddle,bottomleft.Width,Height-bottommiddle.Height,Width-bottomleft.Width-bottomright.Width+1,bottommiddle.Height);
            e.Graphics.DrawImage(bottomright,Width-bottomright.Width,Height-bottomright.Height,bottomright.Width,bottomright.Height);
            e.Dispose();
           // base.OnPaint(e);
        }
        protected override void OnLoad(EventArgs e)
        {
            img = new Bitmap(Screen.AllScreens[0].Bounds.Width,Screen.AllScreens[0].Bounds.Height);
            //base.OnLoad(e);
        }
    }
}[img]http://photo.store.qq.com/http_imgload.cgi?/rurl2=e3286188b69c163ea19f4c493a71e3a3455db6b6ff238f1ce9fa0ccbc17757fcee773b919ba9d642c90208653cacbb3a225a7e165b1442c2cd6477957f59b6fcd58e5480d1bf023827fda3707bc405a19fdab10c[/img]

本人新建群25376219,大量召集高手,非程序人员勿挠,只讨论ASP.net,C#,Java,c++,C,SQL server,Oracle,本人所会Java,C#.Net,JavaWeb,SQL server 正在学的有asp.net和C++


页: [1]

编程论坛