控件(按钮)调整大小



溢出社区, 我在调整控件的大小方面遇到了一些问题(更具体地说:按钮) 背景故事: 我正在使用一个程序,要求您连接到特定网站(通过我计算机上的程序托管)。与其打开我首选的Web浏览器,不如在Visual Studio中使用Microsoft WPF c# Web浏览器工具。 现在: 我已经做到了,因此 Web 浏览器工具可以在调整窗口大小时调整大小,但调整大小会影响按钮(总共 2 个)。按钮变小,但它们只会增长到设定的大小(如在设计器中制作的那样)。XAML 视图:

<Window x:Name="PhantomBot_Browser" x:Class="PhantomBot_Browser_.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:PhantomBot_Browser_"
mc:Ignorable="d"
ResizeMode="CanResize"
Title="PhantomBot Browser" Height="446.079" Width="731.863">
<Grid>
<Grid x:Name="grid1" HorizontalAlignment="Left" VerticalAlignment="Top" Height="auto" Width="auto" >
<Grid Margin="0,35,0,0">
<Border HorizontalAlignment="Left" Width="auto" Height="auto">
<WebBrowser x:Name="webbrowser1" ClipToBounds="True" Height="auto" Width="auto" />
</Border>
</Grid>
<Grid Margin="10,10,663,385">
<Button x:Name="refresh_button" Content="Refresh" HorizontalAlignment="Left" VerticalAlignment="Top" Width="auto" Height="auto" Click="refresh_button_Click"/>
</Grid>
<Grid Margin="66,10,624,385">
<Button x:Name="gobutton" Content="GO" HorizontalAlignment="Left" VerticalAlignment="Top" Width="auto" Height="auto" Click="gobutton_Click"/>
</Grid>
</Grid>
</Grid>

MainWindow.xaml.cs view:

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void gobutton_Click(object sender, RoutedEventArgs e)
{
webbrowser1.Navigate("http://localhost:25005/panel");
}
private void refresh_button_Click(object sender, RoutedEventArgs e)
{
webbrowser1.Refresh();
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
//Grid.Width = this.ActualWidth; Remove the two slashes at the front and minus/add values ONLY if you need it.
grid1.Height = e.NewSize.Height - 100;
grid1.Width = e.NewSize.Width - 300;
webbrowser1.Height = grid1.Height - 300;
//refresh_button.Width = 51;
//gobutton.Width = 34;
}
}

我希望按钮保持在它们的位置和大小。

更新:(一些图片) 当程序尺寸较小时,图片(查看左上角的按钮! https://i.stack.imgur.com/OZa0r.png

程序尺寸较大的图片(按钮可以) https://i.stack.imgur.com/LT3yd.png

不要介意连接错误,它是故意的

Grid 101:支持添加行和列并为每个行和列设置高度/宽度,这可以相对于包含元素,也可以是固定的。 例如:

<Grid> 
<Grid.RowDefintions> 
<RowDefintion Height="Auto"/> Will receive height per child in that row.
<RowDefintion Height="5"/> Height is 5 pixels 
<RowDefinition Height=""/> Height is remaining space (Height in this case) 
<RowDefintion Height="2"/> Height is twice the height the preceeding row 
</Grid.RowDefintions> 
</Grid>

最新更新