Google グループは Usenet の新規の投稿と購読のサポートを終了しました。過去のコンテンツは引き続き閲覧できます。
表示しない

ComboBox in a ToolBar? Any experts?

閲覧: 58 回
最初の未読メッセージにスキップ

Todd Geraty

未読、
2002/07/29 23:08:372002/07/29
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

未読、
2002/07/30 14:51:272002/07/30
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

未読、
2002/07/31 10:08:112002/07/31
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

未読、
2002/07/31 15:18:592002/07/31
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

未読、
2002/07/31 17:25:442002/07/31
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

未読、
2002/07/31 19:20:312002/07/31
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 件