473,411 Members | 1,918 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,411 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 18847
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: 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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.