Scroll Bar Example


A scroll bar is a control made of a small bar that slides along another bar equipped with two arrows on its extremes. To create a scroll bar control in MSVC .NET, you use a VScrollBar or an HScrollBar classes.

Scroll Bar Example
  1. Start Microsoft Visual Studio .NET
  2. On the Start Page, click New Project (alternatively, on the main menu, you can click File -> New -> Project...)
  3. On the New Project dialog box, in the Project Types tree list, click Visual C++ Projects
  4. In the Templates list, click Managed C++ Empty Project
  5. In the Name edit box, replace the <Enter name> content with ScrollBar Example
  6. In the Location combo box, accept the suggestion or type your own. If you don't have any, type C:\Programs\MSVC.NET
  7. Click OK
  8. On the main menu, click Project -> Add New Item...
  9. In the Add New Item dialog box, in the Templates list, click C++ File
  10. In the Name box, replace <Enter name> with Main and click OK
  11. Replace the contents of the empty file with the following (I have commented the whole file to indicate what each piece of code does):
    #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 public class SimpleForm : public Form
    	VScrollBar *Scroller;
    	Label *lblPosition;
    	void ScrollerChange(Object *Sender, System::EventArgs *pArgs);
    	Text = S"ScrollBar Example";
    	Scroller = new VScrollBar;
    	Scroller->Location = Point(20, 20);
    	Scroller->Size = Drawing::Size(20, 200);
    	Scroller->Minimum = 5;
    	Scroller->Maximum = 150;
    	Scroller->add_ValueChanged(new EventHandler(this, ScrollerChange));
    	lblPosition = new Label;
    	lblPosition->Location = Point(60, 100);
    	lblPosition->AutoSize = true;
    	lblPosition->Text = "5";
    void SimpleForm::ScrollerChange(Object *Sender, System::EventArgs *pArgs)
    	lblPosition->Text = Scroller->Value.ToString();
    int __stdcall WinMain()
    	SimpleForm *FM = new SimpleForm();
    	return 0;
  12. Test the application.

Related Applications:

Body Tag Formatter


Home Copyright © 2002 FunctionX, Inc.