textbox在c#中怎么添加背景图片
展开全部
如果是winForm的建议自己写空间 从textbox继承 下面是代码,如果是web我就不会了
=======================从textbox类继承处理绘制背景消息===================
class mytextbox : textbox
{
const int wm_erasebkgnd = 0x0014;
private image backimage;
[displayname("背景图片。")]
public image backimage
{
get { return backimage; }
set { backimage = value; }
}
protected void onerasebkgnd(graphics gs)
{
gs.fillrectangle(brushes.white, 0, 0, this.width, this.height); //填充为白色,防止图片太小出现重影
if (backimage != null) gs.drawimage(backimage, 0, 0); //绘制背景。
gs.dispose();
}
protected override void wndproc(ref message m)
{
if (m.msg == wm_erasebkgnd) //绘制背景
{
onerasebkgnd(graphics.fromhdc(m.wparam));
m.result = (intptr)1;
}
base.wndproc(ref m);
}
}
==================窗口类里设置控件的字体颜色等============================
const int wm_ctlcoloredit = 0x0133;
const int transparent = 0x1;
const int null_brush = 0x5;
[dllimport("gdi32")]
static extern int setbkmode(intptr hdc, int bkmode);
[dllimport("gdi32")]
static extern int settextcolor(intptr hdc, int color);
[dllimport("gdi32")]
static extern intptr getstockobject(int fnobject);
protected override void wndproc(ref message m)
{
if (m.msg == wm_ctlcoloredit && m.lparam == mytextbox1.handle)//类型为edit(textbox)
{
setbkmode(m.wparam, transparent);//设置背景透明
settextcolor(m.wparam,0xff); //字体颜色为红色
m.result = getstockobject(null_brush);
return;
}
else base.wndproc(ref m);
}
展开全部
从textbox类继承处理绘制背景消息
class MyTextBox : TextBox
{
const int WM_ERASEBKGND = 0x0014;
private Image backImage;
[DisplayName("背景图片。")]
public Image BackImage
{
get { return backImage; }
set { backImage = value; }
}
protected void OnEraseBkgnd(Graphics gs)
{
gs.FillRectangle(Brushes.White, 0, 0, this.Width, this.Height); //填充为白色,防止图片太小出现重影
if (backImage != null) gs.DrawImage(backImage, 0, 0); //绘制背景。
gs.Dispose();
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_ERASEBKGND) //绘制背景
{
OnEraseBkgnd(Graphics.FromHdc(m.WParam));
m.Result = (IntPtr)1;
}
base.WndProc(ref m);
}
}
窗口类里设置控件的字体颜色等
const int WM_CTLCOLOREDIT = 0x0133;
const int TRANSPARENT = 0x1;
const int NULL_BRUSH = 0x5;
[DllImport("gdi32")]
static extern int SetBkMode(IntPtr hdc, int bkMode);
[DllImport("gdi32")]
static extern int SetTextColor(IntPtr hdc, int color);
[DllImport("gdi32")]
static extern IntPtr GetStockObject(int fnobject);
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_CTLCOLOREDIT && m.LParam == myTextBox1.Handle)//类型为EDIT(TextBox)
{
SetBkMode(m.WParam, TRANSPARENT);//设置背景透明
SetTextColor(m.WParam,0xFF); //字体颜色为红色
m.Result = GetStockObject(NULL_BRUSH);
return;
}
else base.WndProc(ref m);
}
class MyTextBox : TextBox
{
const int WM_ERASEBKGND = 0x0014;
private Image backImage;
[DisplayName("背景图片。")]
public Image BackImage
{
get { return backImage; }
set { backImage = value; }
}
protected void OnEraseBkgnd(Graphics gs)
{
gs.FillRectangle(Brushes.White, 0, 0, this.Width, this.Height); //填充为白色,防止图片太小出现重影
if (backImage != null) gs.DrawImage(backImage, 0, 0); //绘制背景。
gs.Dispose();
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_ERASEBKGND) //绘制背景
{
OnEraseBkgnd(Graphics.FromHdc(m.WParam));
m.Result = (IntPtr)1;
}
base.WndProc(ref m);
}
}
窗口类里设置控件的字体颜色等
const int WM_CTLCOLOREDIT = 0x0133;
const int TRANSPARENT = 0x1;
const int NULL_BRUSH = 0x5;
[DllImport("gdi32")]
static extern int SetBkMode(IntPtr hdc, int bkMode);
[DllImport("gdi32")]
static extern int SetTextColor(IntPtr hdc, int color);
[DllImport("gdi32")]
static extern IntPtr GetStockObject(int fnobject);
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_CTLCOLOREDIT && m.LParam == myTextBox1.Handle)//类型为EDIT(TextBox)
{
SetBkMode(m.WParam, TRANSPARENT);//设置背景透明
SetTextColor(m.WParam,0xFF); //字体颜色为红色
m.Result = GetStockObject(NULL_BRUSH);
return;
}
else base.WndProc(ref m);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |