简体   繁体   English

vb6:将图像控件动态放置在框架上

[英]vb6: place image control on frame dynamically

I'm working on a new UI-element in an vb6 programm. 我正在vb6程序中开发新的UI元素。 I need to place pictures dynamically on 2 diffenent colored background lines: 我需要将图片动态放置在2种不同颜色的背景线上:

I tried out two different ideas but none of them is working: 我尝试了两种不同的想法,但是没有一个起作用:

Idea 1 想法1

I used image control and assigned an image to the control. 我使用图像控件并将图像分配给该控件。 Then I set left, top, with and hight properties to values where I want to place the image. 然后,将left,top,with和hight属性设置为要放置图像的值。 Image was places at correct position but not in foregound on a frame but in background (behind coloured frame). 图像放置在正确的位置,但不在框架中,而是在背景中(在彩色框架之后)。

Can anyone tell me how I can place an image control in foreground (on green coloured frame)? 谁能告诉我如何将图像控件放置在前景中(绿色框上)? I need to place these image controlls dynamically from code in running program. 我需要从正在运行的程序中的代码动态放置这些图像控件。

Idea 2 想法2

In second sulution I tried to use picturebox instead of image control. 在第二种解决方案中,我尝试使用图片框而不是图像控件。 Picturebox can be placed on colored background (frame) without any problems. Picturebox可以放置在彩色背景(框架)上,没有任何问题。 Here the problem is that loaded picture has to be scaled to size of picturebox picture property. 这里的问题是,加载的图片必须缩放到图片框图片属性的大小。 Picture is loaded to picturebox by following code: Picture.Picture = LoadPicture("F:\\img.JPG") 图片通过以下代码加载到图片Picture.Picture = LoadPicture("F:\\img.JPG")Picture.Picture = LoadPicture("F:\\img.JPG")

Does anyone know how I can scale this img to size of picturebox? 有谁知道我如何将这个img缩放到Picturebox的大小?

Can anyone help me to follow up one of the solutions. 谁能帮助我跟进其中一种解决方案。 In principle I would prefere to use Image controls if it is polible to place them in foreground on frame. 原则上,如果可以控制将图像控件放置在框架中的前景,则最好使用图像控件。

I'm going to guess that after creating the image control, you are moving it onto the Frame. 我猜想在创建图像控件之后,您将其移到了Frame上。 If so, this is why the control is behind the Frame. 如果是这样,这就是控件位于框架后面的原因。 You really want the image to be inside the frame. 您确实希望图像位于框架内。 The key to do this is to set the Container property. 这样做的关键是设置Container属性。

Dim img As Image

Set img = Me.Controls.Add("VB.Image", "Image1")

If Not img Is Nothing Then
   img.Move 200, 200, 400, 400
   img.Stretch = True
   img.Picture = LoadPicture("your image.jpg")
   Set img.Container = Frame1
   img.Visible = True
End If

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM