动态填充不同颜色的图片框 [英] Filling picturebox with different colors dynamically

查看:73
本文介绍了动态填充不同颜色的图片框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在使用c#windows应用程序创建GUI。我对这个编程很陌生。我试图根据一些条件填充不同颜色的pictureBox。



我正在尝试估算来自系统的输入数量。最初我将从系统设置预期的数量量(ucSample.Volume),这将作为比例分配给pictureBox。这很完美。我有一定的估算进货数量的条件。我有一个体积传感器,它将提供已经来自系统的数量(存储在变量体​​积中)。我每秒都在更新图片框。我为每个数量指定了颜色。



例如:我将估计的音量设置为500(ucSample.Volume = 500),然后我将启动系统。系统将慢慢倒入液体,100ml的量需要30分钟才能倒出。当系统在那时缓慢地通过液体时,我将使用传感器读取液体的密度,压力,温度并检查满足哪种条件,根据条件它将选择一种颜色。所以我有一个音量传感器,可以读取到目前为止通过系统的音量。它会每秒更新一次,例如到目前为止系统只通过10毫升液体。因此,图片框必须在比例颜色(比例为500)中仅更新最多10个。接下来假设从10毫升到20毫升进入的液体改变,所以条件将不同,所以现在我需要填充不同颜色的图片盒从10毫升到20毫升规模。 (不是从0到20毫升),这应该是这样的,它不需要改变前一个颜色,从0到10毫升保持相同的颜色,并添加10至20毫升不同的颜色。因此,我需要保持前一个原样,并从前一个终点继续更新。我每秒都在更新。

所以我们不知道系统会发生什么,所以最后看到pictureBox后我们必须估计系统的数量(总量)以及个别数量每种类型。它首先更新它将填充0到100毫升的绿色颜色,如果数量从100变为200,那么它将填充0到200毫升的另一种颜色。 (不是从100到200。)我丢失了以前的信息,所以这是完全错误的。我需要保持初始颜色,因为它在液体变化之前已经绘制了多少,然后如果有任何变化,它必须从那一点开始。



我希望我能给出更明确的解释。如果有人理解我的概念,请帮助我。

Hi everyone,

I am creating GUI using c# windows application program. I am quite new to this programming. I am trying to fill pictureBox with different colors based on some conditions.

I am trying to estimate the incoming quantity which is coming from the system. Initially I will set the expected volume of quantity is going to come(ucSample.Volume)from system, this will assign as a scale to pictureBox. This is working perfectly. I have certain conditions for estimating incoming quantity. I have one volume sensor which is going to give how much quantity already came from system(stored in variable "volume"). I am updating picture box every second. I have assigned color for each quantity.

for example: I have set estimated volume to "500"(ucSample.Volume=500), then i will start the system. System will pour the liquid slowly, it will take 30 mints for 100ml quantity to pour. When system pass liquid slowly at that time i will read the density, pressure, temperature of that liquid using sensors and checking which condition is met, according condition it will select one color. So i have one volume sensor which gives reading of volume which passed through system up to now. It will update every second, for example up to now the system passes only 10 ml liquid. So picture box has to update only up to 10 in the scale(scale of 500) with regarding color. Next suppose from 10 ml to 20 ml the incoming liquid changed so conditions will be different so now i need to fill pictureBox with different color from 10 ml to 20 ml scale. (not from 0 to 20ml), this should be like this, it won''t need to change the color of previous one which is from "0 to 10 ml" keeping the same color and add different color from "10 to 20 ml". So the concept is i need to keep the previous one as it is and keep updating from the previous end point. i am updating every second.
So we don''t know what is coming from system so finally after seeing pictureBox we have to estimate how much quantity (total) came from system and as well as individual quantity of each type. it is updating like first it will fill with "green" color from "0 to 100ml" and if quantity changed from 100 to 200 then it is filling with another color from "0 to 200 ml". (not from "100 to 200".) I am losing the previous information so it is totally wrong. I need to keep the initial color as it is up to how much it has already drawn before any changes in liquid then if any changes come it has to start from that point.

I hope i have given more clear explanation. Please help me if any one understand my concept.

推荐答案

首先,你不应该使用 PictureBox at所有。这是一个中间人,只在最简单的情况下才有用,但它只会增加一些麻烦,耗费你的开发时间和一些额外的系统资源,而不会给予任何回报。我会告诉你你应该做什么。请看我过去的答案:

如何从旧图纸中清除面板 [ ^ ],

在C#中绘制一个矩形 [ ^ ],

在图片框中附加图片 [ ^ ]。



然后,你应该了解渲染的方式确实有效。请查看我过去的答案:

绘图线在mdi子表单之间 [ ^ ],

在面板上捕获图纸 [ ^ ],

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

如何加速我的vb.net应用程序? [ ^ ]。



从那里开始,你会看到如何正确地做事。



-SA
First of all, you should not use PictureBox at all. This is a middleman which is only useful in the simplest cases, but it only adds some hassles, eats up your development time and some extra system resources not giving anything in return. I''ll tell you what you should be doing instead. 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 then, you should understand how rendering really works. Please see my past answers:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
How to speed up my vb.net application?[^].

Just start from there and you will see how to do things properly.

—SA


这篇关于动态填充不同颜色的图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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