0

I'm using this method to write some text on images

Bitmap bmp_hamahang = new Bitmap(WF_Certificate.Properties.Resources.Cert_template_hamahang);
...
Bitmap bmp_hamhng=new Bitmap(bmp_hamahang);
using (Graphics g = Graphics.FromImage(bmp_hamhng))
                {

                    g.DrawString(cert.gavahi_elicens, new Font("B Zar", 13, System.Drawing.FontStyle.Bold), Brushes.Blue, new Point(60, 90));
                    g.DrawString(date_cert, new Font("B Zar", 13, System.Drawing.FontStyle.Bold), Brushes.Blue, new Point(70, 130));
                    g.DrawString(cert.st_fname.Trim(' ', '\0') + " " + cert.st_lname.Trim(' ', '\0'), new Font("B Zar", 15, System.Drawing.FontStyle.Bold), Brushes.Blue, new Point(120, 280));
                    g.DrawString(cert.st_nid, new Font("B Zar", 13, System.Drawing.FontStyle.Bold), Brushes.Blue, new Point(460, 357));
                    g.DrawString(cert.standard_code, new Font("B Zar", 13, System.Drawing.FontStyle.Bold), Brushes.Blue, new Point(130, 357));
                    g.DrawString(cert.standard_name, new Font("B Zar", 11, System.Drawing.FontStyle.Bold), Brushes.Blue, new Point(440, 430));
                    g.DrawString(cert.jam, new Font("B Zar", 13, System.Drawing.FontStyle.Bold), Brushes.Blue, new Point(535, 510));
                    g.DrawString(cert.zaman_azmoon_katbi_az, new Font("B Zar", 13, System.Drawing.FontStyle.Bold), Brushes.Blue, new Point(170, 510));
                    g.DrawString(cert.nomre_final, new Font("B Zar", 13, System.Drawing.FontStyle.Bold), Brushes.Blue, new Point(500, 595));
                    g.DrawString(lvl, new Font("B Zar", 13, System.Drawing.FontStyle.Bold), Brushes.Blue, new Point(250, 595));
                    g.DrawString(cert.ostanname, new Font("B Zar", 13, System.Drawing.FontStyle.Bold), Brushes.Blue, new Point(125, 775));
                    //g.DrawString("(" + cert.markaz_name.Trim(')') , new Font("B Zar", 13, System.Drawing.FontStyle.Bold), Brushes.Blue, new Point(125, 825));
                    //g.DrawString(cert.azad_name.Trim(), new Font("B Zar", 13, System.Drawing.FontStyle.Bold), Brushes.Blue, new Point(125, 875));
                    CaptureScreen(g, cnt, bmp_hamhng);
                }

My problem is that now I have 31 bmp_hamahang image, numbered from 1 to 31 (hamahang#1 to hamahang#31). I have included all images in Resource folder. I should choose images using inst_code. For instance if(inst_code==1) is true I should load image hamahang#1 and print info on it.

Now what's the best way to do it?Should I define like this Bitmap bmp_hamahang = new Bitmap(WF_Certificate.Properties.Resources.Cert_template_hamahang);

Bitmap bmp_hamhng=new Bitmap(bmp_hamahang);

for all 31 of them?

EKrueger
  • 730
  • 8
  • 20
user2628363
  • 143
  • 1
  • 3
  • 14
  • Sounds like you want to load a resource by its name. Maybe [this](http://stackoverflow.com/questions/1192054/load-image-from-resources-area-of-project-in-c-sharp) will help? – TaW Jun 23 '14 at 07:04
  • I have done it and it's working.But now I have 31 of them. Should I define each 31 of them like this `Bitmap bmp_hamahang = new Bitmap(WF_Certificate.Properties.Resources.Cert_template_hamahang)` and then load ? Or there is another way rather than defining one by one? – user2628363 Jun 23 '14 at 07:09
  • If you can load them by their name (as a string!!!) you can put them into a List if you want to. – TaW Jun 23 '14 at 07:11
  • You mean if I put all image in List I would be able to load them by their index in the List ,say like this:`list[2]` for second image. Am I right? – user2628363 Jun 23 '14 at 07:16
  • Indeed. Very simple. It is just the loading from the Resource that is a bit more involved. – TaW Jun 23 '14 at 07:18
  • Thanks. I was not aware of List. Thanks again for your time. – user2628363 Jun 23 '14 at 07:19
  • 1
    __Do__ have a look at List and all other __Generic Colections__. Extremely useful! – TaW Jun 23 '14 at 07:21

0 Answers0