如何使用颜色随机的文本框背面颜色?
textbox1.backcolor = color.**random**;
答案 0 :(得分:1)
使用Random
-class。您可以从System.Drawing.KnownColor
-enum:
KnownColor[] colors = (KnownColor[])Enum.GetValues(typeof(System.Drawing.KnownColor));
colors = Array.FindAll(colors, c => c =! KnownColor.Transparent); // is not allowed
Random r = new Random();
KnownColor randomColor = colors[r.Next(colors.Length)];
textbox1.BackColor = Color.FromKnownColor(randomColor);
请注意,您不应该在循环中调用此代码,否则它将始终生成相同的"随机"数字,因为它是以当前时间播种的。而是重用相同的随机实例。因此,如果它在循环中声明并初始化循环外的随机变量。
答案 1 :(得分:0)
08:57:20 **** Build of configuration gcc-debug for project DB ****
make MODE=debug CONFIGNAME=gcc-debug all
dbSyncSensor.cc
Makefile:93: recipe for target 'out/gcc-debug//dbSyncSensor.o' failed
In file included from dbSyncSensor.cc:11:0:
C:\Program Files (x86)\MySQL\MySQL Connector C++ 1.1.6\include\mysql_connection.h:30:32: fatal error: cppconn/connection.h: No such file or directory
#include <cppconn/connection.h>
^
compilation terminated.
make: *** [out/gcc-debug//dbSyncSensor.o] Error 1
08:57:21 Build Finished (took 1s.629ms)