473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Autosize Combobox in ToolStrip

Hello,

I'm still reimplementing the GUI of my app using the new toolstrips. My
current problem is to autosize a combobox to the available with in the
parent toolstrip. There are some buttons left and right of the
controlhost which contains the combobox. The right buttons are
rightaligned and I now want to fill the available space between the left
buttons and right ones with the combobox. But I can't find a fitting
property and changing the combobox with in a resize-event-handler for
the toolstrip does not seem to work, as when I'm scaling down the
toolstrip, the combobox is hidden (and displayed in the dropdown menu)
as it's too large.
Anyone out there able to help me?
Thanks in advance,

Stefan

--
___________________________________www.VBTricks.de .vu
the free resource for Visual Basic, Gambas and Pascal
components, tips & complete projects

www: http://www.VBTricks.de.vu
mail: vbtricks <at> gmx <dot> net
__________________________________________________ ___
Nov 23 '05 #1
2 6326
Hi,

Make the combobox owner drawn. Use measure string to figure out the
width needed to display the string and resize the combobox if necesssary.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet
Try
ds.ReadXml("http://forums.microsoft.com/MSDN/rss.aspx?ForumID=159&Mode=0&SiteID=1")

ComboBox1.DataSource = ds.Tables("item")
ComboBox1.DisplayMember = "title"
Dim g As Graphics = ComboBox1.CreateGraphics

For Each obj As Object In ComboBox1.Items
Dim drv As DataRowView
Dim s As String
Dim intWidth As Integer

drv = DirectCast(obj, DataRowView)
s = drv.Item("title").ToString
intWidth = g.MeasureString(s, ComboBox1.Font).Width
If ComboBox1.Width < intWidth Then ComboBox1.Width =
intWidth

Next

g.Dispose()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Ken
----------------------
"VBTricks.de.vu Webmaster" <no****@thisserverdoesntexist.com> wrote in
message news:eZ**************@TK2MSFTNGP12.phx.gbl...
Hello,

I'm still reimplementing the GUI of my app using the new toolstrips. My
current problem is to autosize a combobox to the available with in the
parent toolstrip. There are some buttons left and right of the controlhost
which contains the combobox. The right buttons are rightaligned and I now
want to fill the available space between the left buttons and right ones
with the combobox. But I can't find a fitting property and changing the
combobox with in a resize-event-handler for the toolstrip does not seem to
work, as when I'm scaling down the toolstrip, the combobox is hidden (and
displayed in the dropdown menu) as it's too large.
Anyone out there able to help me?
Thanks in advance,

Stefan

--
___________________________________www.VBTricks.de .vu
the free resource for Visual Basic, Gambas and Pascal
components, tips & complete projects

www: http://www.VBTricks.de.vu
mail: vbtricks <at> gmx <dot> net
__________________________________________________ ___

Nov 23 '05 #2
Sorry,

this is not what I meant. I do not want to size the combobox depending
on it's content-length, but to use the available space of the toolbar
containing it, for its' width (like the address-combo in the IE).
But the source you wrote might be useful in another place...
Stefan
--
___________________________________www.VBTricks.de .vu
the free resource for Visual Basic, Gambas and Pascal
components, tips & complete projects

www: http://www.VBTricks.de.vu
mail: vbtricks <at> gmx <dot> net
__________________________________________________ ___
Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fredrik Melin | last post by:
2005 RTM: Have a form, quite a few control, (full form of stuff, tab pages, buttons, labels, text-controls etc) Selecting controls, going in and out between code/design view is a little bit...
1
by: VBTricks.de.vu Webmaster | last post by:
Hello, sorry for posting this question again, but I still have found no solution. I updated my application to .NET2 and replaced the old toolbars by toolstripbars. My application does contain an...
0
by: gene kelley | last post by:
I'm migrating/rewriting one of my VB6 apps to VB2005. In the process, I'm trying to avoid using third party activex controls used in the VB6 project. One of the third party controls in the VB6...
8
by: Jordi Rico | last post by:
Hi, I've made the next inherited class in Visual Studio 2005: Public Class LabelEx Inherits System.Windows.Forms.Label Sub New() MyBase.New() Me.ForeColor = Color.Black Me.AutoSize = False...
0
by: Jon Davis | last post by:
I'm taking the items from a menustrip of a control and moving them to the parent form's menustrip: private void TakeMenus(AdminControl ac) { foreach (Control c in ac.Controls) { if (c is...
0
by: Anand Ganesh | last post by:
Hello Everybody, I am using the ToolStrip Control in .NET 2.0. I am also using a ToolStripContainer Control. I want to know how to retain the position of the ToolStrip Control in the...
4
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
The code below goes into the dropdown event handler for a standard combo box. It makes the dropdown as wide as the widest text entry. Unfortunately, this combo box is on the right edge of the...
2
by: DesCF | last post by:
I have a textbox and a combobox on a toolstrip. The user enters either an ID in the textbox or selects a name from the combobox. When the user selects a name from the combobox the textbox is...
0
by: Martijn Mulder | last post by:
The ToolStrip on top of my form is to small. I want to increase its height. Simply setting the Height-property doesn't change the height, though. So I tried to place the ToolStrip in a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.