如题
解决方案 »
- 求正则?
- 请各位大侠看看我的程序怎么办呢?
- 乘法表
- 关于大型论坛比如CSDN的发表文章,帖子的功能是怎么处理的???????????????
- 怎样让文本框的滚动条自动滚动到最底端?
- c#中要作为结果串返回的字符串可以作为函数参数吗?
- C#读取txt遇阻——数据之间的空格是“0A0D20”而不是“0D0A20“。”
- Bitmap bt=new Bitmap(stream),使用了无效的参数,why?
- 软件开发到中后期,会有很多的方法和变量,如何管理?
- C# 调用 Excel 的打印预览(PrintPreview)的时候会抛出一个异常(0x800a03ec)
- C# Sockets 编程服务器如何判断客户端断开了????
- 新手问题
把你窗体的FormBorderStyle改为FixedDialog试试
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Imaging;
namespace CustomForm
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class CustomForm : System.Windows.Forms.Form
{
public CustomForm()
{
InitializeComponent();
} Image backBitmap=null;
Form frm2=new Form();
bool isMove=true;
private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
public override Image BackgroundImage
{
get
{
return backBitmap;
}
set
{
backBitmap=value;
SetBackground(this.backBitmap);
this.Width=value.Width;
this.Height=value.Height;
}
} protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
if ((int)m.Result == HTCLIENT&&isMove)
m.Result = (IntPtr)HTCAPTION;
return;
break;
}
base.WndProc(ref m);
} public bool IsMoveForm
{
get
{
return isMove;
}
set
{
isMove=value;
}
} private void SetBackground(Image img)
{
try
{
Bitmap bitmap = (Bitmap) img;
if (bitmap.PixelFormat != PixelFormat.Format32bppArgb)
{
throw new ApplicationException("图片必须为32位图像");
}
IntPtr hObject = IntPtr.Zero;
IntPtr zero = IntPtr.Zero;
IntPtr hDC = Win32.GetDC(IntPtr.Zero);
IntPtr ptr2 = Win32.CreateCompatibleDC(hDC);
try
{
hObject = bitmap.GetHbitmap(Color.FromArgb(0));
zero = Win32.SelectObject(ptr2, hObject);
Win32.Size size2 = new Win32.Size(bitmap.Width, bitmap.Height);
Win32.Size psize = size2;
Win32.Point point3 = new Win32.Point(0, 0);
Win32.Point pprSrc = point3;
point3 = new Win32.Point(base.Left, base.Top);
Win32.Point pptDst = point3;
Win32.BLENDFUNCTION pblend = new Win32.BLENDFUNCTION();
pblend.BlendOp = 0;
pblend.BlendFlags = 0;
pblend.SourceConstantAlpha = 0xff;
pblend.AlphaFormat = 1;
Win32.UpdateLayeredWindow(this.Handle, hDC, ref pptDst, ref psize, ptr2, ref pprSrc, 0, ref pblend, 2);
}
catch (Exception exception1)
{
Exception exception = exception1;
throw exception;
}
finally
{
Win32.ReleaseDC(IntPtr.Zero, hDC);
if (hObject != IntPtr.Zero)
{
Win32.SelectObject(ptr2, zero);
Win32.DeleteObject(hObject);
}
Win32.DeleteDC(ptr2);
}
}
catch (ApplicationException exception4)
{
ApplicationException exception2 = exception4;
MessageBox.Show(exception2.Message, "请检测你的PNG文件");
}
catch (Exception exception5)
{
Exception exception3 = exception5;
MessageBox.Show(exception3.Message, "无法打开PNG文件.");
}
} protected override System.Windows.Forms.CreateParams CreateParams
{
get
{
System.Windows.Forms.CreateParams createParams = base.CreateParams;
createParams.ExStyle |= 0x80000;
return createParams;
}
} private void CustomForm_Move(object sender, EventArgs e)
{
frm2.Location = this.Location;
} private void CustomForm_Resize(object sender, EventArgs e)
{
frm2.SetBounds(this.Left, this.Top, this.Width, this.Height);
} private void CustomForm_ControlAdded(object sender, ControlEventArgs e)
{
frm2.Controls.Add(e.Control);
} private void InitializeComponent()
{
//
// CustomForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(536, 358);
base.Move+=new EventHandler(CustomForm_Move);
base.Resize+=new EventHandler(CustomForm_Resize);
this.ControlAdded+=new ControlEventHandler(CustomForm_ControlAdded);
base.FormBorderStyle=FormBorderStyle.None;
base.ClientSize = new System.Drawing.Size(560, 446);
//base.StartPosition=FormStartPosition.CenterScreen;
base.ControlBox=false;
frm2.ShowInTaskbar = false;
frm2.TransparencyKey = Color.Red;
frm2.BackColor = Color.Red;
frm2.FormBorderStyle = FormBorderStyle.None;
frm2.ControlBox = false;
//frm2.TopMost=true;
//this.TopMost=true;
frm2.Owner = this;
frm2.Opacity = this.Opacity;
frm2.MaximizeBox = false;
frm2.MouseDoubleClick += new MouseEventHandler(frm2_MouseDoubleClick);
frm2.DoubleClick += new EventHandler(frm2_DoubleClick);
frm2.Closing += new CancelEventHandler(frm2_Closing);
frm2.Show(); } void frm2_DoubleClick(object sender, EventArgs e)
{
throw new NotImplementedException();
} void frm2_MouseDoubleClick(object sender, MouseEventArgs e)
{
throw new NotImplementedException();
}
private void frm2_Closing(object sender, CancelEventArgs e)
{
this.Close();
}
}
}
继承的这个窗体类 楼上朋友们说的 不行 呵呵 不过还是谢谢你们
前辈 急啊
我这个也是网上下的
{
base.WndProc(ref m);
if(m.Msg == 0x84 && m.Result == (IntPtr)2) // 不让拖动标题栏
{
m.Result = (IntPtr)1;
}
if (m.Msg == 0xA3) // 双击标题栏无反应
{
m.WParam = System.IntPtr.Zero;
}
}
顶下!