الأربعاء، 7 ديسمبر 2011

Check Boxes


Check Boxes

So start a new project. Locate the Checkbox control in the toolbox. Double click the control and a Checkbox appears on your new Form
You'll see that the Checkbox has the Text property of CheckBox1 by default, and a Name of CheckBox1. If you were to double click again on the Checkbox icon in the toolbox, the new control would be called CheckBox2.
The problem with this approach is that by double clicking each Checkbox, you have several individual Checkboxes. And if you wanted to move them around you'd have to move each Checkbox separately. There is a way to group all your Check Boxes together, and move them around as one - by using a Group Box. (You can use a Panel control as well, but we'll stick with the Group Box.)
So, click on your Checkbox with the right mouse button. From the menu that pops up, select delete to get rid of it.
Now locate the Group Box control in the toolbox:
It's better to draw this one on the form, rather than dragging and dropping. When you've added one, the only thing you should have on your Form is a Group Box.
We're not going to be using many of the Properties in the Group Box Property box. But click on your Group Box to select it, and change to the Text Property to "Soaps". Change the Font Property to anything you like. You should now have a Form like this one
A Group Box on a VB .NET form
The Group Box we just added will hold our Checkboxes. It acts as a container for the controls. To move the Checkboxes about, we can just click on the Group Box to select it, and drag and drop the Group Box somewhere else. The Checkboxes will all move with the Group Box. Let's add some Checkboxes to it.
You CAN'T double click a checkbox and add it to a Group Box. The only way to add a control to a Group Box is to draw one on the Group Box.
  1. Click once with your left mouse button on the Checkbox icon in the VB toolbox
  2. Move your mouse pointer over to the inside of the Group Box. The mouse pointer will change to a cross
  3. Hold down you left mouse button inside the Group Box. Keep the button held down, and drag outwards. Release the left button when you're happy with the size. You can always resize it later.
  4. Add 5 Checkboxes to your Group Box
  5. Change the Text property of each of your Checkboxes to any five Soap Operas. Your Form should now look something like the one below:
What your form should look like now
Run your programme to test it out. Click inside a Checkbox to select an item. Click again to deselect it. When you've finished, return to the Design Environment and click on the Group Box itself to select it. Make sure the Group Box IS selected, and not one of your Checkboxes. You can now drag the Group Box around your Form and all the Checkboxes will move with it.
The point about having Checkboxes is to offer your users multiple choices. We'll now write some code to get the choices made by the user. All the Checkboxes with ticks inside them will have their Text displayed in a Message Box

visual basic

ليست هناك تعليقات:

إرسال تعليق