Click here to Skip to main content
15,898,222 members
Home / Discussions / C#
   

C#

 
GeneralRe: ArrayList foreach Pin
Robert Rohde31-Mar-05 19:15
Robert Rohde31-Mar-05 19:15 
GeneralSystem.Web question Pin
QzRz31-Mar-05 9:32
QzRz31-Mar-05 9:32 
GeneralRe: System.Web question Pin
Sebastian Schneider31-Mar-05 17:59
Sebastian Schneider31-Mar-05 17:59 
GeneralRe: System.Web question Pin
QzRz3-Apr-05 0:42
QzRz3-Apr-05 0:42 
Generalupdate problem Pin
webhay31-Mar-05 9:29
webhay31-Mar-05 9:29 
GeneralRe: update problem Pin
Mike Dimmick31-Mar-05 10:28
Mike Dimmick31-Mar-05 10:28 
GeneralTracking External Application Windows Pin
yeela31-Mar-05 9:20
yeela31-Mar-05 9:20 
GeneralConvert Javascript to C# Code Pin
kornstyle31-Mar-05 8:39
kornstyle31-Mar-05 8:39 
GeneralRe: Convert Javascript to C# Code Pin
Richard Parsons31-Mar-05 8:46
Richard Parsons31-Mar-05 8:46 
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 

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.