English 中文(简体)
如何将儿童控制与父母控制权的底部对接?
原标题:How to dock a child control to bottom right of the parent control?

与母控法相比,我如何将儿童控制对接到右下角位置?

I can see that the dockstyle enum has values for None,Top,Bottom,Right,Left and Fill ...

我该怎么去右下角?

最佳回答

也许您不想将其停靠在右下。 docking 更改控件的位置, 但也更改适合窗体高度或宽度的大小 。

如果您想要保持它向下和向右, 请锁定它 。 移除左和上锚, 并添加底和右锚 。 您的控件将保持在那里!

** EDIT ** According to OP comment, it must be on the bottom and take all width and have fixed height. then you must take this steps:

要保持整洁,至少需要两个控件:

  • The one that it s on the bottom: dock it to the bottom and set its height.
  • Other one that use docking style of Fill. This makes it take all the space not occupied by the bottom control.

如果您设置有问题, 请使用布局窗口( 我希望用英文命名, 我的 VS 是本地化的) 将它们移到工作前 。 有时对它进行对接会有点恶心, 使它以您喜欢的方式工作的唯一方法就是更改使用此布局窗口的控件的顺序 。

问题回答

使用 anchorStyles :

yourComponent.Anchor = ((System.Windows.Forms.AnchorStyles)
                       ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));

右下右下角的"dock" 你需要

  1. Dock ControlA on the Right side of the parent, ControlB
  2. Set the Top Padding of ControlA to ControlA.Padding = new Padding(0, ControlB.Height - nTopPadding, 0, 0);

nTopPadding 可以是任何您需要的东西。 对于文本框、标签等, controlA.Font.H8 最有效。

AutoSize = true 时此功能也有效。 您只需要根据需要更新粘贴符 。

http://msdn.microsoft.com/en-us/library/system.windows.forms.forms.control.dock.aspx" rel = “nofollow” >MSDN Documentatio n for control.Dock :

A control can be docked to one edge of its parent container or can be docked to all edges and fill the parent container.

所以,你不能靠两边- 我实际上不知道你的意思是什么。

如果您想要在屏幕右下方保持控制, 您可能会想到 Anchor http://msdn. microsoft. com/ en- us/library/ system. windows. forms. control. anchor. aspx" rel= "nofollow" > property , 这样您就可以设置多个边缘来锁定控制 。

尝试将停靠点设为底部, 取决于您的控件, 您可能不得不关闭自动大小, 例如标签





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.