Making an ActiveX Control for DiceLesson #1 - Concept & Design OverviewThis is a tutorial on how to make an ActiveX Control (.OCX) that you can use in dice-related games (like Yahtzee) as well as other programs. As we create the dice control, we'll explore some of the basics of creating any ActiveX Control. Even if you're not interested in a dice control, you can use most of the techniques for an ActiveX Control of your own creation.This tutorial does assume you have a basic grasp of some VB concepts otherwise this tutorial would have to be many time larger to define all related issues. In particular we use one of VB's wizards to generate some code. If I was to create all the code by hand, or explain it line by line, I'd be writing a book instead of a few short lessons. So if you know that the 'wizard' I'm talking about isn't a funny little guy living in Oz you should be ok. Feel free to ask any questions in the ActiveX forum in the VB Forums section of this site.
Let's start by outlining some basic features and functionality that we'll want the dice control to provide. For purposes of this project, we'll assume a standard, six-sided cube with values ranging from one to six. At the very least, the control should display the appropriate number of "spots", which represent the ordinal values on each face of the dice. Additionally, these spots should be placed in a familiar pattern. I've chosen the following spot placements for each of the six ordinal values: ![]() To keep it interesting we can add some color properties. We'll allow the users of the control (called "clients") to assign color values for the border, background, spots and the inside of each spot. We'll call these properties BorderColor, BackColor, SpotColor and FillColor, respectively. This will allow us to make some colorful dice: ![]() We'll use an enumeration to assign values to the BorderStyle property. We'll call the enumeration EBorderStyles and include the members bsNone and bsSolid.
We'll implement two events - Click and DblClick. As expected, the control will raise these events when the user clicks or double-clicks the mouse while over the dice control. To disable click events, we'll also include an Enabled property. When set to False, this will prevent any click events from firing. The last feature we'll implement is the ability to re-size the control. As the dice get bigger, the spots should get bigger and the border should get thicker. This feature will be the most difficult to implement. We'll talk more about it when we add this feature to the control. For now, take a look at a small sampling of what the dice control can be sized to look like: ![]() Design SummaryTo recap, the following is a list the properties, methods and events that the dice control will expose:
What's Next?In the next lesson, we'll talk about how to create ActiveX Controls and take a closer look at some of the events that VB raises when controls are created and destroyed.© 2000, Brian P. Duckworth
[Dice 1] [Dice 2] [Dice 3] [Dice 4] [Dice 5] [Dice Bitmaps] [Dice Project]
|
Quick searches: Site Search | Advanced Site Search |
|
By using this site you agree to its terms and conditions VB Explorer and VBExplorer.com are trademarks of Exhedra Solutions, Inc. |