English 中文(简体)
我如何在图像Box控制下建立一个有色人种的边界?
原标题:How Do I Create a Colored Border on a PictureBox Control?
  • 时间:2010-12-15 03:40:16
  •  标签:
  • c#

I have an PictureBox and an Image in PictureBox1.Image property.
How do I place a border around the Image?

问题回答

This has always been what I use for that:

改变边界颜色,从电影盒控制涂料活动手里引来:

private void pictureBox1_Paint_1(object sender, PaintEventArgs e)
    {
        ControlPaint.DrawBorder(e.Graphics, pictureBox1.ClientRectangle, Color.Red, ButtonBorderStyle.Solid);
    }

为了积极改变边界色,例如从一次浮标活动中改变边界,我利用照片箱的塔格财产储存颜色,并调整图像箱的Click事件,从那里取回。 例如:

if (pictureBox1.Tag == null) { pictureBox1.Tag = Color.Red; } //Sets a default color
  ControlPaint.DrawBorder(e.Graphics, pictureBox1.ClientRectangle, (Color)pictureBox1.Tag, ButtonBorderStyle.Solid);

因此,图片箱Click事件就是如此:

private void pictureBox1_Click(object sender, EventArgs e)
        {
            if ((Color)pictureBox1.Tag == Color.Red) { pictureBox1.Tag = Color.Blue; }
            else {pictureBox1.Tag = Color.Red; }
            pictureBox1.Refresh();
        }

页: 1 提炼;,一开始,就不用忘记打上pictureBox1.Refresh(。 欢乐!

You can t set the size and color of the border of a PictureBox.
But you can do a little trick to accomplish that.

Set your image to the BackgroundImage property.
Set the BackgroundImageLayout to Center.
Change the BackColor property to the color you want the border to be.
Now resize the PictureBox enough to show the back color, which will now visually act like a border.

您还可以使用<条码>,以完成最后一步。

希望会有所帮助。

你们能够创造自己的形象 盒式从System.Windows.Forms.PictureBox 继承,并优先于PictureBox OnPaint 方法,从此使用System.Forms.ControlPaint。 采用提款法和在贵方通过 系统。 Windows.Forms.PaintEventArgs from the OnPaint methods.

与此类似;

using System.Windows.Forms;
using System.Drawing;

public class CustomPictureBox : PictureBox
{
  protected override void OnPaint(PaintEventArgs e) 
  {
    base.OnPaint(e);
    ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.Red, ButtonBorderStyle.Solid);
  }
}

这只是一个迅速的例子(未经测试),使你开始,令我感到担忧的是,我可能更彻底。

我来到这里是因为我面临同样的问题。 我指出了更为简单的解决办法。

  1. Place a label behind a picturebox.
  2. Change the back color of the label to the color of the wanted border.
  3. Set label s AutoSize property to false and Resize the label as you want.

样本:

“enterography

为实现这一目标,我使用了一个有背景形象的纽芬兰语,并建立了平整式房地产。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...