请问怎样使用Dock,Anchor属性?

lsqlxq 2003-10-21 11:55:48
搜索过以前的帖子,很多帅哥都表示要想设计能自适应不同分辨率窗口的WinForm要Dock,Anchor两个属性配合使用,可我发现一旦设置了Dock属性后,Anchor属性也相应的改了,比如设置Dock为Left后Anchor自动变为Top、Left。这样不能叫配合吧,请问这怎么理解?
如您对这两个属性有相当的理解,请帮我实现一个这样的最直接的效果:一个小窗体(不是最大化的),上面放100个文本框,共10行,每行10个,这100个文本框充满了整个窗体而均匀分布在窗体上。设置它们的属性后,运行程序,用鼠标拉窗体改变窗体大小,这100个文本框中每个都要相应的改变位置而改变大小,按比例扩大,保证还是“充满整个窗体而均匀分布在窗体上”。
谢谢!
...全文
300 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ETstudio 2003-10-21
  • 打赏
  • 举报
回复
我是用另一种方法做的,用上面的属性是不可以实现的,因为Dock是单方向的,只能是一列或一行,不可以多行多列
ETstudio 2003-10-21
  • 打赏
  • 举报
回复
给我你的email,我做一个给你!
lsqlxq 2003-10-21
  • 打赏
  • 举报
回复
请问 zzzsssccc(籍秋风) 您写的这两段代码是干啥的?
三杯倒 2003-10-21
  • 打赏
  • 举报
回复
// Add a button to a form and set some of its common properties.
private void AddMyButton()
{
// Create a button and add it to the form.
Button button1 = new Button();

// Anchor the button to the bottom right corner of the form
button1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);

// Assign a background image.
button1.BackgroundImage = imageList1.Images[0];

// Make the button the same size as the image.
button1.Size = button1.BackgroundImage.Size;

// Set the button's TabIndex and TabStop properties.
button1.TabIndex = 1;
button1.TabStop = true;

// Add a delegate to handle the Click event.
button1.Click += new System.EventHandler(this.button1_Click);

// Add the button to the form.
this.Controls.Add(button1);
}
三杯倒 2003-10-21
  • 打赏
  • 举报
回复
// Add a GroupBox to a form and set some of its common properties.
private void AddMyGroupBox()
{
// Create a GroupBox and add a TextBox to it.
GroupBox groupBox1 = new GroupBox();
TextBox textBox1 = new TextBox();
textBox1.Location = new Point(15, 15);
groupBox1.Controls.Add(textBox1);

// Set the Text and Dock properties of the GroupBox.
groupBox1.Text = "MyGroupBox";
groupBox1.Dock = DockStyle.Top;

// Disable the GroupBox (which disables all its child controls)
groupBox1.Enabled = false;

// Add the Groupbox to the form.
this.Controls.Add(groupBox1);
}
lsqlxq 2003-10-21
  • 打赏
  • 举报
回复
TO:ETstudio(外星人)
我已经发邮件给你了:)
谢谢
ETstudio 2003-10-21
  • 打赏
  • 举报
回复
要的话就发信给我吧:et@fabrefactum.com

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧