Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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
Get
Return MyBase.Text
End Get
Set(ByVal Value As String)
MyBase.Text = Value
End Set
End Property
 
Public Property TextForeColor() As Color
Get
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 13:21pm
Edited 22-Apr-13 15:32pm
v4
Comments
Sergey Alexandrovich Kryukov at 22-Apr-13 19:59pm
   
System.Windows.Forms? Tag it: "WinForms".
—SA
7774tlas at 22-Apr-13 20:30pm
   
Sorry, I always forget that. - WinForms

1 solution

Rate this: bad
good
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).
  Permalink  
Comments
7774tlas at 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 at 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:
<grid>
<Label></Label>
</grid>
 
or you can add border by having you custom object to inherit border. So hierarchically/XMAL would look like :
 
<Border>
<Grid>
<Label></Label>
</grid>
</Border>
 

I believe the default background of Label is transparent, but if not you can set pretty much any control background to be transparent
7774tlas at 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
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 205
3 Jochen Arndt 180
4 Sergey Alexandrovich Kryukov 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,650
3 Kornfeld Eliyahu Peter 3,460
4 Sergey Alexandrovich Kryukov 2,811


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 22 Apr 2013
Copyright © CodeProject, 1999-2014
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