关于网友提出的“ 我用Delphi写的ActiveX控件,在Delphi下用就可以透明,但到Word下就不透明了”问题疑问,本网通过在网上对“ 我用Delphi写的ActiveX控件,在Delphi下用就可以透明,但到Word下就不透明了”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 我用Delphi写的ActiveX控件,在Delphi下用就可以透明,但到Word下就不透明了
描述: 我看了一下Word下的所有控件都有BackStyle,有没有对VB熟的,BackStyle让控件透明在Delphi下如何实现?
解决方案1: 用Delphi编写的ActiveX控件不能自动支持透明
解决方案2: 你找一个拥有设置透明属性的父类继承,比如Tlabel有个属性设置透明的.
解决方案3: 如果是Tpanel 继承来自TCustomPanel---来自 TCustomControl
TCustomControl来自Twincotrol 你参考一下
如果在TCustomPanel的这里做工作是可以透明的
procedure TCustomPanel.CreateParams(var Params: TCreateParams);
const
BorderStyles: array[TBorderStyle] of DWORD = (0, WS_BORDER);
begin
inherited CreateParams(Params);
with Params do
begin
Style := Style or BorderStyles[FBorderStyle];
if NewStyleControls and Ctl3D and (FBorderStyle = bsSingle) then
begin
Style := Style and not WS_BORDER;
ExStyle := ExStyle or WS_EX_CLIENTEDGE;
// ExStyle := ExStyle or WS_EX_TRANSPARENT;如果加上则可以实现透明
//你可以参考
end;
WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
end;
end;
或者 试一下
var exstyle,stdstyle:longint;
StdStyle:= Windows.GetWindowLong(handle, GWL_EXSTYLE);
exStyle:= StdStyle and not WS_EX_TRANSPARENT;
Windows.SetWindowLong(handle, GWL_EXSTYLE, exStyle);
解决方案4: 不懂,帮顶,关注
解决方案5: >>我用Delphi写的ActiveX控件
似乎取决于你继承自那个父类
解决方案6: 我不懂啊,帮顶了!
解决方案7: 与Transparent、Opaque实现方法差不多吧
VB中
fmBackStyleTransparent 0 The background is transparent.
fmBackStyleOpaque 1 The background is opaque (default).
VB代码
BackColor, BackStyle, BorderColor, BorderStyle, ForeColor, SpecialEffect Properties Example
The following example demonstrates the BorderStyle and SpecialEffect properties, showing each border available through these properties. The example also demonstrates how to control color settings by using the BackColor, BackStyle, BorderColor, and ForeColor properties.
To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:
Six TextBox controls named TextBox1 through TextBox6.
Two ToggleButton controls named ToggleButton1 and ToggleButton2.
Private Sub UserForm_Initialize()
'Initialize each TextBox with a border style or special effect,
'and foreground and background colors
'TextBox1 initially uses a borderstyle
TextBox1.Text = "BorderStyle-Single"
TextBox1.BorderStyle = fmBorderStyleSingle
TextBox1.BorderColor = RGB(255, 128, 128)
'Color - Salmon
TextBox1.ForeColor = RGB(255, 255, 0)
'Color - Yellow
TextBox1.BackColor = RGB(0, 128, 64)
'Color - Green #2
'TextBoxes 2 through 6 initially use special effects
TextBox2.Text = "Flat"
TextBox2.SpecialEffect = fmSpecialEffectFlat
TextBox2.ForeColor = RGB(64, 0, 0)
'Color - Brown
TextBox2.BackColor = RGB(0, 0, 255)
'Color - Blue
'Ensure the background style for TextBox2 is initially
'opaque.
TextBox2.BackStyle = fmBackStyleOpaque
TextBox3.Text = "Etched"
TextBox3.SpecialEffect = fmSpecialEffectEtched
TextBox3.ForeColor = RGB(128, 0, 255)
'Color - Purple
TextBox3.BackColor = RGB(0, 255, 255)
'Color - Cyan
'Define BorderColor for later use (when borderstyle=fmBorderStyleSingle)
TextBox3.BorderColor = RGB(0, 0, 0)
'Color - Black
TextBox4.Text = "Bump"
TextBox4.SpecialEffect = fmSpecialEffectBump
TextBox4.ForeColor = RGB(255, 0, 255)
'Color - Magenta
TextBox4.BackColor = RGB(0, 0, 100)
'Color - Navy blue
TextBox5.Text = "Raised"
TextBox5.SpecialEffect = fmSpecialEffectRaised
TextBox5.ForeColor = RGB(255, 0, 0)
'Color - Red
TextBox5.BackColor = RGB(128, 128, 128)
'Color - Gray
TextBox6.Text = "Sunken"
TextBox6.SpecialEffect = fmSpecialEffectSunken
TextBox6.ForeColor = RGB(0, 64, 0)
'Color - Olive
TextBox6.BackColor = RGB(0, 255, 0)
'Color - Green #1
ToggleButton1.Caption = "Swap styles"
ToggleButton2.Caption = "Transparent/Opaque " _
& "background"
End Sub
Private Sub ToggleButton1_Click()
'Swap borders between TextBox1 and TextBox3
If ToggleButton1.Value = True Then
'Change TextBox1 from BorderStyle to Etched
TextBox1.Text = "Etched"
TextBox1.SpecialEffect = fmSpecialEffectEtched
'Change TextBox3 from Etched to BorderStyle
TextBox3.Text = "BorderStyle-Single"
TextBox3.BorderStyle = fmBorderStyleSingle
Else
'Change TextBox1 back to BorderStyle
TextBox1.Text = "BorderStyle-Single"
TextBox1.BorderStyle = fmBorderStyleSingle
'Change TextBox3 back to Etched
TextBox3.Text = "Etched"
TextBox3.SpecialEffect = fmSpecialEffectEtched
End If
End Sub
Private Sub ToggleButton2_Click()
'Set background to Opaque or Transparent
If ToggleButton2.Value = True Then
'Change TextBox2 to a transparent background
TextBox2.BackStyle = fmBackStyleTransparent
Else
'Change TextBox2 back to opaque background
TextBox2.BackStyle = fmBackStyleOpaque
End If
End Sub
以上介绍了“ 我用Delphi写的ActiveX控件,在Delphi下用就可以透明,但到Word下就不透明了”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/2418433.html