Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ComboBox in a ToolBar? Any experts?

58 views
Skip to first unread message

Todd Geraty

unread,
Jul 29, 2002, 11:08:37 PM7/29/02
to
Hi there,

I've been scouring the newsgroups, and I haven't been able to find a way to
add a ComboBox to a ToolBar.

I've heard suggestions to use either a panel to do the job of the toolbar or
use third party code or components. Unfortunately, for various reasons,
we're unable to use either - most of the reasons center around the fact that
we already have a control inherited from System.Windows.Forms.ToolBar that
we need to use in our product.

However, I did see one post that said to create a separator on the toolbar,
use SendMessage to change the length of it, reparent a panel containing my
controls, and position it where the separator is located. I can definitely
follow this route because I'm still using ToolBar as my base control.
Unfortunately, I have no idea how to use SendMessage to change the length of
a separator in C#.

Any ideas on how to do this?

Thanks,
Todd Geraty
rm_tg...@twcny.rr.com (remove "rm_")

Todd Geraty

unread,
Jul 30, 2002, 2:51:27 PM7/30/02
to
Any ideas? This seems like it would be a common problem for people, but I
haven't seen anything in all my searching that shows how to do this?


"Todd Geraty" <rm_tg...@twcny.rr.com> wrote in message
news:Oep4DZ3NCHA.1624@tkmsftngp10...

Sean Francis

unread,
Jul 31, 2002, 10:08:11 AM7/31/02
to
I have added controls to a tool base like this ( tbtools is a toolbar )

Dim tbToolsCombo As New ComboBox()

Me.TbTools.Controls.Add(tbToolsCombo)

me.TbTools.Controls(0).Top = 1

you can use blank buttons as spacers to position the control

"Todd Geraty" <rm_tg...@twcny.rr.com> wrote in message

news:#B423n$NCHA.1996@tkmsftngp12...

Steve Cochran

unread,
Jul 31, 2002, 3:18:59 PM7/31/02
to
What I do is add programmatically (in VB) a whole bunch of separators (like 50) where the combo is positioned.

steve

"Todd Geraty" <rm_tg...@twcny.rr.com> wrote in message news:Oep4DZ3NCHA.1624@tkmsftngp10...

Phil Wright

unread,
Jul 31, 2002, 5:25:44 PM7/31/02
to
There are several toolbars available at www.codeproject.com and I think
one of them demonstrates how to add a combobox to a toolbar.

"Todd Geraty" <rm_tg...@twcny.rr.com> wrote in message
news:Oep4DZ3NCHA.1624@tkmsftngp10...

Todd Geraty

unread,
Jul 31, 2002, 7:20:31 PM7/31/02
to
There are some good examples there, but not quite what I needed.

BUT, I finally figured it out. This is what I did:

1) I created a class to wrap my Win32 calls for my project. Included in
this class are all the constants that I need, the TBBUTTONINFO struct, the
SendMessage prototype (all of which are private). I then created a public
method to set the toolbar button length.

public sealed class Win32API
{
public Win32API()
{
}

private const int WM_USER = 0x0400;
private const int TB_GETBUTTONINFO = WM_USER + 65;
private const int TB_SETBUTTONINFO = WM_USER + 66;
private const int TBIF_IMAGE = 0x00000001;
private const int TBIF_TEXT = 0x00000002;
private const int TBIF_STATE = 0x00000004;
private const int TBIF_STYLE = 0x00000008;
private const int TBIF_LPARAM = 0x00000010;
private const int TBIF_COMMAND = 0x00000020;
private const int TBIF_SIZE = 0x00000040;
private const uint TBIF_BYINDEX = 0x80000000;

[StructLayout(LayoutKind.Sequential)]
private struct TBBUTTONINFO
{
public uint cbSize;
public uint dwMask;
public int idCommand;
public int iImage;
public byte fsState;
public byte fsStyle;
public short cx;
public UIntPtr lParam;
[MarshalAs(UnmanagedType.LPTStr)] public string lpszText;
public int cchText;
}

[DllImport("User32", SetLastError=true)]
private static extern int SendMessage(
IntPtr hWnd,
int Msg,
int wParam,
ref TBBUTTONINFO lParam);

public static void SetTBButtonLength(IntPtr hwnd, int id, int
len)
{
TBBUTTONINFO ti = new TBBUTTONINFO();
ti.dwMask = TBIF_BYINDEX | TBIF_SIZE;
ti.cx = (short) len;
ti.cbSize = (uint) Marshal.SizeOf(ti);
SendMessage(hwnd, TB_SETBUTTONINFO, id, ref ti);
}
}

2) I then did the following after my InitializeComponent() call

// Set the width of the toolbar button
Win32API.SetTBButtonLength(toolBarQuickSearch.Handle, 0,
panelQuickSearch.ClientRectangle.Width);

// Re-parent the panel
panelQuickSearch.Parent = toolBarQuickSearch;

// Place the panel in the correct location
panelQuickSearch.Location = new
Point(toolBarBtnQuickSearchSep1.Rectangle.X,
toolBarBtnQuickSearchSep1.Rectangle.Y);


I think that was all the steps that I did - my code has changed some since I
did this though... Hope that helps anyone who has similar problems!

Thanks,
Todd

"Phil Wright" <phil....@dotnetmagic.com> wrote in message
news:uvJpviNOCHA.2488@tkmsftngp09...

0 new messages