![]() |
![]() ![]() |
Pearls from the auld Scotsman |
ActiveX an' Visio ColorsGreetins tae ye a!!! Have ye ever noticed how bright the colors seem in the summer? Ive been doin quite a lot o travelin this spring and it looks like it will continue thruu the summer as weel. As I travel aboot, I notice how each city has its own look and feel and distinct color palette. This led me to get a grand idea about how to illustrate the use of ActiveX controls in Visio and how you can create your own custom colors with a Visio ShapeSheet function called RGB(). The accompanying Visio diagram has everything ye will need to "adaptively reuse" my code for your own solution. Let me describe a wee bit aboot whats going on here. The illustration below shows my wee sample application in runnin mode: What we have here is a Visio diagram containin a SmartShape symbol which is a simple rectangle. There are just a few special qualities aboot this rectangle that ye need to be aware of Firstly the rectangle shape has been given a name: "Pallette". We do this by selectin Format > Special and in the Name text box we enter the name "Pallette". Now you can name your shape anything you wish, but this was my own name as it came to me blame it on summer, aye? Additionally the shape has a User Defined Section added to the ShapeSheet. In the User Defined section there are three rows named User.R, User.G, and User.B. These will hold the Red, Green, and Blue numeric values that we will pass to Visios RGB() Function. In the Fill Format Section of the ShapeSheet I have placed the formula: =RGB(User.R, User.G, User.B) . As you can see the RGB() Function takes the three arguments, each with a range from 0 to 255 and passes to the Fill format cell a number equating to the unique color that will be displayed on the SmartShape symbol. A peek at the ShapeSheet would look somewhat like the following: Ive created several other shapes aboot the edge of this shape These are strictly for cosmetics and are of no real consequence, except tae mak ye look lak a brilliant graphic artist in front of the boss! Now with all of that accomplished, you are going to need to add three ActiveX Controls to your diagram. If you do not already have your Developer Toolbar visible, right-click on your Toolbar area and select the Developer Toolbar from the context menu choices. Grand! Now you will see several wee buttons on yer newly active Toolbar. One of these wee buttons looks like a Triangle, Ruler and Pencil. This is a state button; that is, it can either be depressed or raised. When it is depressed you are working in "Design Mode" in Visio. When it is raised, you are working in "Run Mode". Make sure that the button is depressed and you are in Design mode. Now click on the ActiveX Controls button. This is the wee button that looks like a VB Command Button overlappin a Radio Button . When you click this, a dialogue will appear with a list of all of the available ActiveX Controls you can work with. Scroll Down until you find the Microsoft 2.0 ScrollBar control. Highlight this item and click OK. If you right-click on the control, you can set its properties. The properties should look like the following: The important properties to set for this Control are the Orientation to Horizontal, the Minimum to 0, the Maximum to 255, and the large change to 10. Make these changes and then do this two more times so that you have all three controls as I have shown ye, in the illustration above. The Code and Events
We want to ensure that our values and the slider bar positions are initialized and accurate each time we enter the drawing or return from Design Mode to Run Mode in Visio. We also need to establish a few global variables to hold our values as long as the drawing is open. By now I assume that you all know how to enter the VBA IDE in Visio. Just as in Office, the magic key combination is Alt+F11. When you are in VBA add a new module to your current drawings project. In that new module declare the following Global variables:
Note that we have three typed as Integer to hold our R, G, and B values, one types as Visio Shape to hold the reference to the Pallette shape, and three typed as Visio Cells to hold the references to the User.R, User.G, and User.B cells. The Document has a RunModeEntered() Event. This is triggered every time the document opens or is placed in Run mode. This is where we will initialize all of the values we need and set the proper position for the thumbs on the ActiveX Controls. The code should look like the following:
Here we are obtaining the reference to the Pallette Shape and each of the User cells. Additionally we are retrieving the values stored in those cells and passing those values to the Value Property of each of the ActiveX Slider Bar Controls to properly position the thumbs. When the user interacts with any of the three slider bars, either the Change or the Scroll Event is triggered for that control. To save us from entering the same function twice for each event for each control, we are going to create 3 subroutines called R_Change(), G_Change(), and B_Change. We will call each of these routines via the proper and associated events for the controls as follows:
The thrust of any one of these three routines is that when called, it reads the new value from the controls thumb position and passes it to the Formula property of the proper User Defined cell in the Pallette Shapes ShapeSheet. It truly is no more difficult than that folks! Conclusion
Hae a grand July, dinnae burn yersel tae much an . "Haste ye back." |
|
|
Copyright © 1998-2007 DBM & others | Disclaimer | Privacy | Re-publication | Trademarks | Webmaster | Home |