设计的时候在界面上拉了个pictureBox的控件,想在运行的时候把pictureBox的边框编程虚线,
Rectangle rec = new Rectangle();
rec.Size = new Size(1this.pictureBox1.Width, this.pictureBox1.Height);
rec.Location = this.PointToClient(new Point(this.pictureBox1.Location.X, this.pictureBox1.Location.Y));
ControlPaint.DrawReversibleFrame(rec, Color.Red, FrameStyle.Dashed);
运行的时候线的位置不对 是在左上角的貌似。
Rectangle rec = new Rectangle();
rec.Size = new Size(1this.pictureBox1.Width, this.pictureBox1.Height);
rec.Location = this.PointToClient(new Point(this.pictureBox1.Location.X, this.pictureBox1.Location.Y));
ControlPaint.DrawReversibleFrame(rec, Color.Red, FrameStyle.Dashed);
运行的时候线的位置不对 是在左上角的貌似。
之后 再试试
Location 就是左上角的坐标
Pen pen = new Pen(Color.Red, 30);
gc.DrawRectangle(pen, this.pictureBox1.Location.X, this.pictureBox1.Location.Y, pictureBox1.Width, pictureBox1.Height);
{
base.OnPaint(e);
Rectangle rec = new Rectangle();
rec.Size = new Size(this.pictureBox1.Width + 200, this.pictureBox1.Height + 200);
rec.Location = pictureBox1.PointToClient(new Point(this.pictureBox1.Location.X, this.pictureBox1.Location.Y));
ControlPaint.DrawReversibleFrame(rec, Color.Red, FrameStyle.Dashed);
}
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
this.Invalidate();}还是不对啊 ,不知道该怎么调用啊。。
我在主窗体的Paint事件里实现了绘制线的功能。 private void PictureBoxTest_Paint(object sender, PaintEventArgs e)
{
Rectangle rect = new Rectangle();
rect.Size = new Size(pictureBox1.Width + 1, pictureBox1.Height + 1);
rect.Location = new Point(pictureBox1.Location.X - 1, pictureBox1.Location.Y - 1);
//ControlPaint.DrawReversibleFrame(rect, Color.Red, FrameStyle.Dashed); Pen pen = new Pen(Color.Red);
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
e.Graphics.DrawRectangle(pen, rect);
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Int32 lineWidth = 5;
Rectangle rect =
new Rectangle(
panel1.Location.X - lineWidth + 1,
panel1.Location.Y - lineWidth + 1,
panel1.Width + lineWidth,
panel1.Height + lineWidth
); using (Pen p = new Pen(Color.Black, lineWidth))
{
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
p.DashOffset = 2.0f;
e.Graphics.DrawRectangle(p, rect);
}
}
}