473,382 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

trackbar and double values

hi

how can I configure/set the trackbar control in order to scroll between
decimal values

i.e.

between 0.5 and 1

for example

How can I do this ?
Apr 9 '06 #1
1 10881
As you've probably noticed the TrackBar only supports int types. But
you could write a control that inherits from TrackBar and then create
NEW properties returning decimal types - using the new keyword with the
calculations factored by 0.1.

Here's an attempt (setting the Factor property adjusts the values that
are stored in the underlying control) :

using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace TrackBarDecimals
{
public class MyTrackBar : System.Windows.Forms.TrackBar
{

private System.ComponentModel.Container components = null;

public MyTrackBar()
{
InitializeComponent();
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

private void RecalcValue()
{
Value = (decimal)(base.Value * factor);
}

protected override void OnValueChanged(EventArgs e)
{
base.OnValueChanged(e);
RecalcValue();
}

protected override void OnScroll(EventArgs e)
{
base.OnScroll(e);
RecalcValue();
}
[Browsable(true)]
public new decimal Maximum
{
get { return (decimal)(base.Maximum * factor); }
set { base.Maximum = (int)(value / factor); }
}
[Browsable(true)]
public new decimal Minimum
{
get { return (decimal)(base.Minimum * factor); }
set { base.Minimum = (int)(value / factor); }
}
private decimal factor = 0.1M;
[Browsable(true)]
public decimal Factor
{
get { return factor;}
set { factor = value;}
}

private decimal myValue;
[Browsable(true)]
public new decimal Value
{
get { return myValue; }
set { myValue = value; }
}

[Browsable(true)]
public new decimal TickFrequency
{
get { return (decimal)(base.TickFrequency * factor); }
set { base.TickFrequency = (int)(value / factor); }
}

[Browsable(true)]
public new decimal SmallChange
{
get { return (decimal)(base.SmallChange * factor); }
set { base.SmallChange = (int)(value / factor); }
}

[Browsable(true)]
public new decimal LargeChange
{
get { return (decimal)(base.LargeChange * factor); }
set { base.LargeChange = (int)(value / factor); }
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

Here's a test form that uses it:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace TrackBarDecimals
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private TrackBarDecimals.MyTrackBar myTrackBar1;
private System.Windows.Forms.Label label1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.myTrackBar1 = new TrackBarDecimals.MyTrackBar();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.m yTrackBar1)).BeginInit();
this.SuspendLayout();
//
// myTrackBar1
//
this.myTrackBar1.Factor = new System.Decimal(new int[] {
1,
0,
0,
65536});
this.myTrackBar1.LargeChange = new System.Decimal(new int[] {
5,
0,
0,
65536});
this.myTrackBar1.Location = new System.Drawing.Point(32, 32);
this.myTrackBar1.Maximum = new System.Decimal(new int[] {
10,
0,
0,
65536});
this.myTrackBar1.Minimum = new System.Decimal(new int[] {
5,
0,
0,
65536});
this.myTrackBar1.Name = "myTrackBar1";
this.myTrackBar1.Size = new System.Drawing.Size(384, 42);
this.myTrackBar1.SmallChange = new System.Decimal(new int[] {
1,
0,
0,
65536});
this.myTrackBar1.TabIndex = 0;
this.myTrackBar1.TickFrequency = new System.Decimal(new int[] {
1,
0,
0,
65536});
this.myTrackBar1.Value = new System.Decimal(new int[] {
5,
0,
0,
65536});
this.myTrackBar1.ValueChanged += new
System.EventHandler(this.myTrackBar1_ValueChanged) ;
this.myTrackBar1.Scroll += new
System.EventHandler(this.myTrackBar1_Scroll);
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 96);
this.label1.Name = "label1";
this.label1.TabIndex = 1;
this.label1.Text = "label1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(456, 157);
this.Controls.Add(this.label1);
this.Controls.Add(this.myTrackBar1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.m yTrackBar1)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void myTrackBar1_Scroll(object sender, System.EventArgs e)
{
label1.Text = "Scroll Value=" + myTrackBar1.Value;
}

private void myTrackBar1_ValueChanged(object sender, System.EventArgs
e)
{
label1.Text = "Val=" + myTrackBar1.Value;
}
}
}

It's kind of there :-)

Apr 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Pls Help | last post by:
Hi, I've encountered a weird TrackBar issue, it seems to hang completely when the TrackBar.Maximum is set to certain large values.. what's going on? Have tried this on a few different 2000/XP...
2
by: juergen | last post by:
how to design a trackbar/slider with diff. look??? For my win-application I need a trackbar/slider, that doesnt look like the control-trackbar offered by vb.net. ; e.g. something like the slider...
3
by: AtlasApollo | last post by:
Greetings! We are working on a project that has a bunch of TrackBars spec'ed as graphic controls. In other words, they are slick looking and green. In the design phase, these controls look...
3
by: Geoff Cox | last post by:
Hello, I am using Visual C++ 2005 Express Beta 2 and cannot sort out how to use the Scroll property value for a trackBar. Under Event properties the name for the Scroll property is...
0
by: RuffAroundTheEdges | last post by:
I'm trying to get an aspx page to display a TrackBar. There is no TrackBar in the System.Web.UI.WebControls. Is there a TrackBar like control in System.Web.UI.WebControls? If not, is there a way to...
4
by: Bernie Yaeger | last post by:
I'd like to allow the user to zoom a window using a trackbar, say from 80% to 120% the size of the original window. I'm trying to do this with the following code, but it fails pretty miserably:...
1
by: Kris | last post by:
Hi. We are developing an application in VS2005 in C#, .NET, that has lots of tabs. On one of these tabs, there is a horizontal trackbar. However, we are unable to set the background color of the...
2
by: mmdst23 | last post by:
I'm working on a video player app, and I want to implement a trackbar that behaves like the one in Media Player, that is the cursor position moves to where the user clicked instead of moving in...
2
by: John | last post by:
Ok, something that I thought would be easy is giving me fits. Using .NET 2.0 and C# I've added a Trackbar to a form. Set some values: trackVolume.Maximum = 100; trackVolume.Minimum = 0;...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.