C# 如何在System.Windows.Controls.TextBox C中设置位置或类似属性#
我正在制作一个C# 如何在System.Windows.Controls.TextBox C中设置位置或类似属性#,c#,.net,winforms,textbox,C#,.net,Winforms,Textbox,我正在制作一个系统.Windows.Controls.TextBox。我需要它是一个System.Windows.Controls.TextBox,而不是System.Windows.Forms.TextBox,因为一个方法需要它来进行拼写检查。我已经找到或查找了该控件的大多数其他属性,但在Google、Stack Overflow或Microsoft上都找不到 以下是我正在使用的代码: this.tbSearch.Name = "tbSearch"; //this.tbSearch.LOCAT
系统.Windows.Controls.TextBox
。我需要它是一个System.Windows.Controls.TextBox
,而不是System.Windows.Forms.TextBox
,因为一个方法需要它来进行拼写检查。我已经找到或查找了该控件的大多数其他属性,但在Google、Stack Overflow或Microsoft上都找不到
以下是我正在使用的代码:
this.tbSearch.Name = "tbSearch";
//this.tbSearch.LOCATION //this needs to be replaced
this.tbSearch.Width = 313;
this.tbSearch.Height = 20;
this.tbSearch.TabIndex = 2;
this.tbSearch.TextChanged += new System.Windows.Controls.TextChangedEventHandler(this.tbSearch_TextChanged);
感谢您的帮助
编辑:
我正在使用WinForms。尝试属性,对象:
更新
似乎在WPF中完全有效
政务司司长:
XAML:
带ElementHost的WinForms
- 您是否将此添加到表单中?如果是这样,表单上的所有控件都支持.Top和.Left设置,以相对于前者的左上角定位元素。设置一种边框;我想要设置控件相对于窗体或其父对象的位置的东西。无论如何谢谢你!是要添加到System.Windows.Form的表单吗?我假设一个WPF System.Windows.Window或控件(它完全可以工作,请参阅更新)我将它添加到一个表单中,但是,这是一个
System.Windows.Control
对象,而不是System.Windows.Forms
。谢谢你的帮助!我不太明白。您正在将WPF对象(System.Windows.Control.Textbox位于PresentationFramework程序集中)添加到WinForm?能否显示要将其添加到窗体控件集合的位置?有一些插件可提供Forms.Textbox
拼写检查属性。这可能更简单。System.Windows.Controls
类是WPF控件。不能将WPF控件直接放置在WinForm窗体中。你需要用一个控件来“托管”它。@krillgar你有链接吗?谢谢@cullub这是来自MSDN的一封信。是我过去用过的那个。这很容易相处。
this.tbSearch.Margin = new Thickness(0, 0, 50, 50);
private void Button_Click(object sender, RoutedEventArgs e)
{
this.tbSearch.Margin = new Thickness(this.tbSearch.Margin.Left - 10,
this.tbSearch.Margin.Top - 10,
this.tbSearch.Margin.Right,
this.tbSearch.Margin.Bottom);
}
<Button Content="Button" HorizontalAlignment="Left" Margin="55,37,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
<TextBox Name="tbSearch" HorizontalAlignment="Left" Height="23" Margin="198,159,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>