123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 |
- 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;
- namespace LYFZ.ComponentLibrary
- {
-
-
-
- public partial class BaseContentsFormMain : BaseFormRelease, LYFZ.StandardInterface.IFormMain
- {
-
- public BaseContentsFormMain()
- {
-
- InitializeComponent();
- this.ctlScrollBarH.Scroll += new EventHandler(ctlScrollBarH_Scroll);
- this.ctlScrollBarV.Scroll += new EventHandler(ctlScrollBarV_Scroll);
- this.plExMainContainer.Resize += new EventHandler(plExMainContainer_Resize);
- this.plFormMainContent.Resize += new EventHandler(plFormMainContent_Resize);
- this.Resize += new EventHandler(BaseContentsFormRelease_Resize);
- this.Shown += new EventHandler(BaseContentsFormRelease_Shown);
- this.isOverrideOnPaint = true;
- IsCustomScrollBar = false;
- this.plExMainContainer.MouseWheel += new MouseEventHandler(plExMainContainer_MouseWheel);
- this.ctlScrollBarV.MouseWheel += new MouseEventHandler(ctlScrollBarV_MouseWheel);
- }
-
-
-
-
- public void ReloadNewForm(object objNewForm)
- {
- LYFZ.ComponentLibrary.BaseContentsFormMain frm = (LYFZ.ComponentLibrary.BaseContentsFormMain)objNewForm;
- frm.TopLevel = this.TopLevel;
- frm.IsShadow = this.IsShadow;
- frm.MaximizeBox = this.MaximizeBox;
- frm.MinimizeBox = this.MinimizeBox;
- frm.IsShowCloseBox = this.IsShowCloseBox;
- frm.TitleBgImageHeight = this.TitleBgImageHeight;
- frm.BottomBgImageHeight = this.BottomBgImageHeight;
- frm.IsMaximized = this.IsMaximized;
- frm.FormMobile = this.FormMobile;
- frm.IsUserControlsSize = this.IsUserControlsSize;
- frm.Dock = this.Dock;
- frm.IsCustomScrollBar = this.IsCustomScrollBar;
- frm.Parent = this.Parent;
- frm.IsShowBtnFormMenu = this.IsShowBtnFormMenu;
- frm.IsShowBtnFormSkin = this.IsShowBtnFormMenu;
- frm.IsCloseForm = this.IsCloseForm;
- frm.IsMinimize = this.IsMinimize;
- if (!frm.IsMaximized && !frm.IsMinimize && !frm.IsCloseForm)
- {
- frm.SetCoverageTitleButtonEvent();
- }
- frm.Show();
-
- this.Close();
- this.Dispose();
- }
-
-
-
-
- public void SetError(string msg)
- {
- LabelEx tryLabMsg = new LabelEx();
- tryLabMsg.Text = msg;
- tryLabMsg.ForeColor =Color.Red;
- tryLabMsg.Font = new System.Drawing.Font("宋体", 12);
- tryLabMsg.Padding = new Padding(10);
- tryLabMsg.Dock = DockStyle.Fill;
- this.plExMainContainer.Controls.Add(tryLabMsg);
-
- }
-
-
-
-
-
-
-
- public LYFZ.StandardInterface.IMenuClick iMenuClick = null;
-
-
-
-
- public void SetCoverageTitleButtonEvent()
- {
- this.btnAppFormExit.Click += new EventHandler(ParentFormBtnAppFormExit_Click);
- this.btnAppFormMaximize.Click += new EventHandler(ParentFormBtnAppFormMaximize_Click);
- this.btnAppFormMinimize.Click += new EventHandler(ParentFormBtnAppFormMinimize_Click);
- isCoverageTitleButtonEvent = true;
- }
- bool isCoverageTitleButtonEvent = false;
- protected override void btnAppFormMaximize_Move(object sender, EventArgs e)
- {
- if (isCoverageTitleButtonEvent)
- {
- this.SetFormMzximizeBtn(this.ParentForm.WindowState);
- }
- else
- {
- base.btnAppFormMaximize_Move(sender, e);
- }
- }
-
-
-
-
-
- protected virtual void ParentFormBtnAppFormMinimize_Click(object sender, EventArgs e)
- {
- this.ParentForm.WindowState = FormWindowState.Minimized;
- }
-
-
-
-
-
- protected virtual void ParentFormBtnAppFormMaximize_Click(object sender, EventArgs e)
- {
- if (this.ParentForm.WindowState == FormWindowState.Normal)
- {
- this.ParentForm.WindowState = FormWindowState.Maximized;
-
- }
- else {
- this.ParentForm.WindowState = FormWindowState.Normal;
- }
-
- }
-
-
-
-
-
- protected virtual void ParentFormBtnAppFormExit_Click(object sender, EventArgs e)
- {
- this.ParentForm.Close();
- }
- #region 滚动轮滚动时滚动窗体
-
-
-
-
-
- int getMouseWheelDelta(MouseEventArgs e)
- {
-
-
-
- int tempDelta = -(e.Delta);
- if (tempDelta < this.ctlScrollBarV.Minimum)
- {
- tempDelta = this.ctlScrollBarV.Minimum;
- }
- int tempDifference = this.ctlScrollBarV.Maximum - this.ctlScrollBarV.LargeChange;
- int tempScrollBar = tempDifference / 120;
- if (tempScrollBar <= 0)
- {
- tempScrollBar = 1;
- }
- if (tempDelta == 120)
- {
- tempDelta = tempDifference;
- }
- else
- {
- tempDelta = tempDelta * tempScrollBar;
- if (tempDelta > tempDifference)
- {
- tempDelta = tempDifference;
- }
- }
-
- return tempDelta;
- }
- void ctlScrollBarV_MouseWheel(object sender, MouseEventArgs e)
- {
- this.ctlScrollBarV.Value = getMouseWheelDelta(e);
-
- scrollY = ctlScrollBarV.Value;
- this.plExMainContainer.AutoScrollPosition = new Point(scrollX, ctlScrollBarV.Value);
- }
- void plExMainContainer_MouseWheel(object sender, MouseEventArgs e)
- {
- this.ctlScrollBarV.Value = getMouseWheelDelta(e);
-
-
- scrollY = ctlScrollBarV.Value;
- }
- #endregion
-
-
-
- int PanlOffset = 0;
-
-
-
-
-
- void BaseContentsFormRelease_Shown(object sender, EventArgs e)
- {
- if (IsCustomScrollBar)
- {
- PanlOffset = 20;
- }
- ResetControls();
- }
-
-
-
-
-
- void BaseContentsFormRelease_Resize(object sender, EventArgs e)
- {
- isSetplExMainContainerFocus = true;
- ResetControls();
- }
-
-
-
-
-
- void plFormMainContent_Resize(object sender, EventArgs e)
- {
- isSetplExMainContainerFocus = true;
- ResetControls();
- }
-
-
-
-
-
- void plExMainContainer_Resize(object sender, EventArgs e)
- {
- if (!this.TopLevel)
- {
- ResetControls();
- }
- isSetplExMainContainerFocus = true;
- }
-
-
-
- void ResetControls()
- {
- SetplExMainContainerSize(PanlOffset);
- SetScrollBarAttr();
- InitializeScrollBar();
-
- }
-
- int scrollX = 0;
- int scrollY = 0;
- bool isShowCtlScrollBarV = false;
- bool isShowCtlScrollBarH = false;
- void ctlScrollBarV_Scroll(object sender, EventArgs e)
- {
-
- scrollY = ctlScrollBarV.Value;
- this.plExMainContainer.AutoScrollPosition = new Point(scrollX, ctlScrollBarV.Value);
-
- }
- void ctlScrollBarH_Scroll(object sender, EventArgs e)
- {
-
- scrollX = ctlScrollBarH.Value;
- this.plExMainContainer.AutoScrollPosition = new Point(ctlScrollBarH.Value, scrollY);
- }
-
-
-
-
- protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
- {
- base.OnPaint(e);
- SetplExMainContainerSize(PanlOffset);
- }
-
-
-
- public void SetplExMainContainerSize(int offset = 0)
- {
-
- this.plFormMainContent.Location = new Point(0, this.TitleBgImageHeight);
-
- isShowCtlScrollBarH = this.plExMainContainer.HorizontalScroll.Visible;
- isShowCtlScrollBarV = this.plExMainContainer.VerticalScroll.Visible;
- if (IsCustomScrollBar)
- {
- if (isShowCtlScrollBarV)
- {
- this.ctlScrollBarV.Visible = true;
- this.plFormMainContent.Width = this.Width - offset;
- this.plExMainContainer.Width = this.plFormMainContent.Width + offset - 4;
- }
- else
- {
- this.ctlScrollBarV.Visible = false;
- this.plFormMainContent.Width = this.Width;
- this.plExMainContainer.Width = this.plFormMainContent.Width;
- }
- if (isShowCtlScrollBarH)
- {
- this.ctlScrollBarH.Visible = true;
- this.plFormMainContent.Height = this.Height - this.TitleBgImageHeight - this.BottomBgImageHeight - offset;
- this.plExMainContainer.Height = this.plFormMainContent.Height + offset - 4;
- }
- else
- {
- this.ctlScrollBarH.Visible = false;
- this.plFormMainContent.Height = this.Height - this.TitleBgImageHeight - this.BottomBgImageHeight;
- this.plExMainContainer.Height = this.plFormMainContent.Height;
- }
- }
- else
- {
- this.plFormMainContent.Width = this.Width;
- this.plFormMainContent.Height = this.Height - this.TitleBgImageHeight - this.BottomBgImageHeight;
- this.plExMainContainer.Width = this.plFormMainContent.Width;
- this.plExMainContainer.Height = this.plFormMainContent.Height;
- }
- }
-
-
-
- public void InitializeScrollBar()
- {
- this.plExMainContainer.AutoScrollPosition = new Point(scrollX, scrollY);
- this.ctlScrollBarV.Minimum = 0;
- this.ctlScrollBarV.Maximum = this.plExMainContainer.DisplayRectangle.Height;
- this.ctlScrollBarV.LargeChange = ctlScrollBarV.Maximum / ctlScrollBarV.Height + this.plExMainContainer.Height - 20;
- this.ctlScrollBarV.Value = Math.Abs(this.plExMainContainer.AutoScrollPosition.Y);
- this.ctlScrollBarH.Minimum = 0;
- this.ctlScrollBarH.Maximum = this.plExMainContainer.DisplayRectangle.Width;
- this.ctlScrollBarH.LargeChange = ctlScrollBarH.Maximum / ctlScrollBarH.Width + this.plExMainContainer.Width - 20;
- this.ctlScrollBarH.Value = Math.Abs(this.plExMainContainer.AutoScrollPosition.X);
- }
-
-
-
- void SetScrollBarAttr()
- {
- if (IsCustomScrollBar)
- {
- this.ctlScrollBarV.Location = new Point(this.plFormMainContent.Width, this.plFormMainContent.Location.Y);
- this.ctlScrollBarH.Location = new Point(0, this.plFormMainContent.Location.Y + this.plFormMainContent.Height);
- this.ctlScrollBarV.Size = new Size(this.ctlScrollBarV.Width, this.plFormMainContent.Height);
- this.ctlScrollBarH.Size = new Size(this.plFormMainContent.Width, this.ctlScrollBarH.Height);
- scrollX = this.ctlScrollBarH.Value;
- scrollY = this.ctlScrollBarV.Value;
- }
- }
- bool isCustomScrollBar = false;
-
-
-
- [Browsable(false), Category("自定义窗体属性"), Description("设置是否使用自定义滚动条")]
- public bool IsCustomScrollBar
- {
- get { return isCustomScrollBar; }
- set { isCustomScrollBar = value; }
- }
- private bool isSetplExMainContainerFocus = true;
- private void plExMainContainer_MouseEnter(object sender, EventArgs e)
- {
- if (isSetplExMainContainerFocus)
- this.plExMainContainer.Focus();
- isSetplExMainContainerFocus = false;
- }
-
- }
- }
|