Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
2.00/5 (1 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
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
Updated 22-Apr-13 14:32pm
v4
Comments
Sergey Alexandrovich Kryukov 22-Apr-13 19:59pm    
System.Windows.Forms? Tag it: "WinForms".
—SA
7774tlas 22-Apr-13 20:30pm    
Sorry, I always forget that. - WinForms

1 solution

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).
 
Share this answer
 
Comments
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
sorawit amorn 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900