C#中有什么对象可以像VB6中的Picturebox一样使用?哪里可以放置物体?
标题说明了一切。
我只是想知道是否有可以
在 vb6 中使用的东西,可以像容器示例一样使用图片框
。我可以将文本框的..命令按钮放在图片框中。
感谢您的任何建议..
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.. command buttons inside a picturebox.
thanks for any sudgestions ..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就其作为容器的用途而言,最接近 VB6 的图片框的是面板。 Vb6 面板控件不是很好,我总是使用图片框,但 C# 面板几乎提供了 VB6 的图片框所做的一切,包括背景图像。您的情况的主要区别是 C# 面板不允许在其上绘图。换句话说,你可以在里面放图片,但你不能用圆、线、PSet等来画画。
另外看看你的工具箱。根据您所处的工作环境,您可能会看到控件分组在“通用控件”、“容器”、“组件”等下。查看“容器”下的内容以了解哪些控件可以用作容器。
您还可以将其他控件作为容器,例如图片框。对于 Picturebox,您可以在运行时将其设为控件的父级。我认为“MyControl.Parent = Picturebox1;”应该有效。但在设计时,您不能将控件放在图片框上以使其成为父控件。
最后,您可以创建自定义控件或充当容器的用户控件。作为一个简单的示例,我将展示如何使图片框充当容器,您可以在设计时将控件放置在其上。
在这里,我通过创建一个继承现有控件的类来创建一个自定义控件。然后,我通过设置适当的属性使其表现得像设计时容器。我还必须添加一些用法。
现在,您可以像任何其他控件一样将 MyPicContainer 粘贴到表单上。它的行为就像图片框一样,因为它是一个图片框,但同时它的行为也像任何其他容器控件一样。
但除非您想在运行时在其上绘制直线和圆圈,否则您要寻找的控件就是面板。
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.
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.