Click here to Skip to main content
15,887,881 members
Home / Discussions / C#
   

C#

 
GeneralRe: Convert Javascript to C# Code Pin
Judah Gabriel Himango31-Mar-05 9:00
sponsorJudah Gabriel Himango31-Mar-05 9:00 
GeneralExposing a control through a property Pin
Richard Parsons31-Mar-05 8:26
Richard Parsons31-Mar-05 8:26 
GeneralRe: Exposing a control through a property Pin
spif200131-Mar-05 19:54
spif200131-Mar-05 19:54 
GeneralRe: Exposing a control through a property Pin
spif200131-Mar-05 20:02
spif200131-Mar-05 20:02 
QuestionMatching visual lines in RTF with internal Lines? Pin
LongRange.Shooter31-Mar-05 8:10
LongRange.Shooter31-Mar-05 8:10 
QuestionHow to add a new user using DirectoryServices (User Logon Name) Pin
markaelkins31-Mar-05 6:09
markaelkins31-Mar-05 6:09 
GeneralDrawing a transparent labe over another control Pin
RudyBone31-Mar-05 5:29
RudyBone31-Mar-05 5:29 
GeneralRe: Drawing a transparent labe over another control Pin
Heath Stewart31-Mar-05 6:34
protectorHeath Stewart31-Mar-05 6:34 
A more appropriate way would be to extend the ProgressBar control and draw the label yourself. Putting a transparent control over it will require owner drawing anyway (to mask out everything but the text, which isn't easy if you want anti-aliased text) and will require more memory since another control is required (controls are windows and too many is very expensive).

So, extend the ProgressBar class and draw the text in the middle like so (just a basic example):
public class ProgressWithText : ProgressBar
{
  Brush textBrush;
  public ProgressWithText()
  {
    SetStyle(ControlStyles.UserPaint, true);
    textBrush = new SolidBrush(ForeColor);
  }
 
  protected override void OnPaint(PaintEventArgs e)
  {
    base.OnPaint(e);
 
    e.Graphics.DrawString(Value.ToString() + "%", Font, textBrush,
      (RectangleF)Bounds);
  }
  protected override void OnForeColorChanged(EventArgs e)
  {
    base.OnForeColorChanged(e);
    if (textBrush != null)
      textBrush.Dispose();
 
    textBrush = new SolidBrush(ForeColor);
  }
}
If you want to change the color of part of the text when the actual progress bar moves under the text, you should consider painting the whole thing (easier in the long run), which isn't too hard. Search for "progress bar" on this site for a number of good articles about owner-drawn progress bars.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralRe: Drawing a transparent labe over another control Pin
RudyBone31-Mar-05 6:51
RudyBone31-Mar-05 6:51 
GeneralRe: Drawing a transparent labe over another control Pin
Heath Stewart31-Mar-05 8:24
protectorHeath Stewart31-Mar-05 8:24 
Generalimage Resize Pin
muslcesonvacation31-Mar-05 5:20
muslcesonvacation31-Mar-05 5:20 
GeneralRe: image Resize Pin
Heath Stewart31-Mar-05 5:27
protectorHeath Stewart31-Mar-05 5:27 
GeneralRe: image Resize Pin
muslcesonvacation31-Mar-05 5:31
muslcesonvacation31-Mar-05 5:31 
GeneralRe: image Resize Pin
Heath Stewart31-Mar-05 6:25
protectorHeath Stewart31-Mar-05 6:25 
GeneralRe: image Resize Pin
Heath Stewart31-Mar-05 6:23
protectorHeath Stewart31-Mar-05 6:23 
GeneralDates Pin
scotlandc31-Mar-05 5:11
scotlandc31-Mar-05 5:11 
GeneralRe: Dates Pin
techieboi31-Mar-05 5:57
techieboi31-Mar-05 5:57 
GeneralRe: Dates Pin
Heath Stewart31-Mar-05 6:19
protectorHeath Stewart31-Mar-05 6:19 
GeneralRe: Dates Pin
scotlandc4-Apr-05 0:52
scotlandc4-Apr-05 0:52 
GeneralWhidbey - beta1 - "Beta period has expired!!!" Pin
abcxyz8231-Mar-05 3:59
abcxyz8231-Mar-05 3:59 
GeneralRe: Whidbey - beta1 - "Beta period has expired!!!" Pin
Judah Gabriel Himango31-Mar-05 4:53
sponsorJudah Gabriel Himango31-Mar-05 4:53 
GeneralRe: Whidbey - beta1 - "Beta period has expired!!!" Pin
Koushik.roy@rbc.com31-Mar-05 10:33
Koushik.roy@rbc.com31-Mar-05 10:33 
GeneralQuestion on File.Copy Pin
RockRock31-Mar-05 3:42
RockRock31-Mar-05 3:42 
GeneralRe: Question on File.Copy Pin
Colin Angus Mackay31-Mar-05 4:28
Colin Angus Mackay31-Mar-05 4:28 
GeneralRe: Question on File.Copy Pin
RockRock31-Mar-05 4:35
RockRock31-Mar-05 4:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.