Cullub
Cullub

Reputation: 3218

How to set location or similar property in System.Windows.Controls.TextBox C#

I am making a System.Windows.Controls.TextBox. I need it to be a System.Windows.Controls.TextBox, not a System.Windows.Forms.TextBox, because a method needs it for SpellCheck. I have figured out, or looked up most of the other properties for this control, but I can not find this, either on Google, Stack Overflow, or Microsoft.

Here is the code I am working with:

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);

Any help is appreciated!

Edit:

I am using WinForms.

Upvotes: 1

Views: 920

Answers (2)

Kyle
Kyle

Reputation: 1365

Try the Margin property, a System.Windows.Thickness object:

this.tbSearch.Margin = new Thickness(0, 0, 50, 50);

Update

Totally seems to work in WPF.

CS:

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);
}

XAML:

<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"/>

WinForms with ElementHost

Upvotes: 2

ThomasC
ThomasC

Reputation: 118

Are you adding this to a Form? If so, all controls on a form support setting of .Top and .Left to position the element relative to the top-left corner of the former.

Upvotes: 0

Related Questions