Visual C++ .Net Tutorials: The Cursors |
|
A cursor is a small picture that represents the position of the mouse on a screen. To help in your applications development, Microsoft Visual Studio .Net ships with two sets of cursors: those readily available and those stored in the installed files. Everyone of the cursors in MSVC .Net can be easily used simply by referring to its name once you know the cursor you want to use. Those cursors already available to you are: These cursors are stored in the Cursors namespace. To use one of the available cursors, call the Cursors namespace followed by the exact name of the above list.
Besides the cursors available in the studio, Microsoft Visual Studio .Net installs additional cursors
in the To create your own cursor, on the main menu of MSVC, you can click Project -> Add New Item... or Project -> Add Resource. A starting but empty cursor would be displayed. After designing a cursor, you must save it. It has an extension of .cur. Essentially, a cursor uses only two colors, black or white. This is because a cursor is only used as an indicator of the presence or position of the mouse pointer on the screen. Based on this (limitation), you ought to be creative. The minimum you can give a cursor is a shape. This can be a square, a rectangle, a circle, an ellipse, a triangle, or any shape of your choice. You can make the cursor fully black by painting it with that color. If you decide to make the cursor completely white, make sure you draw the borders of the cursor. By playing with the frequency of pixels and varying the frequencies of black and white, you can create variances of gray. Between the black and white colors, two gray degrees are provided to you. In reality these two colors are used to give a transparency to the cursor so the background can be seen when the mouse passes over a section of the document. After creating a cursor, you must (in reality you should) define the area that serves as the actual pointer of the mouse. Such an area, actually a point, is called the hot spot of the cursor. If you don't define the hot spot, the resource editor will define or pick one for you, and you might not like it. Therefore, you should know where the hot spot of your cursor, or of any cursor your application is using, is.
After creating your own cursor, you can use a constructor of the Cursor class, which is defined in the Forms namespace. |
#using <mscorlib.dll> #using <System.dll> #using <System.Drawing.dll> #using <System.Windows.Forms.dll> using namespace System; using namespace System::Drawing; using namespace System::Windows::Forms; __gc class SimpleForm : public Form { public: // A constructor for the form object SimpleForm(); private: // This panel will host some radio buttons Panel *pnlPizzaSize; // This group box will host some check boxes GroupBox *GBox; // Some radio buttons RadioButton *rdoSmall; RadioButton *rdoMedium; RadioButton *rdoLarge; // Some check boxes CheckBox *ExtraCheese; CheckBox *Sausage; // A rectangular object Panel *pnlRectangle; }; SimpleForm::SimpleForm() { // The caption of the form this->Text = S"Cursors Example"; // The dimensions of the form this->Size = Drawing::Size(360, 265); // Create a panel pnlPizzaSize = new Panel; pnlPizzaSize->Location = Point(16, 16); pnlPizzaSize->Size = Drawing::Size(150, 108); pnlPizzaSize->BorderStyle = BorderStyle::Fixed3D; // Set a built-in cursor for the panel pnlPizzaSize->Cursor = Cursors::Hand; // Create some radio buttons // and add each to the panel that will host them rdoSmall = new RadioButton; rdoSmall->Location = Point(16, 16); rdoSmall->CheckAlign = Drawing::ContentAlignment::MiddleRight; rdoSmall->Text = S"&Small"; pnlPizzaSize->Controls->Add(rdoSmall); rdoMedium = new RadioButton; rdoMedium->Location = Point(16, 40); rdoMedium->Text = S"&Medium"; rdoMedium->CheckAlign = Drawing::ContentAlignment::MiddleRight; pnlPizzaSize->Controls->Add(rdoMedium); rdoLarge = new RadioButton; rdoLarge->Location = Point(16, 64); rdoLarge->Text = S"&Large"; rdoLarge->Checked = true; rdoLarge->CheckAlign = Drawing::ContentAlignment::MiddleRight; pnlPizzaSize->Controls->Add(rdoLarge); // Add the panel itself to the form this->Controls->Add(pnlPizzaSize); GBox = new GroupBox; GBox->Location = Point(200, 12); GBox->Text = S"Pizza Toppings"; GBox->Size = Drawing::Size(140, 110); // Set a custom cursor for the group box GBox->Cursor = new System::Windows::Forms::Cursor("ThePoint.cur"); // Create some check boxes // and add each to the group box that will host them ExtraCheese = new CheckBox; ExtraCheese->Location = Point(16, 30); ExtraCheese->CheckAlign = Drawing::ContentAlignment::MiddleRight; ExtraCheese->Text = S"&Extra Cheese"; GBox->Controls->Add(ExtraCheese); Sausage = new CheckBox; Sausage->Location = Point(16, 54); Sausage->CheckAlign = Drawing::ContentAlignment::MiddleRight; Sausage->Text = S"&Sausage"; GBox->Controls->Add(Sausage); // Add the group box to the form this->Controls->Add(GBox); // Create a rectangular object from a panel pnlRectangle = new Panel; pnlRectangle->Location = Point(16, 140); pnlRectangle->Size = Drawing::Size(325, 80); pnlRectangle->BorderStyle = BorderStyle::Fixed3D; pnlRectangle->BackColor = Color::LightBlue; // Set a custom cursor for the panel pnlRectangle->Cursor = new System::Windows::Forms::Cursor("AKeyboard.cur"); this->Controls->Add(pnlRectangle); } int __stdcall WinMain() { SimpleForm *FM = new SimpleForm; Application::Run(FM); return 0; } |
|
||
Home | Copyright © 2004-2010 FunctionX, Inc. | |
|