Solved

Draw a character in two colors

Posted on 2004-10-27
197 Views
Last Modified: 2010-04-15
Hi all

I want to draw a character in two colors. For example: After display, character "X" has upper part in red and lower part in blue.
How can I do this?

Thanks.
0
Question by:melodiesoflife
    8 Comments
     
    LVL 18

    Expert Comment

    by:armoghan
    quite a difficult question :)
    0
     
    LVL 18

    Expert Comment

    by:armoghan
    The only solution I can think of is to create an image of the charactor and display it on runtime
    0
     
    LVL 18

    Expert Comment

    by:armoghan
    Ok another way is to create a custom control whcih has two labels on top of other both should have same text and different color
    Now place one label over the other. The label which is on top should have less size so that it becomes half and comes over the other label exectly
    0
     
    LVL 18

    Expert Comment

    by:armoghan
    I made these two labels and set there positions manually

    Lower part is blue and the upper part is Black

    //
                      // label1
                      //
                      this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
                      this.label1.Location = new System.Drawing.Point(104, 176);
                      this.label1.Name = "label1";
                      this.label1.Size = new System.Drawing.Size(100, 16);
                      this.label1.TabIndex = 2;
                      this.label1.Text = "label1";
                      //
                      // label2
                      //
                      this.label2.Location = new System.Drawing.Point(104, 176);
                      this.label2.Name = "label2";
                      this.label2.Size = new System.Drawing.Size(100, 8);
                      this.label2.TabIndex = 3;
                      this.label2.Text = "label1";
    0
     
    LVL 6

    Author Comment

    by:melodiesoflife
    Hi armoghan
    Thanks for your response but do you have any other solution? I hope I can do it by used Graphics, Pen ... classes.

    Thanks
    0
     
    LVL 18

    Expert Comment

    by:armoghan
    see if you can use PathGradientBrush or LinearGradientBrush in g.DrawString

    http://www.c-sharpcorner.com/2/gdi_plus.asp

    I have not done it so do tell me if it works
    0
     
    LVL 7

    Accepted Solution

    by:
    Bitmap texture= new Bitmap(pb.Width,12);
                      Graphics g = Graphics.FromImage(texture);
                      for(int i=0; i<texture.Height;i++)
                      {
                            Pen p  = new Pen(new SolidBrush(Color.FromArgb(255-(int)Math.Round((255.0/texture.Height)*i),0,(int)Math.Round((255.0/texture.Height)*i))),1.0f);
                                  
                            g.DrawLine(p,0,i,texture.Width,i);
                            p.Dispose();
                      }
                      g.Dispose();

                      Bitmap b= new Bitmap(pb.Width,pb.Height);
                      g = Graphics.FromImage(b);
                      
                      g.DrawString("he how are you",this.Font,new TextureBrush(texture),0.0f,10.0f);
                      g.Dispose();
                      pb.Image = b;
                      
    0
     
    LVL 7

    Expert Comment

    by:God_Ares
    pb is an imagebox ,, uses system.drawing,drawing2d;
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video discusses moving either the default database or any database to a new volume.

    877 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now