Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 749845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:28:55+00:00 2026-05-14T14:28:55+00:00

I am building a Windows Forms applicaton in C# and have a TrackBar on

  • 0

I am building a Windows Forms applicaton in C# and have a TrackBar on my Form. How can I compute the (pixel) position of the tip of the tracker? I would like to draw a line from there to another point on my form.
Additionally I also would like to compute the lowest and highest possible x position of the tip.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:28:56+00:00Added an answer on May 14, 2026 at 2:28 pm

    The native Windows control that is wrapped by TrackBar has an awkward restriction, you cannot get the positions for the first and last tic marks. You can however get the display rectangles for the channel and the slider. This class returns them:

    using System;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Runtime.InteropServices;
    
    class MyTrackBar : TrackBar {
      public Rectangle Slider {
        get {
          RECT rc = new RECT();
          SendMessageRect(this.Handle, TBM_GETTHUMBRECT, IntPtr.Zero, ref rc);
          return new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
        }
      }
      public Rectangle Channel {
        get {
          RECT rc = new RECT();
          SendMessageRect(this.Handle, TBM_GETCHANNELRECT, IntPtr.Zero, ref rc);
          return new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
        }
      }
      private const int TBM_GETCHANNELRECT = 0x400 + 26;
      private const int TBM_GETTHUMBRECT = 0x400 + 25;
      private struct RECT { public int left, top, right, bottom; }
      [DllImport("user32.dll", EntryPoint = "SendMessageW")]
      private static extern IntPtr SendMessageRect(IntPtr hWnd, int msg, IntPtr wp, ref RECT lp);
    }
    

    Here is a sample usage in a form, it draws a line from the first tick mark to the slider pointer:

    private void myTrackBar1_ValueChanged(object sender, EventArgs e) {
      this.Invalidate();
    }
    protected override void  OnPaint(PaintEventArgs e) {
      var chan = this.RectangleToClient(myTrackBar1.RectangleToScreen(myTrackBar1.Channel));
      var slider = this.RectangleToClient(myTrackBar1.RectangleToScreen(myTrackBar1.Slider));
      e.Graphics.DrawLine(Pens.Black, chan.Left + slider.Width / 2, myTrackBar1.Bottom + 5,
        slider.Left + slider.Width / 2, myTrackBar1.Bottom + 5);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a Windows form application using .NET 3.5. I would like to
I'm building a Windows Forms application where I have a menuStrip and a toolStripMenuItem
I'm building a Windows Forms form in C# with various elements in a panel
I 'am building a small windows form application. I have a View - a
When building a Windows Forms project in Visual Studio 2010 I have a following
I'm building a desktop app in C# with Windows Forms. I have a custom
I'm building a .net application with windows forms. I'm pondering on the following problem:
I am building a Web Application using asp.net (C#). I come from windows forms
I get the following error when building my Windows Forms solution: LC.exe exited with
I have very little experience building software for Windows, and zero experience using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.