在forms窗体上初始化画了几个图形,我现在点击一个按钮想改变其中一个的颜色,可总是报参数无效错误。
我知道是因为没有调用paint():方法,可现在不知道在在Click里怎么调用。
我知道是因为没有调用paint():方法,可现在不知道在在Click里怎么调用。
解决方案 »
- C# 已经实现模拟登录(可以获得登录后的html),怎样实现打开一个登录后的页面
- 接口提问,很简单的问题
- 收藏 不显示删除回复显示所有回复显示星级回复显示得分回复 winform中我怎么将ip的数据放入数据库中?
- 在c#中如何控制键盘响应
- 菜人问菜鸟问题。
- select * from datatable 怎么写
- 我想实现弹出新窗口!
- 2个不同窗体的2个dataGridView控制相同数据源问题
- 在SQL中添加数据库的问题
- 为什么我的程序取不到C盘的WINNT还有,Program Files这些系统目录???看看我的代码错了吗???
- 急!刚参加工作就让我写程序,我不会啊!谁来帮帮我!
- 关于数据库触发器
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 画矩形
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} Pen mypen=new Pen(Color.Black);
private void button1_Click(object sender, EventArgs e)
{
mypen.Color = Color.Blue;
draw();
} private void draw()
{
int x = 30;
int y = 40;
int width = 90;
int height = 90;
Graphics g = this.CreateGraphics();
g.DrawRectangle(mypen, new Rectangle(x, y, width, height));
} private void button2_Click(object sender, EventArgs e)
{
mypen.Color = Color.Red;
draw();
}
}
}
SolidBrush redBrush = new SolidBrush(Color.Red);
try
{
m_pGraphic.FillEllipse(redBrush, rcF2);
}
catch (System.Exception ex)
{
} //m_pGraphic.DrawEllipse(Pens.Orange, GetRectFromRectF(rcF2));
Font titleFont = new Font("宋体", 0.6F * m_nHeightTitle * m_dScale, GraphicsUnit.Pixel);
StringFormat strFormat = new StringFormat();
strFormat.Alignment = StringAlignment.Center;
strFormat.LineAlignment = StringAlignment.Center;
m_pGraphic.DrawString("sss".ToString(), titleFont, Brushes.Black, rcF2, strFormat);
我是在以前的代码上改的。用的是RectangleF 。总是报参数无效,查了查好像是因为Form1_Paint方法的原因。可不知道该怎么调用它。把方法写在Form1_Paint里。在窗体加载时就画上了。
要是问怎么调用Form_Paint直接调用Invalidate方法或Refresh发送WM_Paint方法就行了,要是窗体加载时就画上了,弄一个标志符不就完了。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 绘图
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} Pen p;
SolidBrush s;
private void draw(int x,int y,int width,int height)
{
Graphics g = this.CreateGraphics();
g.DrawRectangle(p, new Rectangle(x, y, width, height));
g.FillRectangle(s, x, y, width, height);
}
private void button1_Click(object sender, EventArgs e)
{
p = new Pen(Color.Green,5);
s = new SolidBrush(Color.Red);
draw(40,50,50,50);
} private void button2_Click(object sender, EventArgs e)
{
p = new Pen(Color.Red, 5);
s = new SolidBrush(Color.Yellow);
draw(150, 50, 50, 50);
}
}
}