Click here to Skip to main content
13,094,411 members (56,141 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi, I am trying to make my first custom control. All I want to do is display a value in Text on a progressbar. I've added the properties that I need (TextValue & TextForeColor), but how do I display the actual text on the progressbar? This is what I have so far:

Imports System.ComponentModel

Public Class MeterBar

Inherits ProgressBar

Public Property TextValue() As String
Return MyBase.Text
End Get
Set(ByVal Value As String)
MyBase.Text = Value
End Set
End Property

Public Property TextForeColor() As Color
Return MyBase.ForeColor
End Get
Set(ByVal Value As Color)
MyBase.ForeColor = Value
End Set
End Property

-Can I display text w/o inheriting from textbox? Also, how could I set the alignment of the text w/in the progressbar (Left/Center/Right)? Please help.
Posted 22-Apr-13 12:21pm
Updated 22-Apr-13 14:32pm
Sergey Alexandrovich Kryukov 22-Apr-13 19:59pm
System.Windows.Forms? Tag it: "WinForms".
7774tlas 22-Apr-13 20:30pm
Sorry, I always forget that. - WinForms

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Short Answers:
(1) You could use Label, instead of textbox.
(2) To set the alignment, you can use grid wrap around the your object that use to display the text.

Note: When you want to create your own custom control, I would recommend you to try to make it with the combination of existing controls first. Making your own control takes a lot of time and difficult because of the complex structure of Silverlight (also WPF).
7774tlas 22-Apr-13 19:35pm
If I inherit from label will I be able to display the text w/o the displaying the label's background? I want the text to display over the progressbar (z-order). Thanks
Member 9891853 22-Apr-13 19:49pm
you are not inheriting from label. if you want to use as the object, you should inherit of the base control. For example, you can inherit grid and in you costume control have a label object as a child. So now your costume control is a grid that has label.

if you think of XAML, your control would look something like:

or you can add border by having you custom object to inherit border. So hierarchically/XMAL would look like :


I believe the default background of Label is transparent, but if not you can set pretty much any control background to be transparent
7774tlas 22-Apr-13 20:40pm
I've never used XAML, that's WPF isn't it? (sorry, I'm still learning) I'm using WinForm. The problem that I'm having w/ the label background is that it shows it's parent control's backcolor instead of the progressbar (blocks out the marquee). I came across an article on the DrawString method, could that be used to display the text?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 22 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100