| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- 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);
- }
- }
- }
- }
|