社区
C#
帖子详情
如何设置一个control的ClientRectangle?
sarmoo
2003-04-02 09:42:09
如何设置一个control的ClientRectangle?
谢谢!
...全文
117
11
打赏
收藏
如何设置一个control的ClientRectangle?
如何设置一个control的ClientRectangle? 谢谢!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
11 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
sarmoo
2003-08-22
打赏
举报
回复
To snof:
不是这个意思,不能改变整个Control的位置大小,
例如我想在Control内加一个Bevel,Bevel以内的区域才算是ClientRectangle,
该如何实现?
sarmoo
2003-08-22
打赏
举报
回复
我的目的是当用户读取其ClientRectangle的大小时,得到的是已经除去了Bevel的区域,
或者若我的控件是一个类似于Panel的容器,其内部若放置其他控件无法覆盖到Bevel上,
其实也就是NC的概念。
liduke
2003-08-22
打赏
举报
回复
ClientRectangle是只读的。
在Graphics中有剪切区域这个概念,可以参考一下
雪狼1234567
2003-08-21
打赏
举报
回复
this.Controls[i].Size = new Size(200,200);
this.Location = new Point(100,100);
gewanjun
2003-06-27
打赏
举报
回复
把BorderStyle 设成none
Explorerwen
2003-06-27
打赏
举报
回复
notice
sarmoo
2003-06-27
打赏
举报
回复
The bounds of the control includes the nonclient elements such as scroll bars, borders, title bars, and menus.
我需要改变clientRectangle 的大小,相应的NC的也就跟着变了,但不是整个的大小。
所以通过Bound进行设置达不到我的目的。
Knight94
2003-06-09
打赏
举报
回复
通过Bound进行设置。
sarmoo
2003-04-04
打赏
举报
回复
怎么没人理我呀?
郁闷ing……
sarmoo
2003-04-02
打赏
举报
回复
那原点怎么变?
贝贝壳壳
2003-04-02
打赏
举报
回复
ClientRectangle是只读的。
通过设置大小 ,应该就改变了它吧?
c#t自定义Button
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using System.Diagnostics; using System.Drawing.Drawing2D; namespace KRT.Component.Common { /// /// 停靠面板控件 /// public class DockPanel : Panel { /// /// 关闭按钮 /// DockPanelCloseButton closeButton = new DockPanelCloseButton(); /// /// 浮动窗口 /// Form flowForm = new Form(); /// /// 分割栏 /// Splitter splitter = new Splitter(); /// /// 标题栏 /// Label titleBar = new Label(); /// /// 标题栏背景色 /// public Color TitleBackColor //using System.Drawing; { get { return titleBar.BackColor; } set { titleBar.BackColor = value; closeButton.BackColor = value; } } /// /// 标题栏前景色 /// public Color TitleForeColor { get { return titleBar.ForeColor; } set { titleBar.ForeColor = value; } } /// /// 标题栏文本 /// [Localizable(true)] public string TitleText { get { return titleBar.Text; } set { titleBar.Text = value; } } /// /// 标题栏可见 /// public bool TitleVisible { get { return titleBar.Visible; } set { titleBar.Visible = value; closeButton.Visible = value; } } /// /// 浮动窗口最大尺寸 /// Size flowFormMaxSize = new Size(640, 480); public Size FlowFormMaxSize { get { return flowFormMaxSize; } set { flowFormMaxSize = value; if (this.VisibleAll) { flowForm.Size = flowFormMaxSize; } } } /// /// 整个控件的隐藏、显示,包括浮动窗口状态下 /// bool visibleAll = true; public bool VisibleAll { get { return visibleAll; } set { visibleAll = value; if (flowForm.
Control
s.Count > 0) { flowForm.Visible = visibleAll; } else { this.Visible = visibleAll; } } } /// /// 控件初始化 /// public DockPanel() { //InitializeComponent(); flowForm.ShowInTaskbar = false; // 关闭按钮 closeButton.Location = new System.Drawing.Point(0, 0); closeButton.Name = "Close"; closeButton.Size = new System.Drawing.Size(16, 16); closeButton.TabIndex = 0; closeButton.BackColor = SystemColors.
Control
Dark; closeButton.Click += new EventHandler(closeButton_Click); // 浮动窗口 flowForm.FormBorderStyle = FormBorderStyle.SizableToolWindow; //VS2008自带的窗体设计器进行
设置
窗体的边框。 flowForm.ShowInTaskbar = false; //任务栏 flowForm.MaximizeBox = false; //最大化按钮 flowForm.Move += new EventHandler(flowForm_Move); //EventHandler是asp.net内置的委托,事件是特殊的委托。 flowForm.MouseCaptureChanged += new EventHandler(flowForm_MouseCaptureChanged); // flowForm.FormClosing += new FormClosingEventHandler(flowForm_FormClosing); // 标题栏 titleBar.AutoSize = false; //自动调整大小 titleBar.Dock = DockStyle.Top;//控件顶端;DockStyle是个枚举,有none, top, bottom... titleBar.Height = 18; titleBar.Padding = new Padding(3); titleBar.MouseDown += new MouseEventHandler(titleBar_MouseDown); titleBar.MouseMove += new MouseEventHandler(titleBar_MouseMove); titleBar.MouseUp += new MouseEventHandler(titleBar_MouseUp); //this.Padding = new Padding(1); this.
Control
s.Add(closeButton); this.
Control
s.Add(titleBar); this.ParentChanged += new EventHandler(DockPanel_ParentChanged); this.VisibleChanged += new EventHandler(DockPanel_VisibleChanged); this.MouseDown += new MouseEventHandler(titleBar_MouseDown); this.MouseMove += new MouseEventHandler(titleBar_MouseMove); this.MouseUp += new MouseEventHandler(titleBar_MouseUp); this.
Control
Added += new
Control
EventHandler(DockPanel_
Control
Added); } /// /// 如果是用户单击浮动窗口的关闭按钮,隐藏浮动窗口 /// /// /// void flowForm_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { e.Cancel = true; flowForm.Visible = false; visibleAll = false; closeButton_Click(sender, e); } } /// /// 添加子控件时调整顺序 /// /// /// void DockPanel_
Control
Added(object sender,
Control
EventArgs e) { if (e.
Control
!= titleBar && e.
Control
!= closeButton) { e.
Control
.BringToFront(); } } /// /// 同时修改Splitter的可视效果 /// /// /// void DockPanel_VisibleChanged(object sender, EventArgs e) { splitter.Visible = Visible; if (this.Parent != null && Visible) { if (!this.DesignMode) { if (this.Parent.
Control
s.IndexOf(splitter) < 0) { //splitter.Dock = this.Dock; //this.Parent.
Control
s.AddRange(new
Control
[] { splitter, this }); this.Parent.
Control
s.Add(splitter); int index = this.Parent.
Control
s.IndexOf(this); this.Parent.
Control
s.SetChildIndex(splitter, index); //this.Parent.
Control
s.SetChildIndex(this, index + 1); //foreach (
Control
item in this.Parent.
Control
s) //{ // Debug.WriteLine( // this.Parent.
Control
s.GetChildIndex(item).ToString() + " : " + // item.ToString()); //} } } } } /// /// 初始化Splitter /// /// /// void DockPanel_ParentChanged(object sender, EventArgs e) { //if (this.Parent != null) //{ // if (!this.DesignMode) // { // //Parent.
Control
s.Add(splitter); // splitter.Dock = this.Dock; // this.Parent.
Control
s.AddRange(new
Control
[] { splitter, this }); // } //} } /// /// 关闭事件 /// public event EventHandler CloseButtonClick; /// /// 单击关闭按钮,触发关闭事件 /// /// /// void closeButton_Click(object sender, EventArgs e) { VisibleAll = false; if (null != CloseButtonClick) { CloseButtonClick(sender, e); } } /// /// 浮动窗口开始拖动时触发 /// /// /// void flowForm_MouseCaptureChanged(object sender, EventArgs e) { if (!flowFormCapture) { flowFormCapture = true; } else { flowFormCapture = false; flowFormDock = true; } } bool flowFormDock = false; // 浮动窗口可以被停靠 bool flowFormCapture = false; // 浮动窗口开始拖动 /// /// 浮动窗口移动过程 /// /// /// void flowForm_Move(object sender, EventArgs e) { if (flowFormDock) { flowFormDock = false; switch (this.Dock) { case DockStyle.Left: if (flowForm.Location.X < Parent.Location.X) { ShowDockPanel(); } break; case DockStyle.Top: if (flowForm.Location.Y Parent.Location.X + Parent.Width) { ShowDockPanel(); } break; case DockStyle.Bottom: if (flowForm.Location.Y + flowForm.Height > Parent.Location.Y + Parent.Height) { ShowDockPanel(); } break; } } } /// /// 控件尺寸改变 /// /// protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); closeButton.Location = new Point(
Client
Rectangle
.Right - closeButton.Width - 1, 1); closeButton.Refresh(); } Point oldMouseLocation; // 鼠标位置
Rectangle
rect; // 面板区域 bool mouseDown = false; // 鼠标按下 /// /// 鼠标按下事件 /// /// /// void titleBar_MouseDown(object sender, MouseEventArgs e) { if (this.Dock != DockStyle.None && this.Dock != DockStyle.Fill) { oldMouseLocation = e.Location; mouseDown = true; rect = this.
Rectangle
ToScreen(
Client
Rectangle
);
Control
Paint.DrawReversibleFrame(rect, Color.Black, FrameStyle.Thick); } } /// /// 鼠标移动事件 /// /// /// void titleBar_MouseMove(object sender, MouseEventArgs e) { if (mouseDown) {
Control
Paint.DrawReversibleFrame(rect, Color.Black, FrameStyle.Thick); rect.Offset(e.X - oldMouseLocation.X, e.Y - oldMouseLocation.Y); oldMouseLocation = e.Location;
Control
Paint.DrawReversibleFrame(rect, Color.Black, FrameStyle.Thick); } } /// /// 鼠标弹起事件 /// /// /// void titleBar_MouseUp(object sender, MouseEventArgs e) { if (mouseDown) { mouseDown = false;
Control
Paint.DrawReversibleFrame(rect, Color.Black, FrameStyle.Thick);
Rectangle
rc = this.
Rectangle
ToScreen(
Client
Rectangle
); Point pt = this.PointToScreen(e.Location); if (!rc.Contains(pt)) { ShowFlowForm(); } } } //protected override void OnPaint(PaintEventArgs e) //{ // base.OnPaint(e); // Pen borderPen = new Pen(borderColor); //
Rectangle
rc = new
Rectangle
( // e.Clip
Rectangle
.Left, e.Clip
Rectangle
.Top, // e.Clip
Rectangle
.Right - 1, e.Clip
Rectangle
.Bottom - 1); // e.Graphics.Draw
Rectangle
(borderPen, rc); //} /// /// 显示浮动窗口 /// void ShowFlowForm() { flowForm.Show(Parent); flowForm.Location = new Point(rect.Left, rect.Top); Size newSize = new Size(rect.Width, rect.Height); if (newSize.Width > FlowFormMaxSize.Width) { newSize.Width = FlowFormMaxSize.Width; } newSize.Height = newSize.Height + (this.TitleVisible ? SystemInformation.CaptionHeight - this.titleBar.Height : SystemInformation.CaptionHeight); if (newSize.Height > FlowFormMaxSize.Height) { newSize.Height = FlowFormMaxSize.Height; } flowForm.Size = newSize; flowForm.Text = TitleText; while (this.
Control
s.Count > 2) { for (int i = 0; i < this.
Control
s.Count; i++) { if (this.
Control
s[i] != closeButton && this.
Control
s[i] != titleBar) { flowForm.
Control
s.Add(this.
Control
s[i]); break; } } } this.Visible = false; } /// /// 显示停靠面板 /// void ShowDockPanel() { this.Visible = true; while (flowForm.
Control
s.Count > 0) { this.
Control
s.Add(flowForm.
Control
s[0]); } flowForm.Hide(); } } }
画线橡皮筋效果实现用C#源码实现
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace DoubleBufferDraw { public partial class DrawLine : Form { class LineObj { private Point m_start; private Point m_end; public LineObj(Point start, Point end) { this.m_start = start; this.m_end = end; } public void Draw(Graphics g, Pen pen) { g.DrawLine(pen, m_start, m_end); } } private Point m_startPoint = Point.Empty; List lineList = new List(); public DrawLine() { InitializeComponent(); } private void drawLine(Graphics graphics, Point startPoint, Point endPoint) { BufferedGraphicsContext context = BufferedGraphicsManager.Current; BufferedGraphics bg = context.Allocate(graphics, this.
Client
Rectangle
); bg.Graphics.Clear(this.BackColor); foreach (LineObj line in this.lineList) { line.Draw(bg.Graphics, SystemPens.
Control
Text); } bg.Graphics.DrawLine(SystemPens.
Control
Text, startPoint, endPoint); bg.Render(); bg.Dispose(); bg = null; } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); foreach (LineObj line in this.lineList) { line.Draw(e.Graphics, SystemPens.
Control
Text); } } protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); this.m_startPoint = new Point(e.X, e.Y); } protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.Button == MouseButtons.Left) { this.drawLine(this.CreateGraphics(), this.m_startPoint, new Point(e.X, e.Y)); } } protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); LineObj line = new LineObj(this.m_startPoint, e.Location); this.lineList.Add(line); } } }
如何
设置
Winform控件的
Client
Rectangle
最近学习制作WinForm控件,自己动手写控件的时候才发现System.Windows.Forms.
Control
竟然没有提供默认的border绘制。记得以前用API做控件的时候,只需要
设置
空间窗口的WS_BORDER风格就可以。遍寻无方,只有自己绘制了,这里有出现
一个
,如果border在客户区,那么在OnPaint方法里不得不每次都要考虑Bo...
dotnetbar的Ribbon
Control
控件使用
使用ribbon
Control
要注意的几个问题: 1、首先将form的text
设置
为空 2、然后将form的
control
box
设置
为false 3、然后将form的formborderstyle
设置
为Sizable 4、在ribbon
control
的标题栏写窗口标题,注意不是text而是Ribbon
Control
1.TitleText = “管理信息系统” 5、将FORM的STAR...
user
Control
保存图片
SaveImage(string filename){ using (Bitmap bmp = new Bitmap(user
Control
1.Width, user
Control
11Height)) { user
Control
1.DrawToBitmap(bmp, user
Control
1.
Client
Rectangle
);
C#
110,534
社区成员
642,575
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章