473,324 Members | 2,124 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,324 software developers and data experts.

Building a Custom ToolStrip Control

Hi

I'm trying to create a composite control to be used on a ToolStrip,
consisting of a ToolStripComboBox and a ToolStripButton. It's going to be a
control used to search for text in a grid control on a WinForm.
I've got it working fine on a single form but now want to reuse this
functionality on other forms. Usually this would be a simple matter of
creating a UserControl, however a ToolStripComboBox cannot be placed on a
UserControl.

I've looked into the ToolStripControlHost however this only accepts a single
control in its constructor.

I need to make sure that I can handle the Enter and Leave events for the
composite control so that I can display / hide text "Type text to find".

What is the best way to create this control? Ideally I'd like to avoid
having to do my own Paint code etc.

thanks

Richard

-----------
Please provide code examples in VB if possible...thanks!
-----------
Feb 13 '07 #1
4 18835
Hi Richard,

You're in the right direction to implement a derived ToolStripControlHost
to solve your problem.

You're right that a derived ToolStripControlHost only accepts a single
control. You may create a UserControl, which consists of a ComboBox and a
Button, and then add the user control to the derived ToolStripControlHost.

The following is a sample. It requires that you have created a UserControl
named UserControl1, which contains a ComboBox and a Button.

Public Class ToolStripComposite
Inherits ToolStripControlHost

Public Sub New()
MyBase.New(New UserControl1())
End Sub

Public ReadOnly Property InnerControl() As UserControl1
Get
Return CType(Control, UserControl1)
End Get
End Property

End Class
The ToolStripControlHost is derived from ToolStripItem, which provides the
MouseEnter and MouseLeave events, so the derived ToolStripControlHost has
the two events as well.

Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 13 '07 #2
Thanks Linda - that's perfect!

By setting the following properties on the UserControl, it sits just right
in the ToolStrip too:
AutoSize = true
AutoSizeMode = GrowAndShrink
BackColor=Transparent
Margin-All = 0 for combobox and button

How would I go about getting the ToolStripComposite control to be available
at design time and in the toolbox? Not sure whether this would be possible as
the ToolStripControlHost has no empty constructor so cannot be viewed in the
designer.

Out of interest, is there an (easy) way to get the ComboBox to render the
same way as the ToolStripComboBox?

thanks again for your quick reply

Richard

Feb 14 '07 #3
Hi Richard,

Thank you for your feedback.

The ToolStripItem does not appear in the Toolbox by default. If you'd like
the derived ToolStripControlHost to appear in the Toolbox, you could add
ToolboxItemAttribute to it. The following is a sample.

Imports system.ComponentModel

<ToolboxItemAttribute(True)_
Public Class ToolStripComposite
Inherits ToolStripControlHost
...
End Class

Note that even after you add the ToolboxItemAttribute and build the
project, the derived ToolStripControlHost won't appear automatically in the
Toolbox. You should add it to the Toolbox manually. To do this, right-click
on the Toolbox and select 'Choose Items..' and then browse to the assembly
that contains the derived ToolStripControlHost.

If you drag&drop the derived ToolStripControlHost onto a ToolStrip control
on a form, you will find that it could not be added to the ToolStrip
control at all. It is because the designer of ToolStrip does not support
such a design-time function.

In fact, a common usage is to add
ToolStripItemDesignerAvailabilityAttribute to the derived
ToolStripControlHost, which makes the custom component available on the Add
ToolStripButton drop down menu of a ToolStrip.

The following is a sample.

Imports System.Windows.Forms.Design

<ToolStripItemDesignerAvailabilityAttribute(ToolSt ripItemDesignerAvailabilit
y.All)_
Public Class ToolStripComposite
Inherits ToolStripControlHost
...
End Class
is there an (easy) way to get the ComboBox to render the same way as the
ToolStripComboBox?

I think an easy way is to set the FlatStyle property of the ComboBox within
the UserControl to Flat. This will make the ComboBox appears almost the
same as the ToolStripComboBox.

Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
Feb 14 '07 #4
thanks Linda!

That answers all of my questions and I've now got a great control I can use
throughout my apps. Have also applied the ToolboxBitmapAttribute using an
image embedded in the control's assembly.

Very impressed! thanks again for your help

Richard
Feb 15 '07 #5

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

Similar topics

0
by: bixby | last post by:
I'm building a custom navigation control for our website developers and would like to allow our users to be able to build the control in the html as such: <td:navHeader> <tab prop1="value"...
19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
0
by: I am Sam | last post by:
Hi Everyone, I am new to Server control development and I need some serious help with something. I want to build a control that will allow the developer using the control to define columns so I...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
1
by: Sam Samnah | last post by:
Hi Everyone. It has been a long time since my last post. Nevertheless, I have built a custom server control that allows a user to edit text, bolding, italics strike though table insertion and...
0
by: MLM450 | last post by:
I have created some custom ToolStrip items using ToolStripControlHost. I can not get them to show up in the designer. I have added the ToolStripItemDesignerAvailablility attribute, but it makes no...
1
by: trainersb | last post by:
I am trying to use the ToolStrip control in Visual Studio 2005. I create a C# Windows application & add a ToolStripContainer control to the form with top, left, bottom & right panels visible. I...
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...
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.