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" <rm_tg...@twcny.rr.com> wrote in message
news:Oep4DZ3NCHA.1624@tkmsftngp10...
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
"Todd Geraty" <rm_tg...@twcny.rr.com> wrote in message news:Oep4DZ3NCHA.1624@tkmsftngp10...
"Todd Geraty" <rm_tg...@twcny.rr.com> wrote in message
news:Oep4DZ3NCHA.1624@tkmsftngp10...
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...