Click to See Complete Forum and Search --> : How to insert Combobox control in ToolBar ?
Vasily7
November 23rd, 2002, 07:13 AM
Hello!
I am just a newbie in VB.Net but I have experience in Visual C++ programming :D
I know that in Visual C++ it was rather easy to insert Combobox Control (like in MS Word application) in Toolbar.
But when I looked through the ToolBar class description in MSDN I didn't find any help. Is it really posible to do this in VB.Net ?
P.S. I am wondering if Microsoft haven't implemented it.
Athley
November 23rd, 2002, 07:36 AM
Believe it or not. :)
Dim cb As New ComboBox()
ToolBar1.Controls.Add(cb)
/Leyan
Vasily7
November 23rd, 2002, 02:46 PM
thank you Athley for the reply. That really works!
:cool:
Angelicus
November 24th, 2002, 06:27 AM
Question along the same lines....how would I go about adding a button into the toolbar AFTER two combo boxes ? or would I just do it all when the form loads ?
Athley
November 24th, 2002, 12:44 PM
I am not sure I understand the question, could you please elaborate.
/Leyan
Vasily7
November 24th, 2002, 05:37 PM
I would like to ask the same question as Angelicus because I didn't find any way to put ToolBarButtons AFTER combobox. When I add ToolBarButtons to my ToolBar they are placed closely and there is no way to place anything else exept ToolBarButton using toolBar.Buttons.Add method. The only way to place combobox BEFORE some toolbar buttons is to use Location property of the combobox. But in this case combobox will overlap some toolbar buttons :(
Any ideas ?
Angelicus
November 25th, 2002, 12:17 AM
Basically what I'm wanting to do is have the toolbar...now within the toolbar I want 5 buttons, then two comboboxes, and then two more buttons, in exactly that order. Now I'm finding just as Vasily7 has, that the comboboxes overlap the buttons. This seems like a lot of work to do such a minute task, but I guess that's just b/c we don't know how to do it right..lol
Athley
November 25th, 2002, 03:32 AM
Hmmm, I see what you mean. Didn't go that far myself. You are sure facing a problem there with the ToolBarButtons.....
Is it possible for you to use ordinary buttons?
I added a toolbar and 2 buttons (not in the toolbar) to a form and then this code:
Dim position As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim btn As New Button()
btn.Width = 20
btn.Left = position
ToolBar1.Controls.Add(btn)
position += 20
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Dim cb As New ComboBox()
cb.Width = 50
cb.Left = position
ToolBar1.Controls.Add(cb)
position += 50
End Sub
/Leyan
Angelicus
November 25th, 2002, 03:51 AM
I could use regular buttons...but I want to use a tool bar :rolleyes: ..lol
Athley
November 25th, 2002, 03:55 AM
Well isn't that what I did? :)
The code adds ordinary buttons to the toolbar....
/Leyan
Athley
November 25th, 2002, 04:35 AM
So my question was not meant to be "Can you use regular buttons instead of the toolbar?" but "Can you use regular buttons with the toolbar?"
/Leyan
Vasily7
November 25th, 2002, 05:10 AM
I discussed this problem at another forum. People adviced the following:
1. Wait untill Microsoft solve this problem, maybe in another version of VS or Net.Framework
2. Make your own control in VB.Net .
3. Write a class in Visual C++ which is based on MFC class ReBar. And then make your own class in VB which is inheritied from C++ class.
It sounds too complicated, doesn't it ? Why should I use C++ if I wish to simplify my programming and don't want to use Visual C++ ?! I don't understand.
Athley
November 25th, 2002, 05:18 AM
What is the problem with the example I posted? Does it have to be ToolBarButtons that you add to the ToolBar?
My feeling is... Button as Button... ?
The ToolBarButton is a specifik control for the toolbar, but the Combobox is not. And it does not seem to be a ToolBarComboBox control. That lead me to test the example with Buttons and ComboBoxes and then keep track of the horizintal position.
/Leyan
Vasily7
November 25th, 2002, 05:52 AM
Hmm. I have built your example and found it rather suitable. BUT how can I get "flat" appearance of those buttons ? In my application I would like to have flat buttons on toolbar.
Athley
November 25th, 2002, 06:19 AM
Well, then I would have to agree with what you read from the other forum. I can't see a way around that.
I don't say that there is no way around, just that I don't know it . :)
/Leyan
keibetsu
November 29th, 2002, 04:39 PM
I'm not sure if this will be of any help or not, but here goes:
Add a placeholder on the toolbar, then adjust the size of the placeholder to meet your needs. You can add the placeholder by editing the toolbar properties and clicking on the "Buttons" tab. Then in the "Style" combo box, select "4 - tbrPlaceholder".
Add a combo box and position it on the toolbar. The way I added this to my toolbar in my program was by placing the combo box somewhere on the form, then cut it (CTRL-X), then clicked the toolbar and pasted it (CTRL-V). Then I moved the combo box where I wanted it with the left and top properties.
Then when you add buttons to the toolbar, insert them before the placeholder or after the placeholder and the placeholder width should remain the same. You might have to move the combo boxes left or right if you add more buttons, but that's not so difficult.
This method of putting a combo box on the toolbar might be a VERY rough way, improper way, or considered poor programming, but it worked for me and I got the result that I was looking for.
I'm by no means a professional programmer, I'm just a novice programmer who experienced the same problem of getting a combo box to appear in a toolbar.
I saw your post and I wanted to share how I managed to get it working in one of my programs.
I hope this helps.
Angelicus
December 1st, 2002, 06:03 AM
I appreciate the insight...I have yet to try that due to increased hours of working :mad: , and I'm also by no means a professional programmer... This is just something to do during my me time :D
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.