Click here to Skip to main content
15,897,968 members
Home / Discussions / C#
   

C#

 
QuestionDrawing Text on Panel Pin
Danzy8315-Feb-12 0:39
Danzy8315-Feb-12 0:39 
AnswerRe: Drawing Text on Panel Pin
Pete O'Hanlon15-Feb-12 1:14
mvePete O'Hanlon15-Feb-12 1:14 
GeneralRe: Drawing Text on Panel Pin
Danzy8315-Feb-12 2:05
Danzy8315-Feb-12 2:05 
GeneralRe: Drawing Text on Panel Pin
Dave Kreskowiak15-Feb-12 3:55
mveDave Kreskowiak15-Feb-12 3:55 
AnswerRe: Drawing Text on Panel Pin
Wayne Gaylard15-Feb-12 1:22
professionalWayne Gaylard15-Feb-12 1:22 
AnswerRe: Drawing Text on Panel Pin
BobJanova15-Feb-12 2:02
BobJanova15-Feb-12 2:02 
GeneralRe: Drawing Text on Panel Pin
Danzy8315-Feb-12 2:10
Danzy8315-Feb-12 2:10 
GeneralRe: Drawing Text on Panel Pin
Pete O'Hanlon15-Feb-12 2:25
mvePete O'Hanlon15-Feb-12 2:25 
One way to handle this is to create a list of items you want to paint (ordered by the order you want to paint them), and have each one use it's own paint method. Then you just iterate over this list in the paint event and call the appropriate draw. I would typically do something like this:
C#
public abstract class PaintBase
{
  public void Draw(Graphics graphics)
  {
    OnDraw(Graphics graphics);
  }
  
  protected abstract OnDraw(Graphics graphics);
}
Then, you derive your classes from this:
C#
public class PanelText : PaintBase
{
  public Font DrawFont { get; set; }
  public string Text { get; set; }
  protected override OnDraw(Graphics graphics)
  {
    graphics.DrawString(Text, DrawFont, Brushes.Black, 50, 50);
  }
}
Then, in your form, create a list of type PaintBase and add what you need to it, as in:
C#
private List<PaintBase> paintables = new List<PaintBase>();
private void AddPaintables()
{
  PanelText panelText = new PanelText();
  panelText.DrawFont = panel.Font;
  panelText.Text = "Problem drawing text on panel";
  paintables.Add(panelText);
}
Finally, in your paint handler, all you would do is iterate like this:
C#
foreach (PaintBase item in paintables)
{
  item.Draw(e.Graphics);
}
This is a very rough implementation - it's missing a lot of error handling, validation, etc, but on the whole, you should be able to get the idea. Note that I've just knocked this up in the message editor, so I apologise if the syntax isn't 100%; it should serve to get you started though.

*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

"Mind bleach! Send me mind bleach!" - Nagy Vilmos


My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility


GeneralRe: Drawing Text on Panel Pin
BillWoodruff18-Feb-12 1:05
professionalBillWoodruff18-Feb-12 1:05 
AnswerRe: Drawing Text on Panel Pin
Montasser Ben Ouhida2-Mar-12 4:30
Montasser Ben Ouhida2-Mar-12 4:30 
QuestionHow to create method extensions but inject into them with IoC Pin
Gizz14-Feb-12 23:08
Gizz14-Feb-12 23:08 
AnswerRe: How to create method extensions but inject into them with IoC Pin
BobJanova14-Feb-12 23:24
BobJanova14-Feb-12 23:24 
GeneralRe: How to create method extensions but inject into them with IoC Pin
Gizz15-Feb-12 0:16
Gizz15-Feb-12 0:16 
GeneralRe: How to create method extensions but inject into them with IoC Pin
BobJanova15-Feb-12 0:38
BobJanova15-Feb-12 0:38 
GeneralRe: How to create method extensions but inject into them with IoC Pin
Gizz15-Feb-12 1:41
Gizz15-Feb-12 1:41 
GeneralRe: How to create method extensions but inject into them with IoC Pin
BobJanova15-Feb-12 1:58
BobJanova15-Feb-12 1:58 
QuestionGive me some Suggestions for Make a Editor like Word Pin
Marlai14-Feb-12 21:15
Marlai14-Feb-12 21:15 
AnswerRe: Give me some Suggestions for Make a Editor like Word Pin
thatraja14-Feb-12 21:36
professionalthatraja14-Feb-12 21:36 
Questionpso(particle swarm optimization) Pin
nasrin6614-Feb-12 21:01
nasrin6614-Feb-12 21:01 
Questioncapturing outward traffic Pin
saneehaAamir14-Feb-12 19:14
saneehaAamir14-Feb-12 19:14 
AnswerRe: capturing outward traffic Pin
Keith Barrow14-Feb-12 21:52
professionalKeith Barrow14-Feb-12 21:52 
QuestionAbout Reflecting and generics Pin
PozzaVecia14-Feb-12 11:06
PozzaVecia14-Feb-12 11:06 
AnswerRe: About Reflecting and generics Pin
Luc Pattyn14-Feb-12 11:19
sitebuilderLuc Pattyn14-Feb-12 11:19 
GeneralRe: About Reflecting and generics Pin
PozzaVecia14-Feb-12 11:42
PozzaVecia14-Feb-12 11:42 
AnswerRe: About Reflecting and generics Pin
Luc Pattyn14-Feb-12 12:08
sitebuilderLuc Pattyn14-Feb-12 12:08 

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.