Design of VB Add-in Program-Get the control right of VB

Source: Internet
Author: User
Program | control | Design VB Add-ins design one, get the control of VB first, external, so the name thinking, of course, must be with VB to start together! After creating a new external project. In the new project, there are CONNCET.DSR in the designer, which has one of the most critical events in the device. Private Sub addininstance_onconnection (ByVal application as Object, ByVal ConnectMode as Addindesignerobjects.ext_connectmode, ByVal addInInst as Object, custom () as Variant the application in this event is vbide. To control VB, you must start from here. So there's a public vbinstance as in the declaration area. Vbide. VBE This line of code, there is a Set vbinstance = Application in this event. Then, your add-in can directly control the entire VB. It is recommended that you do not use too long variable name vbinstance, Use a short name such as VBI. Programming is not about writing. You can be brief. The goal is to complete the function, not to let people appreciate the art of writing your code. ConnectMode lets you write software that has a standard external connection. If it's not standard, your code is a lot more concise, but the functionality is daunting. In the end, when connectmode = ext_cm_external, it is for the wizard. Create a new wizard whose Component Wizard code is clear enough to tell you, "The wizard toolbar is used to start the wizard" If ConnectMode = Ext_ Cm_external Then ' is used by the wizard toolbar to start the wizard Loadme Else [...] End If Of course, now we step through the creation of the wizard, create wizard also step with worry too much, many work templates already exist, but there is a question I am curious, why did not create Wizards of the wizard, it seems to be an ironic thing, but from VB6 to vb.net I do not seem to have heard. The next thing to do is to add to the VB toolbar or menu. The same work is very simple, very important point, you need to declare a Response button event object: Public WithEvents Evnmycmdbar as CommandBarEvents CommandBarEvents There is only one event, that is Click. It is no use to declare it so. Must beIn the Addininstance_onconnection event: Dim cbmycmd As CommandBarControl Dim cbcmd As Commnadbar Then: Set cbcmd = VBI. CommandBars ("Tools") ' Tools is the name of the menu of the VB Menu tool. If you want to add to the File menu, the "file" Edit menu is the "edit" view, and the Project menu is "project." Add to the tool bar, Know the name is, recommend the best way to know the name, and then press pause when debugging, and then monitor add VBI variable, and then expand it to view, a point, absolutely can find what you want. Set Cbmycmd=cbcmd.controls.add Add a button under the setting of the caption cbmycmd.caption= "This is my button" to create an icon for the button it was the way I learned it later, and it seemed odd. Look at the code I'm going to write. Clipboard.clear ' clears the Clipboard contents. Clipboard.setdata loadrespicture (102, Vbresbitmap) ' Loads a picture of a 16*16 size from a resource or any other way. Cbmycmd.pasteface ' then paste to the button, this method Object Browser is not visible, completely invisible, and sometimes the call will be wrong. However, calling here guarantees no problem. Clipboard.clear ' finally suggest you clear out, and now you may understand another question. Why does the contents of the Clipboard before you start VB disappear after you start VB, or if you paste it on the form, A VB add-in icon appears. Very impressive. The process makes each found code first copy and then open VB and then paste, but nothing. I don't know if you have been dizzy for this! I think it must be true. The next thing you have to do is associate the button's event with the time you declared in the statement line. It's also very simple: Set Me.evnmycmdbar = VBI. Events.commandbarevents (cbmycmd) ' VBI is Vbide.vbe object. Again, you must have the Set vbi= application before creating the button this is one of the arguments for the event that is now in place. Here, if you see what's on the top, your program should be able to run. But don't forget to add frmname.show to the Evnmycmdbar event if the button is to display your form., VB control of your program will have a! Do what you want! I do not want to give you my written code, if you have the code, you will not study carefully, not careful study how can make to external!


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.