123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- 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 BaseContentsFormRelease : BaseForm360
- {
- /// <summary>
- /// 设置是否使用自定义滚动条
- /// </summary>
- /// <param name="isCustomScrollBar">设置是否使用自定义滚动条</param>
- public BaseContentsFormRelease()
- {
- InitializeComponent();
- this.btnAppFormMenu.MouseClick += new MouseEventHandler(btnAppFormMenu_MouseClick);
- // 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);
- // IsCustomScrollBar = false;
- }
- /// <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;
- }
- SetplExMainContainerSize(PanlOffset);
- SetScrollBarAttr();
- InitializeScrollBar();
- }
- /// <summary>
- /// 窗体大小变化时
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void BaseContentsFormRelease_Resize(object sender, EventArgs e)
- {
-
- SetplExMainContainerSize(PanlOffset);
- SetScrollBarAttr();
- InitializeScrollBar();
- }
- /// <summary>
- /// 父panl大小变化时
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void plFormMainContent_Resize(object sender, EventArgs e)
- {
-
- SetplExMainContainerSize(PanlOffset);
- SetScrollBarAttr();
- InitializeScrollBar();
-
- }
- /// <summary>
- /// 子panl大小变化时
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void plExMainContainer_Resize(object sender, EventArgs e)
- {
- if (!this.TopLevel)
- {
- 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);
- }
- /// <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)
- {
- try
- {
- //父panl大小和位置
- this.plFormMainContent.Location = new Point(0, this.TitleBgImageHeight);
- //子panl大小和位置
- 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;
- }
- }
- catch { }
- }
- /// <summary>
- /// 初始化滚动条
- /// </summary>
- public void InitializeScrollBar()
- {
- try
- {
- 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);
- }
- catch { }
-
-
- }
-
- /// <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 = value; }
- }
- private void btnAppFormMenu_MouseClick(object sender, MouseEventArgs e)
- {
- Button btn = sender as Button;
- Point point = new Point();
- point.Y = btn.Height;
- if (e.Button == MouseButtons.Left)
- {
- this.cmsSystemMeunList.Show(btn, point);
- }
- }
- private void tsmAbout_Click(object sender, EventArgs e)
- {
- frmSystemAbout frmAbout = new frmSystemAbout();
- frmAbout.ShowDialog(this);
- }
- }
- }
|