Click here to Skip to main content
13,147,044 members (62,983 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I want to make following function:

With a button_click to load a picture, which should has a embeded label at the bottom left of the picture. And then this "new" picture (picture + label) should be saved in a file.

I made the label easily over the image at bottom left. The Label should show the system date and time.
My code for loading the picture and change the value of label1 is:
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
 label1->Text = Convert::ToString(System::DateTime::Now);
 pictureBox1->Image = gcnew Bitmap( "H:\\picture1.jpg");
 //How to save this two in a file?
Now I have the picture with the datetime label in the window. And I want to save these two together as a new picture file.
How can I realize this?

I appreciate your answers!
Posted 12-Oct-12 3:33am
Updated 14-Oct-12 1:35am
Sergey Alexandrovich Kryukov 12-Oct-12 13:22pm
To avoid confusion, please change the tag C++ to C++/CLI.
christmars 14-Oct-12 7:35am
thanks for your advice!

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You could simply impose a Label instance on top of the PictureBox control, using absolute positioning (Label::Top, Label::Left). However, this won't give you transparent label background (transparency is a general problem of System.Windows.Forms, unlike WPF).

You can also draw on the image itself. The algorithm is this:

I should also note that this is too much for PictureBox — this class does not help you, just presents some extra hassles, eats up some extra resource and your development time, nothing else. You should better draw immediately on some control, using the event Paint or overriding the virtual method OnPaint. Please see my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^];
and also:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^].

christmars 14-Oct-12 7:42am
thanks a lot! I'm reading your past answers.
Sergey Alexandrovich Kryukov 14-Oct-12 23:09pm
You are welcome.
As this should solve your problem (even with PictureBox), please accept the answer formally (green button) -- thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 14 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100