|
Introduction
While working on my own Forms designer, I used a Toolbox from another article by Giordio Santini. However, when I saw the Toolbox in VS2005 and, after unsuccessful trials to find something like it on the Internet, I decided to make my own. That is what I've done. This control is derived directly from System.Windows.Forms.Control without using any other controls or components except ScrollBar. All drawing is made by myself and it is divided into three parts: the drawing of the whole toolbox, the single tab and the item.
Using the code
This component is fully supported by the VS designer. Just add a reference to the compiled DLL and add the toolbox or HostToolbox to your form. Alternatively, create it using the following code:
private IP.Components.Toolbox toolbox1;
toolbox1 = new IP.Components.Toolbox();
yourForm.Controls.Add(toolbox1);
You have a wide variety of settings for customizing the toolbox appearance, starting from the height of the tabs and the items, to the colors which are used for the selected item or tab, the hovered item, selection borders, and others. For more details, see the Toolbox Appearance category in the toolbox properties. Starting from version 1.2 of this component, both the Toolbox control and the Tab object implement the ITab interface. It provides support for multilevel Tabs and non-categorized Items because interface defines three primary properties:
Categories - a collection of Tabs; you could make changes to this collection at design-time and they would be displayed immediately on the control
Items - a collection of items in a category or non-categorized items of the toolbox
Owner - an owner of the object; it is always Null for Toolbox control
In the Toolbox category, you can find more properties:
CreateGeneralCategory - used to mimic the VS2005 toolbox; it creates an empty tab at run-time with the property AllowDelete set to false, by default
ItemMenu - contains the ContextMenuStrip menu object, which is shown when the user right-clicks on any enabled Item; I've added the default menu, but you can change it and set your own
TabMenu - like an ItemMenu, contains a menu which would be displayed when the user right-clicks on a Tab; I've also added a default menu
Each Tab object has its own properties, which include:
Text - caption of the tab
Opened, Visible - properties say what they mean
AllowDelete - if this property is set to true, then the tab cannot be deleted from the toolbox; it can be deleted only programmatically by setting AllowDelete = false
Selected - at run-time, you can determine if the tab is currently selected.
Also, Tab has a readonly field: PointerItem. This is an Item that is always added to a Tab at first place and does not get added to the Items collection. Thus, it cannot be removed. As with Tab, Item objects also have properties: Text, Image, Tooltip, Enabled, Visible, and Selected. I've also added the properties BackColor and ForeColor, but haven't used them. If you want, you can inherit from the Toolbox.Item class, override the OnPaint method and use those properties for drawing before adding your items to the tabs. For programmers, I've added many public and protected methods and events, including:
- Public
Toolbox.Save/Toolbox.SaveXml and Toolbox.Load/Toolbox.LoadXml for serializing/deserializing the state of a toolbox
- Public
Tab.SortItems for sorting items by alphabetical order
- Public
Tab.Select/Item.Select for selecting tabs/items in a program
- Protected method
OnSelectedChanged and public event SelectedChanged for both tabs and items
- Public
Tab.EnsureVisible/Item.EnsureVisible for scrolling to tab/item
- Protected methods for handling
Paint, MouseDown, MouseUp events on tabs and items
- Protected method
Tab.OnToggleTab and public event Tab.Toggle for handling the toggling of a tab
...and others.
Terms and conditions
The IPToolbox control is provided as free software with source code provided. You can freely use it in your applications, commercial or non-commercial. Ivan Popok, the author of the control, owns the copyright of the control and is NOT responsible for any damage to your application caused by using this control, directly or indirectly.
History
- 05/24/2006 - v.1.0
- 10/10/2006 - v.1.1
- Added missing
SelectItem event and SelectedItem property
- Added the
ShowPointer property that enables hiding of the pointer
- Added the
AutoScroll property and the ScrollView method for synchronized scrolling of the Toolbox and other controls
- Added the
TransparentColor property for the Item class
- Rewrote the
HitTest method
- Now uses the
ToolboxService class from .NET instead of my own implementation
- Added gradient background drawing and support for background image
- Added comments for all
public and protected properties
- 10/25/2006 - v.1.2
- Added multilevel tabs (see
AllowNestedTabs property)
- Added placing items directly on the Toolbox (see
AllowToolboxItems property)
- Added
OnClick and OnDoubleClick protected methods for Tab and Item objects
- Added
ColorStyle.None enumeration member (see TabColorStyle property)
- Fixed drawing of the
Item image
- Fixed showing of
TextBox for renaming
- 03/23/2007 - v.1.2.1
- Fixed saving the state of
CreateGeneralTab property
- Fixed serialization and deserialization of the nested tabs and toolbox items
- Fixed adding
Tab object to its own collection
- Added
Tag property for Tab and Item classes
- Some other minor fixes
- 05/25/2007 - v.1.3
- Re-engineered serialization/deserialization of
Items
- Applied antialiasing
| You must Sign In to use this message board. |
|
| | Msgs 1 to 25 of 104 (Total in Forum: 104) (Refresh) | FirstPrevNext |
|
 |
|
|
Hy
Thank's for this control. It is exactly what I need for my application. I have just one question.
Is it possible to delete the menu on the right click? My users don't have to modify the toolbox but just take some controls and make a drag and drop on another control.
Thanks
PS. excuse my english, I'm french 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
hi,i want to know what happen when i drag an item,for example a textbox, from toolbox?i mean;what is creating in background as textbox1,textbox2,textbox3,because i want to extract them to another form.and also if it is possible plz guid me in the way of changing selectedObject to the current textBox1,2,3 or label1,2,3 that are dragged into the from in order to use propertiyGrid for them.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hello,
I used your control, its cool, it works and is very easy to use !! Great job..
Cheers, Aseem Chiplonkar
Enough research will tend to support whatever theory !
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi
I want to use toolbox. Its working fine. keep it up.
I want to know the following. Once I drag and drop a control (textbox) and then a label and switch between these controls (textbox and label) how do I know which control has the focus.
Kindly help me in regards to this. Thanks in advance
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Great control but RightToLeft functionality is missing.
Computer Science is no more about computers than Astronomy is about telescopes. - E. W. Dijkstra
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
It is not possible to drag a tab to another tab. Instead to be moved to the tab I drag it to it is placed in its parent
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Can i able to include the controls in the run time by this one? I want to develop an application which provide the user to include controls in "run time" by drag and drop option. Can any one help me in this?
Raghava
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
Hi!
The support for using a keyboard on the control has been up in another message, is tis something you can add to the control?
Great work you have done with the control, thx a lot. 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
This is an excellent piece of software. Well done!
There is someone in my head but it's not me - Pink Floyd
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Hi, Nordin Rahman!
Thanks for your comment!
Nordin Rahman wrote: Do you post this project somewhere else (souceforge/codeplex).
No, there is the latest version, though I can post it to code.google.com, if you want.
Nordin Rahman wrote: Is there any documentation in VS2005 style (can be done via SandCastle?? not sure)?
Sure, at the top of the article there is a link for the help file created using SandCastle (but for version 1.2.1 only , though the difference isn't great)
Nordin Rahman wrote: How about the licensing? Can I use it freely both in commercial/non-commercial and open/closed-source?
Yes, you can use it wherever you want, I've already wrote it But if you send me a link to product site where it was used, I would be pleased
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi! Greate control! Thanks you a lot. By the way I tried to read the help, but it doesn't work. All URLs are not valid? Can you help me please with a help? Привет земляку!!!! 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi
I got some warnings regarding the use of SerializeItem in your code.. Is this correct?
And the image files are there now but they look strange.. the background of the image files is not transparant anymore, it's black. The image files I added are from png files.
This is vb.. I load my image icon with this code, it wokrs fine .
Myiteme.image = CType(resources.GetObject("Test.Image"), System.Drawing.Image)
So when loading the image with code it looks fine, but loading with xml I get the black backgrounds
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, Neno
Yes, Obsolete warnings are correct, try to avoid using of those methods in your code.
[Neno] wrote: And the image files are there now but they look strange.. the background of the image files is not transparant anymore, it's black. The image files I added are from png files.
That's the problem that I've not included serialization of images by default in previous versions - from the runtime I can't determine what type of the image is associated with the Item, so I've hardcoded to serialize it to BMP format. But bmp is lossy format compared to png, so the backgroud of the image is lost. To solve the problem, you have to serialize images manually. Inherit from the Item class, override Image property and add an XmlIgnore attribute for it, then override methods SerializeToXml and DeserializeXml like that:
[System.Xml.Serialization.XmlIgnore] public override System.Drawing.Image Image { get { return base.Image; } set { base.Image = value; } }
protected override System.Xml.XmlElement SerializeToXml(System.Xml.XmlDocument document) { System.Xml.XmlElement xml = base.SerializeToXml(document);
using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) { Image.Save(stream, System.Drawing.Imaging.ImageFormat.Png); stream.Flush(); xml.SetAttribute("Image", Convert.ToBase64String(stream.ToArray())); } }
protected override void DeserializeXml(XmlElement element) { base.DeserializeXml(element); System.Xml.XmlAttribute imageAttribute = element.Attributes["Image"]; if (imageAttribute != null) { System.IO.MemoryStream stream = new System.IO.MemoryStream(Convert.FromBase64String(attribute.Value)); this.Image = System.Drawing.Image.FromStream(stream); } }
You can omit overriding of Image property and DeserializeXml method, but in that case image would be serialized twice, though only the second would be saved to XML
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
public partial class UserControl1 : UserControl { private UserControl1 _userCtl;
public UserControl1 UserCtl { get { return _userCtl; } set { _userCtl = value; } }
public UserControl1() { InitializeComponent(); } }
In RealTime: .... class Form1:Form{ public Form1(){ InitializeComponent();//-2 UserControl1 are (uc1 and uc2) and 1 property grid propertygrid1.selectobject=uc1; //now in RealTime I whant set in uc1.UserCtl - some as uc2 BUT IN DropDownList I look none? //pleas help me } } ....
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi! 
In your example you have this code to save the settings to xml this.toolbox1.Save("toolbox.xml");
I use the same function in vb to save my settings but I when doing that the image on the items dosen't get saved. I got a imges on the item when running the program
Here is the xml file after a save.
<code> <ToolboxConfig> <Toolbox general="False" itemHeight="20" tabHeight="16" autoScroll="True" allowToolboxItems="True" allowNested="False" drawLevel="False" showAll="False" showIcons="True" showPointer="False"> <Category text="Avvikande poster" opened="True" deletable="False"> <Item text="Test" tip="Test" /> <Item text="Test2" tip="Test2" /> </Category> </Toolbox> </ToolboxConfig> </code>
Must I add the item in a certain way to get it to work? I get my image from the froms resx file not the global.
/Neno
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, Neno!
You're right, images are not serialized by default, you should serialize them yourself. Just inherit from the Toolbox, and override methods SerializeItem and DeserializeItem (check the HostToolbox.Serializer.cs file to see how it's done). By default, only Text, Visible, Enabled and Tooltip properties are serialized.
P.S. I've noticed that the serialization isn't well done , it should be re-engineered
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Ok. I a little new when it comes to serialize items. Is it possible to add this functions so i's done automaticallywhen using the save function.
But in you XML file there are image suport.
I'm not exactly sure if I understand how to do this. 
Can I add a row like this one to serialize the image in the SerializeItem function tabItem.SetAttribute(Serializer_Text, hostItem.Text);
and one in the DeserializeItem.
someting like this?? but what should xxxxx be?? and the code in the DeserializeItem how do I fix the value from string to image.
internal const string Serializer_Image = "Image";
protected override void SerializeItem(XmlElement category, Toolbox.Item item) { HostItem hostItem = item as HostItem; if (hostItem != null) { --- Your code------ tabItem.SetAttribute(Serializer_Image, xxxxxxxx); } else base.SerializeItem(category, item); }
protected override void DeserializeItem(XmlElement item, ITab tab) { string stringValue;
if (GetAttribute(item, Serializer_TypeName, out stringValue)) { Type type = Type.GetType(stringValue); if (type != null) { --- Your code------
if (GetAttribute(item, Serializer_Text, out stringValue)) { hostItem.Text = stringValue; } else if (GetAttribute(item, Serializer_Image, out stringValue)) { hostItem.Image = stringValue; } } } else base.DeserializeItem(item, tab); }
-- modified at 13:48 Thursday 24th May, 2007
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I've just posted an updated article, where I've fixed serialization of Items, so now Images are saved by default. Just wait for a while 
P.S. As images are binaries, they should be converted to string to serialize into XML format. It is done like that:
string attributeValue; using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) { image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); stream.Flush(); attributeValue = Convert.ToBase64String(stream.ToArray()); }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Just a quick tip: I found that when using the control the text had no antialiasing applied. So i just added the following to the OnPaint events of the ToolBox,ToolBox.Tab and ToolBox.Item classes:
e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
And there it was perfect !!!
Great control man
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Hi Ivan,
We can get selecteditem from SelectedItem Property, But can we give a feature by which we can Set selected index if items including tabs. I want to access ToolBox items (including Tabs) just like a list.
regards, Probeer
-- modified at 8:35 Thursday 29th March, 2007
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, Probeer,
Probeer Das wrote: I want to delete some of the context menu items of ToolBoxItems and Tab. Can i do that? How?
You should inherit from Toolbox and override CreateTabMenu and CreateItemMenu methods to remove tab/item menu items or add new. Also, you can assign different menus to TabMenu/ItemMenu properties without inheriting from Toolbox.
Probeer Das wrote: We can get selecteditem from SelectedItem Property, But can we give a feature by which we can Set selected index if items including tabs. I want to access ToolBox items (including Tabs) just like a list.
Once more, you should inherit from Toolbox and call SelectTool method with a Tab or Item as a parameter. Before calling ensure that Tab/Item is visible (use EnsureVisible method) and, if selecting Item, enabled.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|