473,725 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Building a Custom ToolStrip Control

Hi

I'm trying to create a composite control to be used on a ToolStrip,
consisting of a ToolStripComboB ox 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 ToolStripComboB ox cannot be placed on a
UserControl.

I've looked into the ToolStripContro lHost 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...than ks!
-----------
Feb 13 '07 #1
4 18892
Hi Richard,

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

You're right that a derived ToolStripContro lHost 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 ToolStripContro lHost.

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

Public Class ToolStripCompos ite
Inherits ToolStripContro lHost

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 ToolStripContro lHost is derived from ToolStripItem, which provides the
MouseEnter and MouseLeave events, so the derived ToolStripContro lHost 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=Trans parent
Margin-All = 0 for combobox and button

How would I go about getting the ToolStripCompos ite control to be available
at design time and in the toolbox? Not sure whether this would be possible as
the ToolStripContro lHost 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 ToolStripComboB ox?

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 ToolStripContro lHost to appear in the Toolbox, you could add
ToolboxItemAttr ibute to it. The following is a sample.

Imports system.Componen tModel

<ToolboxItemAtt ribute(True)_
Public Class ToolStripCompos ite
Inherits ToolStripContro lHost
...
End Class

Note that even after you add the ToolboxItemAttr ibute and build the
project, the derived ToolStripContro lHost 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 ToolStripContro lHost.

If you drag&drop the derived ToolStripContro lHost 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
ToolStripItemDe signerAvailabil ityAttribute to the derived
ToolStripContro lHost, 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

<ToolStripItemD esignerAvailabi lityAttribute(T oolStripItemDes ignerAvailabili t
y.All)_
Public Class ToolStripCompos ite
Inherits ToolStripContro lHost
...
End Class
is there an (easy) way to get the ComboBox to render the same way as the
ToolStripComboB ox?

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 ToolStripComboB ox.

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 ToolboxBitmapAt tribute 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
1118
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" prop2="value"> <tab prop1="value" prop2="value"> </td:navHeader> where navHeader is a WebControl that contains n Tabs, another custom WebControl.
19
2979
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 provide an open TD with a DIV in it for the content of this formlet. (The DIV is for DHTML to hide and show the content) I've created a web page showing step by step the two problems I'm encountering. This problem is much easier to see than it...
0
1112
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 am building a composit control and inheriting from the Table web control. My problem is how do I set up the control so that columns can be set at design time much like <asp:Table...> <asp:TableRow ...> <asp:TableCell...></asp:TableCell>
7
3011
by: Shimon Sim | last post by:
I have a custom composite control I have following property
1
1505
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 manipulation etc etc. The control works perfectly when placed outside a templated control but when placed in, for instance, a datagrid EditItemTemplate, I get the following error on the DataBind Method: the dreaded "Object not set to a referance"...
0
1537
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 difference. What more do I need to do? Thanks, Mike
1
1905
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 have docked it to fill the form. Next I add a ToolStrip control to tje top panel of the ToolStripContainer control. I add a few items to the ToolStrip (it doesn't matter what these items are). Finally I run the project. I can 'dock' the...
0
1899
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 ToolStrip Container. For example if user drags the ToolStrip and Docks to the Bottom of the ToolStrip Container.
5
4122
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 to wrap the control in the proper control type - which is also a container. At design time I want to be able to turn this : <my:container> <asp:textbox />
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6702
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.