Solved

Mimick Spring on ToolStrip

Posted on 2006-07-19
7
950 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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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