ToolStripTextBox and ToolStripButton Side-By-Side

Posted on 2007-07-30
Last Modified: 2013-12-03
I have the following code and I would like to have the ToolStripTextBox and ToolStripButton drawn next ot each other... Any ideas?

Bitmap img = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(

private void InitializeComponent()
            this.components = new System.ComponentModel.Container();
            this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
            this.toolStripMenuItemReset = new System.Windows.Forms.ToolStripMenuItem();
            this.searchFieldMenuStrip = new System.Windows.Forms.ToolStripMenuItem();
            this.txtSearch = new System.Windows.Forms.ToolStripTextBox();
            this.btnSearch = new System.Windows.Forms.ToolStripButton();
            this.searchSubMenuStrip = new System.Windows.Forms.MenuStrip();            
            this.AllowUserToOrderColumns = true;

            // contextMenuStrip
            this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.contextMenuStrip.Name = "contextMenuStrip1";
            this.contextMenuStrip.Size = new System.Drawing.Size(390, 54);
            // toolStripSeparator1
            this.toolStripSeparator1.Name = "toolStripSeparator1";
            this.toolStripSeparator1.Size = new System.Drawing.Size(365, 6);
            // toolStripMenuItemReset
            this.toolStripMenuItemReset.Name = "toolStripMenuItem1";
            this.toolStripMenuItemReset.Size = new System.Drawing.Size(365, 22);
            this.toolStripMenuItemReset.Text = "Reset Search";
            this.toolStripMenuItemReset.Click += new System.EventHandler(toolStripMenuItemReset_Click);
            // searchFieldMenuStrip
            this.searchFieldMenuStrip.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.txtSearch, this.btnSearch});                
            this.searchFieldMenuStrip.Name = "toolStripMenuItem2";
            this.searchFieldMenuStrip.Size = new System.Drawing.Size(365, 22);
            this.searchFieldMenuStrip.Text = "Search for:";
            // txtSearch
            this.txtSearch.Name = "txtSearch";
            this.txtSearch.Size = new System.Drawing.Size(100, 21);
            this.txtSearch.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtSearch_KeyPress);
            // btnSearch
            this.btnSearch.Image = img;
            this.btnSearch.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
            this.btnSearch.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.ImageAndText;
            this.btnSearch.Dock = System.Windows.Forms.DockStyle.Right;
            this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
            // searchSubMenuStrip
            this.searchSubMenuStrip.Location = new System.Drawing.Point(0, 0);
            this.searchSubMenuStrip.Name = "menuStrip1";
            this.searchSubMenuStrip.Size = new System.Drawing.Size(292, 24);
            this.searchSubMenuStrip.TabIndex = 1;
            this.searchSubMenuStrip.Text = "menuStrip1";          
            // SearchGridControl
            this.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.SearchGridControl_ColumnHeaderMouseClick);
            this.ScrollBars = System.Windows.Forms.ScrollBars.Both;




        private System.Windows.Forms.ContextMenuStrip contextMenuStrip;
        private System.Windows.Forms.ToolStripMenuItem searchFieldMenuStrip;
        private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
        private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemReset;
        private System.Windows.Forms.ToolStripTextBox txtSearch;
        private System.Windows.Forms.MenuStrip searchSubMenuStrip;
        private System.Windows.Forms.ToolStripButton btnSearch;


Question by:yamazed
    LVL 18

    Expert Comment

    What do you mean by: >> rawn next ot each other? Do you mean ToolStripButton to be on top of the ToolStripTextBox? As far as I know, it is not possible. You can simulate something like that by creating a System.Windows.Forms.Button control, and placing it on top of the ToolStripTextBox.


    Author Comment

    What I mean is something like this:

    Search (a ToolStripMenuItem ) --> (ToolStripMenuItem ) myTextbox (space) mybutton (both in a single line)

    Currently when adding them as in this.searchFieldMenuStrip.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {this.txtSearch, this.btnSearch});    both context get displayed in a new line... What I would like is the display to be on a single line...


    LVL 18

    Accepted Solution

    So if I understood you well, you have a MenuStrip control, and you want items in dropdownlist to be displayed horisontally? :) No, that is not possible either. Even ToolStripButton is not natively supported with MenuStrip, only MenuItem, ComboBox, Separator and TextBox. Maybe you should try ToolStrip control instead.

    LVL 18

    Expert Comment

    Altough if you use DropDownButton in ToolStrip, it has the same behavour as TollStripMenuItem, so you will end up as with MenuStrip.


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now