Click here to Skip to main content
15,903,523 members
Home / Discussions / C#
   

C#

 
GeneralRe: modifying a html file in windows c# application Pin
Suunil18-May-10 3:11
Suunil18-May-10 3:11 
GeneralRe: modifying a html file in windows c# application Pin
T M Gray18-May-10 5:10
T M Gray18-May-10 5:10 
AnswerRe: modifying a html file in windows c# application Pin
Not Active18-May-10 3:54
mentorNot Active18-May-10 3:54 
AnswerRe: modifying a html file in windows c# application Pin
Suunil20-May-10 3:02
Suunil20-May-10 3:02 
QuestionReading integer from an xml file Pin
acont18-May-10 2:41
acont18-May-10 2:41 
AnswerRe: Reading integer from an xml file Pin
Seishin#18-May-10 4:40
Seishin#18-May-10 4:40 
GeneralRe: Reading integer from an xml file Pin
acont18-May-10 5:23
acont18-May-10 5:23 
AnswerRe: Reading integer from an xml file Pin
PIEBALDconsult18-May-10 4:56
mvePIEBALDconsult18-May-10 4:56 
QuestionPlz, des'nt File Delete ,, [modified] Pin
sonic74718-May-10 0:25
sonic74718-May-10 0:25 
AnswerFile not deleting [modified] Pin
DaveyM6918-May-10 0:32
professionalDaveyM6918-May-10 0:32 
GeneralRe: File not deleting Pin
Johnny J.18-May-10 1:25
professionalJohnny J.18-May-10 1:25 
GeneralRe: File not deleting Pin
DaveyM6918-May-10 2:08
professionalDaveyM6918-May-10 2:08 
AnswerRe: Plz, des'nt File Delete ,, Pin
Luc Pattyn18-May-10 1:10
sitebuilderLuc Pattyn18-May-10 1:10 
AnswerRe: Plz, des'nt File Delete ,, Pin
sonic74718-May-10 1:30
sonic74718-May-10 1:30 
GeneralRe: Plz, des'nt File Delete ,, Pin
Not Active18-May-10 2:41
mentorNot Active18-May-10 2:41 
GeneralRe: Plz, des'nt File Delete ,, Pin
William Winner18-May-10 7:29
William Winner18-May-10 7:29 
AnswerRe: Plz, des'nt File Delete ,, Pin
Seishin#18-May-10 4:39
Seishin#18-May-10 4:39 
QuestionCombobox SelectedValue Problem. Pin
Dotnetkanna17-May-10 23:30
Dotnetkanna17-May-10 23:30 
AnswerRe: Combobox SelectedValue Problem. Pin
Abhinav S18-May-10 0:34
Abhinav S18-May-10 0:34 
AnswerRe: Combobox SelectedValue Problem. Pin
Seishin#18-May-10 4:46
Seishin#18-May-10 4:46 
QuestionHow can save picturebox image using menustrip Pin
Nivas8217-May-10 21:00
Nivas8217-May-10 21:00 
Hi,

I have the picture box in which i draw the rectangle (code is below) and inside that rectangle i typed some name using label box. Now i try to store these. How can i do this using c#


private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
string file = "";
OpenFD.FileName = "";
OpenFD.Title = "open image";
OpenFD.InitialDirectory = "C";
OpenFD.Filter = "JPEG|*.jpg|Bmp|*.bmp|All Files|*.*.*";
if (OpenFD.ShowDialog() == DialogResult.OK)
{
file = OpenFD.FileName;
pictureBox1.Image = Image.FromFile(file);
sz = pictureBox1.Size;
a=sz.Width; b= sz.Height;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
switch (e.Button)
{
case MouseButtons.Left:
{
rect = new Rectangle(rect.Left, rect.Top, e.X - rect.Left, e.Y - rect.Top);
this.Invalidate();
Application.DoEvents();
break;
}
}
}



private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
rect = new Rectangle(e.X, e.Y, 0, 0);
this.Invalidate();
}



private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
using (Pen pen = new Pen(Color.Red, 2)) e.Graphics.DrawRectangle(pen, rect);
if (label1.TextAlign == ContentAlignment.TopLeft)
{
e.Graphics.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), label1.Bounds);
}
else if (label1.TextAlign == ContentAlignment.TopCenter)
{
SizeF size = e.Graphics.MeasureString(label1.Text, label1.Font);
float left = ((float)this.Width + label1.Left) / 2 - size.Width / 2;
RectangleF rect1 = new RectangleF(left, (float)label1.Top, size.Width, label1.Height);
e.Graphics.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), rect1);
}
else
{
SizeF size = e.Graphics.MeasureString(label1.Text, label1.Font);
float left = (float)label1.Width - size.Width + label1.Left;
RectangleF rect1 = new RectangleF(left, (float)label1.Top, size.Width, label1.Height);
e.Graphics.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), rect1);
}
label1.Top = rect.Top; label1.Left = rect.Left; label1.Width = rect.Width; label1.Height = rect.Height;
}


private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog SaveFD1 = new SaveFileDialog();
SaveFD1.FileName = "";
SaveFD1.InitialDirectory = "C";
SaveFD1.Title = "save file Name";
SaveFD1.Filter= "JPG|*.jpg|Bmp|*.bmp";
if (SaveFD1.ShowDialog() != DialogResult.Cancel)
{
System.IO.Stream filename = (System.IO.FileStream)SaveFD1.OpenFile();

if (SaveFD1.Filter == "JPG")
pictureBox1.Image.Save(SaveFD1.FileName);
System.Drawing.Imaging.ImageFormat.Jpeg);
else if (SaveFD1.Filter == "Bmp")
{
pictureBox1.Image.Save(filename, System.Drawing.Imaging.ImageFormat.Bmp);
}
filename.Close();
}
}



On using the above code i just load and saved the image (without drawing any rectangle). Now tried to open the saved image but its shows the error as "Out of memory".

Please Can any one tell where i am going wrong....
AnswerRe: How can save picturebox image using menustrip Pin
William Winner18-May-10 8:00
William Winner18-May-10 8:00 
GeneralRe: How can save picturebox image using menustrip Pin
Nivas8218-May-10 19:18
Nivas8218-May-10 19:18 
GeneralRe: How can save picturebox image using menustrip Pin
William Winner19-May-10 5:29
William Winner19-May-10 5:29 
GeneralRe: How can save picturebox image using menustrip Pin
Nivas8219-May-10 23:13
Nivas8219-May-10 23:13 

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.