)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to specify the text alignment of the ComboBoxBarItem in WinForms XPToolBar?

Platform: WinForms |
Control: XPToolbar |
Published Date: July 16, 2015 |
Last Revised Date: February 7, 2020

Specify the text alignment

The cursor position of the ComboBoxBarItem is the same on its lost focus, by default. Like the ComboBox, the cursor position of the ComboBoxBarItem can be aligned to the left by handling its events, TextBoxBound, MouseUp, and LostFocus.

TextBoxBound:

This event is raised when TextBox bounds in the ComboBarItem is set. By handling this event, you can access its inner TextBox.

MouseUp:

This event is raised once Mouse selection occurs in the ComboBarItem. By handling this event, you can update the cursor position upon selection.

LostFocus:

This event is raised when the ComboBarItem focus is lost. By handling this event, you can update its cursor position once the focus in lost.

C#

//Initializes the TextBoxBase.
private TextBoxBase textBox = null;
//Checks whether the ComboBox is focused.
private bool textBoxFocused;
private void comboBoxBarItem1_TextBoxBound(object sender, Syncfusion.Windows.Forms.Tools.XPMenus.TextBoxBoundEventArgs args)
{
    textBox = args.TextBox;
    textBox.MouseUp += new MouseEventHandler(textBox_MouseUp);
    //The event fires when the focus leaves the text box.
    textBox.LostFocus += new System.EventHandler(textBox_LostFocus);
}
//Selects all the Text in the TextBox of the ComboBoxBarItem.
void textBox_MouseUp(object sender, MouseEventArgs e)
{
    if ((!textBoxFocused) && this.textBox1.SelectionLength == 0)
    {
        textBoxFocused = true;
        this.textBox.SelectAll();
    }
}
private void textBox_LostFocus(object sender, EventArgs e)
{
    textBoxFocused = false;
    textBox.SelectionStart = textBox.Text.Length;
    textBox.SelectionStart = 0;
}

VB

'Initializes the TextBoxBase.
Private textBox As TextBoxBase = Nothing
'Checks whether the ComboBox is focused.
Private textBoxFocused As Boolean
Private Sub comboBoxBarItem1_TextBoxBound(ByVal sender As Object, ByVal args As Syncfusion.Windows.Forms.Tools.XPMenus.TextBoxBoundEventArgs)
    textBox = args.TextBox
    AddHandler textBox.MouseUp, AddressOf textBox_MouseUp
    'The event fires when the focus leaves the text box.
    AddHandler textBox.LostFocus, AddressOf textBox_LostFocus
End Sub
'Selects all the Text in the TextBox of the ComboBoxBarItem.
Private Sub textBox_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
    If ((Not textBoxFocused)) AndAlso Me.textBox1.SelectionLength = 0 Then
       textBoxFocused = True
       Me.textBox.SelectAll()
    End If
End Sub
Private Sub textBox_LostFocus(ByVal sender As Object, ByVal e As EventArgs)
    textBoxFocused = False
    textBox.SelectionStart = textBox.Text.Length
    textBox.SelectionStart = 0
End Sub

 

ComboBoxBarItem focused on its item selection

Figure 1: ComboBoxBarItem focused on its item selection

ComboBoxBarItem text is left aligned on its focus last

Figure 2: ComboBoxBarItem text is left aligned on its focus lost

Samples:

C#: http://www.syncfusion.com/downloads/support/directtrac/141232/ze/ComboBoxJustify-897526030

VB: http://www.syncfusion.com/downloads/support/directtrac/141232/ze/ComboBoxJustify_VB-574148021

Reference link: https://help.syncfusion.com/windowsforms/xptoolbar/baritem-types#comboboxbaritem

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon