vb.net 如何应用“锚点”属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22551561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to apply "Anchor" property
提问by dsi
I have design a form which contains one tab control and dynamically adding tab pages. Problem: in each tab page, controls are not placed at correct place as given "LOcation" field while adding "Anchor property to RIGHT OR BOTTOM or eighter of it. If i remove anchor then it works fine. But i need to use anchor to resolve resize of form should remain consistent for the controls.
我设计了一个表单,其中包含一个选项卡控件并动态添加选项卡页。问题:在每个标签页中,控件未放置在给定的“位置”字段的正确位置,同时将“锚点属性添加到 RIGHT OR BOTTOM 或其八位。如果我删除锚点,那么它工作正常。但我需要使用锚点来解决表单的大小调整应与控件保持一致。
Please suggest how i could resolve this issue and also anchor should remain there.
请建议我如何解决这个问题,并且锚应该留在那里。
Below is the code:
下面是代码:
Dim t As TabPage = New TabPage(titletext)
t.Name = IDValue
Dim w As New WebBrowser()
Dim b As New Button()
b.Text = "&Close"
w.Size = New Size(New Point(tcrViewer.Width - 3, tcrViewer.Height - (b.Height + 30)))
w.Anchor = AnchorStyles.Right Or AnchorStyles.Bottom
w.Location = New Point(0, 0)
w.Navigate(url)
t.Controls.Add(w)
b.Location = New Point(w.Width - (b.Width + 30), w.Size.Height + 3)
b.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
AddHandler b.Click, AddressOf btnReportClose_Click
t.Controls.Add(b)
tcrViewer.TabPages.Add(t)
tcrViewer.SelectedTab = t
tcrViewer.SelectedTab.Focus()
when execute the form, then, WEBEXPLORER CONTROL CUTS by form and it does not appear on "0,0" location and same thing happen for Button also. If i remove "Anchor" then its all fine as follow the location.
然后,当执行表单时,WEBEXPLORER CONTROL 按表单剪切,它不会出现在“0,0”位置,按钮也会发生同样的事情。如果我删除“锚点”,那么按照位置就可以了。
Please resolve
请解决
Thanks
谢谢
回答by dsi
The issue is resolved.
问题已解决。
I have removed "DocK" property and added webexplorer into the panel.
我已经删除了“DocK”属性并将 webexplorer 添加到面板中。
Anchor is applied to "Bottom" and "Right" only and not to top, left. Then its work fine for Bottom,right anchor style.
锚点仅应用于“底部”和“右侧”,而不应用于顶部、左侧。然后它适用于底部,右锚样式。

