int[] ra = rank();
Graphics g = this.CreateGraphics();
Pen mypen = new Pen(Color.Black);
int iBarWidth = 40;
decimal dw = 1;
for (int i = 0; i < ra.Length; i++)
{
g.DrawRectangle(mypen, (i * iBarWidth) , 600 - Convert.ToInt32((ra[i] * dw)) + 50, 30, Convert.ToInt32((ra[i])));
}
麻烦解释下Graphics中几个参数是什么意思。我的窗体大小是1024*768的,我想在窗体中画点矩形图,要在下面对齐,上面又不至于顶到窗体外面去。这其中的参数如何改?
ra是一组从大到小排列好了的整数。
C# 解释Graphics的参数
答案:2 悬赏:80 手机版
解决时间 2021-12-28 18:43
- 提问者网友:孤凫
- 2021-12-28 09:30
最佳答案
- 五星知识达人网友:神也偏爱
- 2021-12-28 10:34
mypen是画笔 ,可以配置颜色和线条宽度
后面两个参数是坐标x,y,不过是相对于你要作画的控件的坐标
最后两个参数是矩形的高和宽
后面两个参数是坐标x,y,不过是相对于你要作画的控件的坐标
最后两个参数是矩形的高和宽
全部回答
- 1楼网友:千夜
- 2021-12-28 11:04
以下是我写的一个winform控件.验证码的.你看看就知道了.其实字符串变图片就是这样的
public partial class codecontrol : usercontrol
{
private string _code = "";
public string code {
get { return this._code; }
}
public codecontrol()
{
initializecomponent();
}
public void createcodeimage() {
string[] str = new string[4];
string servercode = "";
//生成随机生成器
random random = new random();
_code = "";
for (int i = 0; i < 4; i++)
{
str[i] = random.next(10).tostring().substring(0, 1);
_code += str[i];
}
createcodeimage(str);
}
private void createcodeimage(string[] checkcode)
{
if (checkcode == null || checkcode.length <= 0)
return;
//system.drawing.bitmap image = new system.drawing.bitmap((int)math.ceiling((checkcode.length * 32.5)), this.codepicturebox.height);
system.drawing.bitmap image = new system.drawing.bitmap(this.codepicturebox.width, this.codepicturebox.height);
system.drawing.graphics g = graphics.fromimage(image);
try
{
random random = new random();
//清空图片背景色
g.clear(color.white);
//画图片的背景噪音线
for (int i = 0; i < 20; i++)
{
int x1 = random.next(image.width);
int x2 = random.next(image.width);
int y1 = random.next(image.height);
int y2 = random.next(image.height);
g.drawline(new pen(color.silver), x1, y1, x2, y2);
}
//定义颜色
color[] c = { color.black, color.red, color.darkblue, color.green, color.orange, color.brown, color.darkcyan, color.purple };
//定义字体
string[] f = { "verdana", "microsoft sans serif", "comic sans ms", "arial", "宋体" };
for (int k = 0; k <= checkcode.length - 1; k++)
{
int cindex = random.next(7);
int findex = random.next(5);
font drawfont = new font(f[findex], 16, (system.drawing.fontstyle.bold));
solidbrush drawbrush = new solidbrush(c[cindex]);
float x = 3.0f;
float y = 0.0f;
float width = 20.0f;
float height = 25.0f;
int sjx = random.next(10);
int sjy = random.next(image.height - (int)height);
rectanglef drawrect = new rectanglef(x + sjx + (k * 14), y + sjy, width, height);
stringformat drawformat = new stringformat();
drawformat.alignment = stringalignment.center;
g.drawstring(checkcode[k], drawfont, drawbrush, drawrect, drawformat);
}
//画图片的前景噪音点
for (int i = 0; i < 100; i++)
{
int x = random.next(image.width);
int y = random.next(image.height);
image.setpixel(x, y, color.fromargb(random.next()));
}
//画图片的边框线
g.drawrectangle(new pen(color.silver), 0, 0, image.width - 1, image.height - 1);
system.io.memorystream ms = new system.io.memorystream();
image.save(ms, system.drawing.imaging.imageformat.gif);
this.codepicturebox.image = image.fromstream(ms);
}
finally
{
g.dispose();
image.dispose();
}
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯