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.Imaging; using System.Drawing.Drawing2D; using HXX.Scanner.Client.Properties; namespace HXX.Scanner.Client.Base { public partial class BaseForm : Form { public BaseForm() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true); InitializeComponent(); InitParts(); } protected override void OnPaint(PaintEventArgs e) { Calculate(); DrawBackground(e.Graphics); base.OnPaint(e); } PartBase partTopBG_Left; //PartBase partTopBG_Right; PartBase partTopBG_Center; PartBase partTopLine; PartBase partBottomLine; PartBase partLeftLine; PartBase partRightLine; PartBase partBottomSquare; FormWindowState _formState = FormWindowState.Normal; int _orginWidth; int _orginHeight; int _orginX; int _orginY; private void InitParts() { partTopLine = new PartBase(); partTopLine.BackgroundBitmap = Resources.HLine; partBottomLine = new PartBase(); partBottomLine.BackgroundBitmap = Resources.HLine; partLeftLine = new PartBase(); partLeftLine.BackgroundBitmap = Resources.VLine; partRightLine = new PartBase(); partRightLine.BackgroundBitmap = Resources.VLine; partTopBG_Left = new PartBase(); partTopBG_Left.BackgroundBitmap = Resources.topbg_left; //partTopBG_Right = new PartBase(); //partTopBG_Right.BackgroundBitmap = Resources.topbg_Right21; partTopBG_Center = new PartBase(); partTopBG_Center.BackgroundBitmap = Resources.topbg_Center; partBottomSquare = new PartBase(); partBottomSquare.BackgroundBitmap = Resources.BottomMiddle; b1.ReadButtonImage(Resources.MinNormal, Resources.MinMove, Resources.MinDown); //b2.ReadButtonImage(Resources.MaxNormal, Resources.MaxMove, Resources.MaxDown); b3.ReadButtonImage(Resources.CloseNormal, Resources.CloseMove, Resources.CloseDown); } private void Calculate() { partTopLine.X = 0; partTopLine.Y = 0; partTopLine.Height = partTopLine.BackgroundBitmap.Height; partTopLine.Width = this.Width; partBottomLine.X = 0; partBottomLine.Y = this.Height - partBottomLine.BackgroundBitmap.Height; partBottomLine.Height = partBottomLine.BackgroundBitmap.Height; partBottomLine.Width = this.Width; partLeftLine.X = 0; partLeftLine.Y = 0; partLeftLine.Height = this.Height; partLeftLine.Width = partLeftLine.BackgroundBitmap.Width; partRightLine.X = this.Width - partLeftLine.BackgroundBitmap.Width; partRightLine.Y = 0; partRightLine.Height = this.Height; partRightLine.Width = partRightLine.BackgroundBitmap.Width; partTopBG_Left.X = partLeftLine.Width; partTopBG_Left.Y = partTopLine.Height; partTopBG_Left.Height = partTopBG_Left.BackgroundBitmap.Height; partTopBG_Left.Width = partTopBG_Left.BackgroundBitmap.Width; //partTopBG_Right.X = partRightLine.X - partTopBG_Right.BackgroundBitmap.Width; //partTopBG_Right.Y = partTopLine.Height; //partTopBG_Right.Height = partTopBG_Right.BackgroundBitmap.Height; //partTopBG_Right.Width = partTopBG_Right.BackgroundBitmap.Width; partTopBG_Center.X = partTopBG_Left.X + partTopBG_Left.Width; partTopBG_Center.Y = partTopLine.Height; partTopBG_Center.Height = partTopBG_Center.BackgroundBitmap.Height; partTopBG_Center.Width = this.Width - partLeftLine.Width - partRightLine.Width - partTopBG_Left.Width;// - partTopBG_Right.Width; partBottomSquare.X = partLeftLine.Width; partBottomSquare.Y = this.Height - partBottomLine.Height - partBottomSquare.BackgroundBitmap.Height; partBottomSquare.Height = partBottomSquare.BackgroundBitmap.Height; partBottomSquare.Width = this.Width - partLeftLine.Width - partRightLine.Width; palCenter.Top = partTopBG_Left.Y + partTopBG_Left.Height; palCenter.Left = partLeftLine.Width; palCenter.Height = this.Height - partTopLine.Height - partTopBG_Left.Height - partBottomSquare.Height - partBottomLine.Height; palCenter.Width = this.Width - partLeftLine.Width - partRightLine.Width; b3.Top = partTopLine.Height; b3.Left = this.Width - 50; b2.Top = b3.Top; b2.Left = b3.Left - b2.Width + 1; b2.Visible = false; b1.Top = b3.Top; b1.Left = b2.Left - b1.Width + 1; } private void DrawBackground(Graphics g) { g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; ImageAttributes attribute = new ImageAttributes(); attribute.SetWrapMode(WrapMode.TileFlipXY); //g.Clear(Color.Transparent); //边框线 partTopLine.DrawSelf(g, attribute); partBottomLine.DrawSelf(g, attribute); partLeftLine.DrawSelf(g, attribute); partRightLine.DrawSelf(g, attribute); //Title图 partTopBG_Left.DrawSelf(g, null); //partTopBG_Right.DrawSelf(g, null); if (partTopBG_Center.Width > 0) { partTopBG_Center.DrawSelf(g, attribute); } //底部横块 partBottomSquare.DrawSelf(g, attribute); attribute.Dispose(); } private void NewBaseForm_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && _formState != FormWindowState.Maximized) //拖动窗体 { if (e.Y < partTopBG_Left.X + partTopBG_Left.Height) { BaseFormWin32.ReleaseCapture(); BaseFormWin32.SendMessage(Handle, 274, 61440 + 9, 0); return; } } } protected virtual void maxButton_Click(object sender, EventArgs e) { if (_formState == FormWindowState.Normal) { MaxWindow(); } else { NormalWindow(); } } protected virtual void minButton_Click(object sender, EventArgs e) { WindowState = FormWindowState.Minimized; } protected virtual void closeButton_Click(object sender, EventArgs e) { Close(); } private void NormalWindow() { this.Invalidate(); Left = _orginX; Top = _orginY; Width = _orginWidth; Height = _orginHeight; _formState = FormWindowState.Normal; } private void MaxWindow() { this.Invalidate(); //最大化之前记录窗口信息便于缩小 _orginHeight = Height; _orginWidth = Width; _orginX = Location.X; _orginY = Location.Y; Width = Screen.PrimaryScreen.WorkingArea.Width + 4; Height = Screen.PrimaryScreen.WorkingArea.Height + 4; Top = -1; Left = -1; _formState = FormWindowState.Maximized; } private void NewBaseForm_DoubleClick(object sender, EventArgs e) { //if (e.Y < partTopBG_Left.X + partTopBG_Left.Height) { maxButton_Click(null, null); } } private void NewBaseForm_Click(object sender, EventArgs e) { //Point p = this.PointToClient(Control.MousePosition); //if (p.X > partTopBG_Right.X && p.X < partTopBG_Right.X + partTopBG_Right.Width // && p.Y > partTopBG_Right.Y && p.Y < partTopBG_Right.Y + partTopBG_Right.Height) //{ // frmHelp frm = new frmHelp(); // frm.ShowDialog(); //} } } class PartBase { public int X { get; set; } public int Y { get; set; } public int Width { get; set; } public int Height { get; set; } public Bitmap BackgroundBitmap { get; set; } public Rectangle Rectangle { get { return new Rectangle(X, Y, Width, Height); } } public void DrawSelf(Graphics g, ImageAttributes attribute) { if (attribute != null) { g.DrawImage(BackgroundBitmap, Rectangle, 0, 0, Width, Height, GraphicsUnit.Pixel, attribute); } else { g.DrawImage(BackgroundBitmap, Rectangle); } } } }