The Slider Control[2]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 mynote 的 blog

after placing a slider control on a form or other host, by default, its assumes a horizontal direction. if you want a vertical slider, change the value of the orientation property. if you are dynamically creating the control, its default orientation would be horizontal, whose style is tbs_horz. if you want a vertical slider, apply the tbs_vert style:

bool cdlgslide::oninitdialog() 
{
cdialog::oninitdialog();

	// todo: add extra initialization here
	csliderctrl *trackbar = new csliderctrl;

	trackbar->create(ws_child | ws_visible | tbs_vert,
	crect(20, 20, 50, 250), this, 0x14);

	return true; // return true unless you set the focus to a control
	// exception: ocx property pages should return false
}

the new slider appears as one line, horizontal or vertical, that guides the user with the area to slide the thumb. when sliding the thumb along the line, the user can set only the value where the thumb is positioned. alternatively, if you want the user to be able to select a range of values instead of just a value, at design time, you can set the enable selection property to true. this is equivalent to adding the tbs_enableselection style. a slider equipped with this style displays a 3-d “whole” in the body of the slider:

the selection area allows the user to select a range of values.

the thumb of a slider can assume one of three shapes. by default, it appears as a rectangular box. alternatively, you can convert one of its shorter borders to appear as an arrow. the shape of the thumb is controlled at design time by the point property. its default value is both, which gives it a rectangular shape. you can get this same shape by omitting or adding the tbs_both value.

for a horizontal slider, you can make the thumb’s arrow point to the left by changing the point property to top/left. if the slider is horizontal, this point value would orient the thumb arrow to the top:

to make the thumb of a dynamically created horizontal slider point up, add the tbs_top style. if the slider is vertical, to point its thumb to the left, add the tbs_left style to it.

if you want the thumb to point down for a horizontal slider, set the point property to bottom/right. this same value would make the thumb of a vertical slider point n the right direction:

to point the thumb up for a horizontal slider you are programmatically creating, add the tbs_bottom. for the thumb of a vertical slider to point right, add the tbs_right to it.

if you want to guide the user with some ticks on the control, at design time, set the tick marks property to true. if you are dynamically creating the slider and you want it to display ticks, simply adding the either the tbs_vert or the tbs_horz style equips the slider with ticks. if you don't want to display the ticks at all, at design time, clear the tick marks property or set its value to false.

the ticks are positioned on the side the thumb is pointing. if the slider is created with the both value for the point property or the tbs_both style, the ticks would appear on both sides the thumb.

the thumb of a slider is used to scroll from one minimum value to another. the range of these extreme values can be divided in regular increments that can further guide the user with value selection. to display where these increments are set, at design time, set the auto ticks property to true or add the tbs_autoticks style to a dynamic slider.

  1. while the slider control is selected on the dialog box, on the properties window, change its id to idc_slider
  2. check its auto ticks check box or set it to true
  3. check its tick marks check box or set it to true
  4. set its point property to top/left
    set to true the tooltips property of the slider control (msvc 7)
  5. add a csliderctrl control variable for the slider and name it m_carslider
  6. save all

slider methods

本文关键:The Slider Control
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top