123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677 |
- 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
- {
- /// <summary>
- /// 所有内容窗体的基窗体
- /// </summary>
- public partial class BaseContentsFormMain : BaseFormRelease, LYFZ.StandardInterface.IFormMain
- {
- UCNavigationTool currentUcNavigationTool = new UCNavigationTool();
- 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.plExMainContainer.MouseMove += plExMainContainer_MouseMove;
- this.plExMainContainer.Click += plExMainContainer_Click;
- 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);
- this.plExMainContainer.BackColor = LYFZ.ComponentLibrary.GetUIResources.FrmContentBackgroundColor;
- this.FormClosing += BaseContentsFormMain_FormClosing;
- this.FormClosed += BaseContentsFormMain_FormClosed;
- //this.ctlScrollBarV.MouseEnter += ctlScrollBarV_MouseEnter;
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
- }
- bool isShowWelcomeForm = true;
- public void ClosThisForm()
- {
- isShowWelcomeForm = false;
- this.Close();
- }
- /// <summary>
- /// 等待释放的控件集合
- /// </summary>
- static List<Form> WaitDisposeAllControls = new List<Form>();
- void BaseContentsFormMain_FormClosed(object sender, FormClosedEventArgs e)
- {
- /* try
- {
- // this.SuspendLayout();
- // ControlsDispose(this.Controls);
- }
- catch { }*/
- //
- }
- public static void ControlsDispose(System.Windows.Forms.Control.ControlCollection controls)
- {
- int count = controls.Count;
- if (count > 0)
- {
- List<System.Windows.Forms.Control> delList = new List<Control>();
- for (int i = 0; i < count; i++)
- {
- System.Windows.Forms.Control control = controls[i];
- /* if (control.Controls.Count > 0)
- {
- ControlsDispose(control.Controls);
- }*/
- if (control.GetType() == typeof(System.Windows.Forms.Panel)
- || control.GetType() == typeof(System.Windows.Forms.Label)
- || control.GetType() == typeof(LYFZ.ComponentLibrary.PanelEx)
- || control.GetType() == typeof(LYFZ.ComponentLibrary.LabelEx)
- || control.GetType() == typeof(LYFZ.ComponentLibrary.CheckBoxEx)
- || control.GetType() == typeof(System.Windows.Forms.CheckBox))
- {
- if (control != null && !control.IsDisposed)
- {
- delList.Add(control);
- }
- }
- }
- count = delList.Count;
- for (int i = 0; i < count; i++)
- {
- delList[i].Dispose();
- }
- delList.Clear();
- delList = null;
- }
- }
-
- void ctlScrollBarV_MouseEnter(object sender, EventArgs e)
- {
- RefreshCtlScrollBarValue();
- }
- /// <summary>
- /// 刷新滚动条值
- /// </summary>
- void RefreshCtlScrollBarValue() {
- // this.ctlScrollBarV.Value = Math.Abs(this.plExMainContainer.AutoScrollPosition.Y);
- // this.ctlScrollBarH.Value = Math.Abs(this.plExMainContainer.AutoScrollPosition.X);
- // scrollY = ctlScrollBarV.Value;
- // scrollX = ctlScrollBarH.Value;
- }
- void plExMainContainer_Click(object sender, EventArgs e)
- {
- this.plExMainContainer.Focus();
- }
-
- void plExMainContainer_MouseMove(object sender, MouseEventArgs e)
- {
- LoginAgain();
- RefreshCtlScrollBarValue();
- }
- bool isClosedLoadWelcomeForm = true;
- public bool IsClosedLoadWelcomeForm
- {
- get { return isClosedLoadWelcomeForm; }
- set { isClosedLoadWelcomeForm = value; }
- }
- void BaseContentsFormMain_FormClosing(object sender, FormClosingEventArgs e)
- { //typeof(LYFZ.StandardInterface.IToolMenuClick).IsAssignableFrom(this.ParentForm.GetType())
- //用于判断父窗体是否实现了指定的LYFZ.StandardInterface.IToolMenuClick接口
- try
- {
- if (this.GetType().FullName != "LYFZ.Software.PhotoStudio.frmWelcomeForm" && isShowWelcomeForm)
- {
- if (this.ParentForm != null)
- {
- if (typeof(LYFZ.StandardInterface.IToolMenuClick).IsAssignableFrom(this.ParentForm.GetType()))
- {
- LYFZ.StandardInterface.IToolMenuClick iParentForm = (LYFZ.StandardInterface.IToolMenuClick)this.ParentForm;
- iParentForm.ShowForm("LYFZ.Software.PhotoStudio.frmWelcomeForm", "SPS", "ShowEmbedded");
- }
- }
- }
- if (this.IsLoginValidation)
- {
- LYFZ.BLL.BLL_ErpUser.UpdateDynamicTimeAccount();
- }
- }
- catch { }
- finally {
- isShowWelcomeForm = true;
- }
- }
- void InitializeUcNavigationTool()
- {
- if (isShowUcNavigationTool)
- {
- if (this.plFormMainContent.Controls.Find("currentUcNavigationTool01", false).Length <= 0)
- {
- currentUcNavigationTool.Width = this.plFormMainContent.Width;
- currentUcNavigationTool.Visible = this.isShowUcNavigationTool;
- currentUcNavigationTool.Location = new Point(0, 0);
- currentUcNavigationTool.Name = "currentUcNavigationTool01";
- this.plFormMainContent.Controls.Add(currentUcNavigationTool);
- }
- }
- else {
- try
- {
- this.plFormMainContent.Controls.Remove(currentUcNavigationTool);
- }
- catch { }
- }
-
- }
- void SetUcNavigationTool()
- {
-
-
- if (this.isShowUcNavigationTool)
- {
- currentUcNavigationTool.Width = this.plFormMainContent.Width;
- this.plExMainContainer.Location = new Point(0, 40);
- }
- else
- {
- this.plExMainContainer.Location = new Point(0, 0);
-
- }
-
- }
- /// <summary>
- /// 设置导航
- /// </summary>
- public UCNavigationTool UcNavigationTool
- {
- get { return this.currentUcNavigationTool; }
- }
- bool isShowUcNavigationTool = false;
- /// <summary>
- /// 是否显示导航栏
- /// </summary>
- public bool IsShowUcNavigationTool
- {
- get { return isShowUcNavigationTool; }
- set { isShowUcNavigationTool = value;
- InitializeUcNavigationTool();
- plFormMainContent_Resize(null,null);
-
- Invalidate(false); }
- }
- /// <summary>
- /// 重载新窗体
- /// </summary>
- /// <param name="objNewForm"></param>
- 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();
- }
- /// <summary>
- /// 设置发生错误时显示信息
- /// </summary>
- /// <param name="msg"></param>
- 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);
-
- }
- /// <summary>
- /// 公共plExMainContainer对象
- /// </summary>
- // public LYFZ.ComponentLibrary.PanelEx PublicContainer = null;
- /// <summary>
- /// 系统菜单事件接口
- /// </summary>
- public LYFZ.StandardInterface.IMenuClick iMenuClick = null;
- /// <summary>
- /// 系统菜单事件设置
- /// </summary>
- /// <param name="menuItem"></param>
- protected override void SetMenuItem_Click(ToolStripMenuItem menuItem)
- {
- if (iMenuClick != null)
- iMenuClick.SetIMenuItem_Click(menuItem);
- }
- /// <summary>
- /// 覆盖窗体标题栏上最小化、最大化和关闭按钮的事件
- /// </summary>
- 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);
- }
- }
- /// <summary>
- /// 最小化父窗体
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void ParentFormBtnAppFormMinimize_Click(object sender, EventArgs e)
- {
- this.ParentForm.WindowState = FormWindowState.Minimized;
- }
- /// <summary>
- /// 最大化父窗体
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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;
- }
-
- }
- /// <summary>
- /// 关闭父窗体
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected virtual void ParentFormBtnAppFormExit_Click(object sender, EventArgs e)
- {
- this.ParentForm.Close();
- }
- #region 滚动轮滚动时滚动窗体
- /// <summary>
- /// 获取滚动轮滚动的值
- /// </summary>
- /// <param name="e"></param>
- /// <returns></returns>
- int getMouseWheelDelta(MouseEventArgs e)
- {
- // this.Text = this.ctlScrollBarV.Maximum + "/" + this.ctlScrollBarV.LargeChange.ToString() + "*" + ctlScrollBarV.Value;
- //e.Delta 在正负 120 之间
- //滚动条要滚动的值在 0 到 this.ctlScrollBarV.Maximum - this.ctlScrollBarV.LargeChange 之间
- 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
- /// <summary>
- /// 记录滚动条显示时需要的宽度
- /// </summary>
- int PanlOffset = 0;
- /// <summary>
- /// 首次显示时
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void BaseContentsFormRelease_Shown(object sender, EventArgs e)
- {
- if (IsCustomScrollBar)
- {
- PanlOffset = 20;
- }
- InitializeUcNavigationTool();
- ResetControls();
- SetUcNavigationTool();
-
- }
- /// <summary>
- /// 窗体大小变化时
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void BaseContentsFormRelease_Resize(object sender, EventArgs e)
- {
- isSetplExMainContainerFocus = true;
- ResetControls();
- }
- /// <summary>
- /// 父panl大小变化时
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void plFormMainContent_Resize(object sender, EventArgs e)
- {
-
- isSetplExMainContainerFocus = true;
- ResetControls();
- SetUcNavigationTool();
- }
- /// <summary>
- /// 子panl大小变化时
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void plExMainContainer_Resize(object sender, EventArgs e)
- {
- if (!this.TopLevel)
- {
- ResetControls();
- }
- isSetplExMainContainerFocus = true;
-
- }
- /// <summary>
- /// 重设相关控件
- /// </summary>
- 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);
- if (this.IsLoginValidation)
- {
- LYFZ.BLL.BLL_ErpUser.UpdateDynamicTimeAccount();
- }
- }
- void ctlScrollBarH_Scroll(object sender, EventArgs e)
- {
- //水平滚动
- // scrollX = ctlScrollBarH.Value;
- // this.plExMainContainer.AutoScrollPosition = new Point(ctlScrollBarH.Value, scrollY);
- if (this.IsLoginValidation)
- {
- LYFZ.BLL.BLL_ErpUser.UpdateDynamicTimeAccount();
- }
- }
- /// <summary>
- /// 重绘控件
- /// </summary>
- /// <param name="e"></param>
- protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
- {
- base.OnPaint(e);
- SetplExMainContainerSize(PanlOffset);
-
- }
- /// <summary>
- /// 设置内容容器的大小和位置
- /// </summary>
- public void SetplExMainContainerSize(int offset = 0)
- {
- //父panl大小和位置
- this.plFormMainContent.Location = new Point(0, this.TitleBgImageHeight);
- //子panl大小和位置
- isShowCtlScrollBarH = this.plExMainContainer.HorizontalScroll.Visible;
- isShowCtlScrollBarV = this.plExMainContainer.VerticalScroll.Visible;
- //导航工具栏高度
- int UcNavigationToolHeight = 0;
- if (this.isShowUcNavigationTool) {
- UcNavigationToolHeight = this.currentUcNavigationTool.Height;
- }
- 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 - UcNavigationToolHeight;
- }
- else
- {
- // this.ctlScrollBarH.Visible = false;
- this.plFormMainContent.Height = this.Height - this.TitleBgImageHeight - this.BottomBgImageHeight;
- this.plExMainContainer.Height = this.plFormMainContent.Height - UcNavigationToolHeight;
- }
- }
- 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 - UcNavigationToolHeight;
- }
-
- }
- /// <summary>
- /// 初始化滚动条
- /// </summary>
- 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);*/
- }
- /// <summary>
- /// 设置滚动条属性
- /// </summary>
- 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;
- /// <summary>
- /// 设置是否使用自定义滚动条
- /// </summary>
- [Browsable(false), Category("自定义窗体属性"), Description("设置是否使用自定义滚动条")]
- public bool IsCustomScrollBar
- {
- get { return isCustomScrollBar; }
- set { isCustomScrollBar = false; }
- }
- private bool isSetplExMainContainerFocus = true;
- bool isMouseEnterSetFocus = false;
- /// <summary>
- /// 是否鼠标进入窗体内容框时自动获取焦点
- /// </summary>
- [Browsable(false), Category("自定义窗体属性"), Description("是否鼠标进入窗体内容框时自动获取焦点")]
- public bool IsMouseEnterSetFocus
- {
- get { return isMouseEnterSetFocus; }
- set { isMouseEnterSetFocus = value; }
- }
- private void plExMainContainer_MouseEnter(object sender, EventArgs e)
- {
- if (IsMouseEnterSetFocus)
- {
- if (isSetplExMainContainerFocus)
- this.plExMainContainer.Focus();
- isSetplExMainContainerFocus = false;
- }
- }
- protected override void CreateHandle()
- {
- if (!IsHandleCreated)
- {
- try
- {
- base.CreateHandle();
- }
- catch { }
- finally
- {
- if (!IsHandleCreated)
- {
- base.RecreateHandle();
- }
- }
- }
- }
- }
- }
|