Sunday, 15 June 2014

c# - how to change the drawstring position when the user changes the coordinates values -



c# - how to change the drawstring position when the user changes the coordinates values -

i planning write on image box.in page load event able that.

graphics g = graphics.fromimage(picturebox1.image); font font = new font("courier new", 6); payagainst = "paradise trading, cont & real estate"; g.drawstring(payagainst, font, new solidbrush(color.black), pagainstx, pagainsty);

my requirement there 2 textbox in form ie mention the x , y coordinates of newly drawn label. if user changes values in textbox position of label has changed according values given in text box. in text box leave event have written code follows. not working. whats right method accomplish this.

private void txtpax_leave(object sender, eventargs e) { if (flag != 0) { graphics gs = graphics.fromimage(picturebox1.image); font font = new font("courier new", 6); payagainst = "paradise trading, cont & real estate"; amount = 3300; gs.drawstring(payagainst, font, new solidbrush(color.black), float.parse(txtpax.text), float.parse(txtpay.text)); flag = 1; } }

any help appreciated

what supposed happen after string printed on image?

do need save image or pass on or display in picturebox aim?

for latter case way it:

you place drawing code in paint event , phone call it, invalidating picturebox, either whenever textboxes have alter or when leave them..:

private void picturebox1_paint(object sender, painteventargs e) { e.graphics.drawstring(yourtext, yourfont, yourbrush, float.parse(textbox1.text), float.parse(textbox2.text)); } // show after leaving textbox: private void textbox_leave(object sender, eventargs e) { picturebox1.invalidate(); } // provide live change: private void textbox_textchanged(object sender, eventargs e) { picturebox1.invalidate(); }

note should hook code both textboxes!

this code persist drawing not alter actual bitmap. guess wouldn't create sense until know text should go..

if want alter actual image can this:

private void stampbutton_click(object sender, eventargs e) { using (graphics g = graphics.fromimage(picturebox1.image)) g.drawstring(yourtext, yourfont, yourbrush, float.parse(textbox1.text), float.parse(textbox2.text)); }

..and maybe save this:

private void savebutton_click(object sender, eventargs e) { picturebox1.image.save("yourfilename", system.drawing.imaging.imageformat.yourfileformat); }

c# c#-4.0

No comments:

Post a Comment