如何在用户更改坐标值时更改抽绳位置 [英] how to change the drawstring position when the user changes the coordinates values

查看:58
本文介绍了如何在用户更改坐标值时更改抽绳位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友..

i我打算在图片框上写点什么。在页面加载事件我能够做到这一点。

Hi Friends..
i am planning to write something on a picture box.in the page load event i am able to do that.

Graphics g = Graphics.FromImage(pictureBox1.Image);
Font font = new Font("Courier New", 6);

payagainst = "PARADISE TRADING, CONT &  REAL ESTATE";
amount = 3300;
g.DrawString(payagainst, font, new SolidBrush(Color.Black), pagainstX, pagainstY);



我的要求是表格中有两个文本框,即提及新绘制标签的X和Y坐标。如果用户更改文本框中的值,则必须根据文本框中给出的值更改标签的位置。在文本框中离开事件我已经编写了如下代码。但它不起作用。最新的方法是什么。


My requirement is there is two textbox in the form ie to mention the the X and Y coordinates of the newly drawn label. If the user changes the values in the textbox position of the label has to be changed according to the values given in the text box. in the text box leave event i have written the code as follows. but its not working. whats the correct method to achieve 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;
           }
       }

推荐答案

首先,创建SolidBrush然后不进行Dispoing它是一个从资源中运行系统并使其崩溃的好方法。



接下来,摆脱那个PictureBox。你不需要它,而你只是无缘无故地使你的绘图代码复杂化。用Panel替换它。



在Panels Paint事件中,输入您的绘图代码。你不需要Image的东西。 PaintEventArgs将为您提供一个要使用的Graphics对象。



最后,在类级别创建画笔并按住它直到您的应用程序退出。当发生这种情况时,请处理画笔。



哦,在文本框的Leave事件中,只需在Panel上调用Invalidate方法,它就会重绘为您的绘图代码。
First, creating that SolidBrush and then not Dispoing it is a good way to run the system out of resources and crash it.

Next, get rid of that PictureBox. You don't need it and you're just complicating your drawing code for no reason. Replace it with a Panel instead.

In the Panels Paint event, put your drawing code. You don't need the Image stuff. The PaintEventArgs will give you a Graphics object to use.

Lastly, create your brush at the class level and hold onto it until your app exits. When that happens, Dispose the Brush.

Oh, and in the Leave event for your textbox, just call the Invalidate method on the Panel and it'll redraw itself with your drawing code.


这篇关于如何在用户更改坐标值时更改抽绳位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆