[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

Draw a character in two colors

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
melodiesoflife
Asked:
melodiesoflife
  • 5
  • 2
1 Solution
 
armoghanCommented:
quite a difficult question :)
0
 
armoghanCommented:
The only solution I can think of is to create an image of the charactor and display it on runtime
0
 
armoghanCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
armoghanCommented:
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
 
melodiesoflifeAuthor Commented:
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
 
armoghanCommented:
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
 
God_AresCommented:
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
 
God_AresCommented:
pb is an imagebox ,, uses system.drawing,drawing2d;
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now