Solved

Mimick Spring on ToolStrip

Posted on 2006-07-19
7
948 Views
Last Modified: 2012-08-13
I was trying to figure out how to span a control on the ToolStrip to expand to fill the entire ToolStrip (with other controls on it as well), similar to AutoSize=Spring for the StatusStrip.

So what I did is similar to the following:

Control.Width = ToolStrip.Width - ToolStrip.Padding.Horizontal - ToolStrip.Margin.Horizontal - (the other widths of the controls)
(BTW, grip is invisible)

Even then, it still overflows and I have to subtract by an arbitrary number to get it to fit...

Am I missing something?

Chris
0
Comment
Question by:khooc
  • 4
  • 3
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17139906
Chris,

I don't totally understand what you need.  Is the control at the far right of the ToolStrip?

Bob
0
 

Author Comment

by:khooc
ID: 17158965
Hi

I mean if you have a docked toolstrip, and I place a textbox on it, how can I make it so that the textbox's width is the same as the toolstrip without overflowing (also with other controls on the toolstrip as well)?

Chris
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17160234
Chris,

How many controls on the ToolStrip?  Do you want it to spring from the controls location to the fill the rest of the ToolStrip?

Bob
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:khooc
ID: 17162010
A variable number of controls...

> Do you want it to spring from the controls location to the fill the rest of the ToolStrip?
Yep, pretty much... basically something that mimicks the Spring property.

Chris
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 17191241
I tried something like this:

Public Class formToolStrip

  Private Sub formToolStrip_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Me.combo1.AutoSize = False
    Me.combo1.Width = Me.ToolStrip1.ClientSize.Width - Me.GetToolItemLeft(Me.combo1) - Me.ToolStrip1.OverflowButton.Width - Me.ToolStrip1.Padding.Left - Me.ToolStrip1.Margin.Left

  End Sub

  Private Function GetToolItemLeft(ByVal item As ToolStripItem)

    Dim left As Integer
    For Each search As ToolStripItem In Me.ToolStrip1.Items
      If search IsNot item Then
        left += search.Width
      End If
    Next

    Return left
  End Function
End Class

Bob
0
 

Author Comment

by:khooc
ID: 17198582
That works, thanks very much :-)  I just had to turn CanOverflow to False to prevent the overflow button from showing.

Chris
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17200133
Chris,

You also have to get the size of the button right, even when CanOverflow = False.

Bob
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

11 Experts available now in Live!

Get 1:1 Help Now