EditBox在默认情况下是不支持透明颜色的,可以使用下面的方法让其支持:SetStyle(ControlStyles.SupportsTransparentBackColor, True)有了上面语句的运行,EditBox就可以支持透明背景色。既然能让EditBox支持背景色,设置背景图片是否就简单了呢?我现在没有办法查阅资料,是否可以象设置背景色一样的解决,但下面的方法也是一个替代的解决办法:放置一个图片,把EditBox放置在图片上面,这样图片就变成EditBox的背景图片了,这个时候,只要再把EditBox的背景色设置为透明,是否就可以解决了呢?

解决方案 »

  1.   

    triout(笨牛):
    我已按你的方法做了。但没有作用。TextBox还是不透明。你试过行的吗?
      

  2.   

    设置样式不行吗?.XpButton01
    {
    BORDER-RIGHT: #333333 1px solid; 
    BORDER-TOP: #333333 1px solid; 
    FONT-SIZE: 9pt; 
    BACKGROUND: url(../images/input.gif) #ffffff; 
    BORDER-LEFT: #333333 1px solid; 
    COLOR: #000000; 
    BORDER-BOTTOM: #333333 1px solid; 
    FONT-FAMILY: verdana;
    font-style:normal;
    width: 60px
    }
      

  3.   

    我说的是WinForm不是Web.
    有没有人会呀。
    或者提供一些自己做一个TextBox控件的方法来啦!
      

  4.   

    http://community.csdn.net/Expert/topic/3199/3199558.xml?temp=.5888788我测试,发现确实不行。上面的连接的楼主说已经解决了让TextBox透明的问题,可以咨询一下。
      

  5.   

    请各位继续指导
    或者提供一些自己做一个TextBox控件的方法来啦!
      

  6.   

    请各位继续指导
    或者提供一些自己做一个TextBox控件的方法来啦!
      

  7.   

    你是用的WebForm吗? 我以前是用TD上放一个TextBox(透明),然后加载背景图片.<TD id="backbmp" style="BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: none; HEIGHT: 108px; BORDER-BOTTOM-STYLE: none" width="146" colSpan="2" runat="server">
    backbmp.Style.Add("BACKGROUND-IMAGE",file);
      

  8.   

    不是WebForm,是WinForm.
    没有人会呀??
    请帮帮忙啦
      

  9.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Runtime.InteropServices;namespace WindowsApplication1
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {

    const int GWL_EXSTYLE = -20;
    const int LWA_ALPHA = 0x00000002;
    const int WS_EX_LAYERED = 0x00080000;
    private System.Windows.Forms.RichTextBox richTextBox1;
    const int LWA_COLORKEY = 0x00000001;

    [DllImport("User32.DLL")]
    public static extern int SetLayeredWindowAttributes(IntPtr hwnd,uint crKey,byte bAlpha,uint dwFlags);
    [DllImport("User32.DLL")]
    public static extern long GetWindowLong(IntPtr hWnd,int nIndex);
    [DllImport("User32.DLL")]
    public static extern long SetWindowLong(IntPtr hWnd,int nIndex,long dwNewLong); /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //


    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.richTextBox1 = new System.Windows.Forms.RichTextBox();
    this.SuspendLayout();
    // 
    // richTextBox1
    // 
    this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
    this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Top;
    this.richTextBox1.Location = new System.Drawing.Point(0, 0);
    this.richTextBox1.Name = "richTextBox1";
    this.richTextBox1.Size = new System.Drawing.Size(624, 312);
    this.richTextBox1.TabIndex = 0;
    this.richTextBox1.Text = "richTextBox1";
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.BackColor = System.Drawing.Color.White;
    this.ClientSize = new System.Drawing.Size(624, 400);
    this.Controls.Add(this.richTextBox1);
    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
    this.Name = "Form1";
    this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion
    private void SetTextWindowOpacity(Control box)
    {
    IntPtr handle = box.Handle;
    long lRt=GetWindowLong(handle,GWL_EXSTYLE);
    lRt=lRt|WS_EX_LAYERED; 
    SetWindowLong(handle,GWL_EXSTYLE,lRt); 
    SetLayeredWindowAttributes(handle,0XFFFFFF,0,LWA_COLORKEY); 
    }
    protected override void OnLoad(EventArgs e)
    {
    base.OnLoad (e);
    SetTextWindowOpacity(this);

    } /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } }
    }
      

  10.   

    呵..看来楼主的问题,同我过去遇到的相似..
    我当时是要做一个可以带背景的RichTextbox也就是像QQ的聊天窗口那样,可以带背景图片的.
    RichTextBox虽然有BackgroundImage属性,但它并没有实现这个属性.实际是不可用的,当时发了贴.查了好多资料也没有解决.后来,想到了这个迂回的办法..基本上解决了这个问题..把上面的代码编译执行后,你就可以在桌面上看到一个透明的RichTextbox,漂亮的桌面都可以看到,同时也可以输入文字,很酷的..如果想在别的窗体中使用,只要把这个窗口改成无边框,非顶级的窗口即可.
      

  11.   

    效果是出来了,但总不能用户用鼠标点击选择RichTextbox的文字时。窗口就失去焦点吧。
      

  12.   

    鼠标事件是被下面的窗口接收到了. 你在下面的窗口的MouseDown事件中,判断它是否得到了焦点,如果得到了,调用TextBox的Focus方法.试一下.