开发者

C# what object can be used like Picturebox in VB6? where its possible to put objects to it?

Title said it all.

im just wandering if there something i can use

in vb6 , a picture box can be used like a container

example. i can put textbox's.. comma开发者_如何学编程nd buttons inside a picturebox.

thanks for any sudgestions ..


The closest thing to VB6's picturebox, in terms of its use as a container, would be the Panel. The Vb6 panel control was not very nice and I always used the picturebox, but the C# panel gives you almost everything VB6's picturebox did, including background image. The main difference in your case is that the C# panel does not allow drawing on it. In other words, you can put pictures in it, but you can't draw using Circle, Line, PSet etc.

Also have a look at your toolbox. Depending on what environment you're working in, you might see your controls grouped under "Common Controls", "Containers", "Components", etc. Look under "Containers" to see which controls can be used as containers.

You can also have other controls as containers, for example the picturebox. In the case of the Picturebox, you can make it the parent of your control during run-time. I think "MyControl.Parent = Picturebox1;" should work. But during design time, you cannot drop your control on the picturebox to make it the parent.

Lastly, you can create a custom control or a user control that acts as a container. As a quick example, I will show how to make a picturebox act as a container that you can drop controls on during design time.

using System.Windows.Forms;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace Whatever
{
  [Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design",
       typeof(IDesigner))] 
  public class MyPicContainer : PictureBox
  {
  }
}

Here I created a custom control, by creating a class that inherits from an existing control. I then make it behave like a design-time container by setting the appropriate attribute. I also had to add a couple of usings.

Now you can stick MyPicContainer on your form like any other control. It will behave just like a picturebox, because it is a picturebox, but at the same time it will behave like any other container control.

But unless you want to draw lines and circles on it during run-time, the control you're looking for is the Panel.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜