suspendlayoutC#中ResumeLayout(false)错误(急)

suspendlayout  时间:2021-06-05  阅读:()

窗体中怎么让toolstrip漂浮(停靠已经做出来了)(C#)

DotNet2.0开发框架中提供的ToolStrip和ToolStripPanel控件可以方便开发具有可停靠工具栏功能的Windows应用程序, ToolStrip对象可以在各个ToolStripPanel间完成拖拽停靠,但是如果想实现类似VS IDE 或Office中可以浮动的工具栏必须借助于DevExpress等一些第三方的控件或编写一定的代码。

这里介绍一种比较简单的方法,只需继承ToolStrip类即可实现上述的效果。

  放置到ToolStripPanel上的,当工具栏浮动的时候,事实上是改变了其所在的容器对象,从其所在的ToolStripPanel移动到一个漂浮的容器上,因此要实现工具栏的浮动必须解决以下两个问题:     必须有一个浮动的容器来承载ToolStrip对象。

    须知道ToolStrip对象何时改变其所在的容器,即在浮动的容器和主窗口上ToolStripPanel之间停靠。

  对于第一个问题,我们的解决方案是动态的创建一个Form类作为浮动的容器,命名为ToolStripFloatWindow,该Form对象具有以下的属性:     FormBorderStyle = FixedToolWindow 边框样式     ShowInTaskbar = false 不在任务栏显示     ShowIcon = false 不显示窗口图标     TopMost = true 在所有窗口之上   为了解决第二个问题,我们查阅MSDN获知,当用鼠标拖拽ToolStrip对象释放鼠标时会触发其EndDrag事件。

我们在这个事件的处理方法中判断当ToolStrip对象的位置被移动到所在的ToolStripPanel之外的时候,创建ToolStripFloatWindow对象,并将ToolStrip对象移动到ToolStripFloatWindow上;要使ToolStrip对象恢复到原来的窗体上只要判断ToolStripFloatWindow对象的位置是否移动到了ToolStripPanel上, 当条件满足时将ToolStrip对象移动回ToolStripPanel中并销毁ToolStripFloatWindow对象。

  此外,还要解决当ToolStrip对象放置到ToolStripFloatWindow对象上时, ToolStripFloatWindow对象必须与ToolStrip对象的尺寸一致。

还有ToolStripFloatWindow对象被点击了关闭按钮时不能将自己关闭。

我们可以做两个类来实现上述的思路。

ToolStripFloatWindow类继承自Form类。

MyToolStrip 继承自ToolStrip类。

增加了相应的属性和方法。

MyToolStrip类的源代码如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace FloatingToolStrip ...{ public partial class MyToolStrip : ToolStrip ...{ public MyToolStrip() ...{ InitializeComponent(); this.EndDrag += new EventHandler(MyToolStrip_EndDrag); this.SizeChanged += new EventHandler(MyToolStrip_SizeChanged); } protected override void OnPaint(PaintEventArgs pe) ...{ // TODO: 在此处添加自定义绘制代码 // 调用基类 OnPaint base.OnPaint(pe); }   漂浮状态#region 漂浮状态 private ToolStripFloatWindow floatWindow; public ToolStripFloatWindow FloatWindow ...{ get ...{ return this.floatWindow; } set ...{ floatWindow = value; if (FloatWindow != null) ...{ floatWindow.LocationChanged += new EventHandler(floatWindow_LocationChanged); floatWindow.FormClosing += new FormClosingEventHandler(floatWindow_FormClosing); } } } public bool isFloating ...{ get ...{ return (floatWindow != null); } } private ToolStripPanel tsPanel; public ToolStripPanel ToolStripPanel ...{ get ...{ return this.tsPanel; } set ...{ tsPanel = value; } } #endregion   漂浮实现#region 漂浮实现 private void floatWindow_LocationChanged(object sender, EventArgs e) ...{ //当floatwindws的位置移动到 toolstrippanel中时,将this放置到 toolstripPanel上 if (this.floatWindow == null) ...{ return; } Point currentPt = new Point(floatWindow.Location.X, floatWindow.Location.Y); Point minpt = this.tsPanel.PointToScreen(tsPanel.Location); Point maxpt; if(this.tsPanel.Height <= 20)...{ maxpt = new Point(minpt.X + this.tsPanel.Width, minpt.Y + 20); }else...{ maxpt = new Point(minpt.X + this.tsPanel.Width, minpt.Y + this.tsPanel.Height); } if ((currentPt.X > minpt.X) && (currentPt.X < maxpt.X) && (currentPt.Y > minpt.Y) && (currentPt.Y < maxpt.Y)) ...{ this.floatWindow.Controls.Remove(this); this.tsPanel.SuspendLayout(); this.tsPanel.Controls.Add(this); this.Location = this.tsPanel.PointToClient(currentPt); this.tsPanel.ResumeLayout(); this.floatWindow.Dispose(); this.floatWindow = null; } } private void MyToolStrip_EndDrag(object sender, EventArgs e) ...{ //判断移出时 if (this.tsPanel == null) ...{ MessageBox.Show("请先设置ToolStripPanel属性"); return; } Point endPoint = Cursor.Position; int openX, openY; openX = endPoint.X; openY = endPoint.Y; Point clientPt = this.tsPanel.Parent.PointToClient(endPoint); if (clientPt.Y > tsPanel.Height) ...{ ToolStripFloatWindow fw = new ToolStripFloatWindow(); this.tsPanel.Controls.Remove(this); fw.Controls.Add(this); this.Left = 0; this.Top = 0; this.FloatWindow = fw; Point newLoc = new Point(openX, openY); fw.Show(); fw.Location = newLoc; fw.SetBounds(newLoc.X, newLoc.Y, this.ClientSize.Width, this.ClientSize.Height); } } private void floatWindow_FormClosing(object sender, FormClosingEventArgs e) ...{ e.Cancel = true; } private void MyToolStrip_SizeChanged(object sender, EventArgs e) ...{ if (this.isFloating) ...{ this.floatWindow.Width = this.ClientSize.Width; } } #endregion } } 结论。

该方法实现较简单, 当不愿意使用功能较强大的第三方控件库时可以采用这种方法,缺点是负责浮动的容器是一个窗口,不大美观。

C#中在panel控件上动态创建100个小的panel控件!所以在加载时闪的厉害!!特求教高手帮

this.SuspendLayout(); // 加载panel this.ResumeLayout(); this.PerformLayout(); wandsg@ 发代码看看

怎样让form窗体标题左对齐

一般情况下,窗口标题栏的文字都是左对齐的,也就是显示在最左边,如果不是,实现方法如下:内置的属性设置代码,可参考下面这个代码片段: 01 private void InitializeComponent() 02 { 03 this.SuspendLayout(); 04 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 05 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 06 this.BackgroundImage = global::WindowsTitleleft.Properties.Resources. 背景 2; 07 this.ClientSize = new System.Drawing.Size(248, 144); 08 this.Name = "Form1"; 09 this.RightToLeft = System.Windows.Forms.leftToright.Yes; 10 this.Text = "标题栏文字左对齐"; 11 this.ResumeLayout(false); 12 }

C#中ResumeLayout(false)错误(急)

System.ArgumentException 在向方法提供的其中一个参数无效时引发的异常。

检查出错的方法ResumeLayout(false)中引入参数(false)的类型数量及顺序与该方法的定义有何不同,更正它。

RAKsmart 2021新年新增韩国服务器及香港美国日本VPS半价

RAKsmart 商家我们肯定不算陌生,目前主要的营销客户群肯定是我们。于是在去年的时候有新增很多很多的机房,比如也有测试过的日本、香港、美国机房,这不今年有新增韩国机房(记得去年是不是也有增加过)。且如果没有记错的话,之前VPS主机也有一次磁盘故障的问题。 这不今天有看到商家新增韩国服务器产品,当然目前我还不清楚商家韩国服务器的线路和速度情况,后面我搞一台测试机进行...

云基Yunbase无视CC攻击(最高500G DDoS防御),美国洛杉矶CN2-GIA高防独立服务器,

云基yunbase怎么样?云基成立于2020年,目前主要提供高防海内外独立服务器,欢迎各类追求稳定和高防优质线路的用户。业务可选:洛杉矶CN2-GIA+高防(默认500G高防)、洛杉矶CN2-GIA(默认带50Gbps防御)、香港CN2-GIA高防(双向CN2GIA专线,突发带宽支持,15G-20G DDoS防御,无视CC)。目前,美国洛杉矶CN2-GIA高防独立服务器,8核16G,最高500G ...

HostNamaste$24 /年,美国独立日VPS优惠/1核1G/30GB/1Gbps不限流量/可选达拉斯和纽约机房/免费Windows系统/

HostNamaste是一家成立于2016年3月的印度IDC商家,目前有美国洛杉矶、达拉斯、杰克逊维尔、法国鲁贝、俄罗斯莫斯科、印度孟买、加拿大魁北克机房。其中洛杉矶是Quadranet也就是我们常说的QN机房(也有CC机房,可发工单让客服改机房);达拉斯是ColoCrossing也就是我们常说的CC机房;杰克逊维尔和法国鲁贝是OVH的高防机房。采用主流的OpenVZ和KVM架构,支持ipv6,免...

suspendlayout为你推荐
腾讯举报中心如何举报QQ号?视频压缩算法1分钟视频的大小在10M左右的格式有哪些?视频技术视频编辑是干什么的,主要是做一些什么工作呢?这个职位好不好?发展前景怎么样?搜索引擎的概念7 什么是搜索引擎?如何在Internet上搜索图片和文字资料的?awvawv转换器哪里下?jstz举手望,草上马跑,打什么数字?腾讯技术腾讯是什么东西?审计平台什么叫数据库审计系统?单元测试规范如何写线程池的单元测试网络电话免费版有没有免费的网络电话?纯免费的
中文域名注册 政务和公益机构域名注册管理中心 花生壳免费域名申请 新网域名管理 hostmonster 2014年感恩节 腾讯云数据库 60g硬盘 网盘申请 丹弗 小米数据库 北京双线机房 刀片服务器的优势 如何安装服务器系统 吉林铁通 跟踪路由命令 便宜空间 路由跟踪 游戏服务器出租 浙江服务器 更多