我想在 C# 上的 Windows 窗体一侧添加按钮(在外面)。当窗口移动时,按钮应该一起移动。
例如 :
我看到两个选择:
干得好:
首先,您可以通过以下方式设置表单样式:
- Setting
this.ControlBox = false;
- Setting
this.MaximizeBox = false;
- Setting
this.MinimizeBox = false;
- Setting
this.Text= "";
- Setting
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
- Setting
this.BackColor = System.Drawing.Color.Fuchsia;
- Setting
this.TransparencyKey = this.BackColor;
现在添加到Form
- a
Panel
填充了右侧的主要部分Form
- the
Button
你想要附加
- a
Label
(label1
)在主程序内Panel
,填充顶部并保留表单的标题文本
- a
Tab
控制等..
最后我们要添加代码来制作表单moveable:
using System.Runtime.InteropServices;
..
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
private void label1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
您也可以查找代码来使窗口变大。
您可以查找代码以使用区域为按钮提供非矩形形状。请注意,您需要避免此处使用抗锯齿像素,否则紫红色将会透出。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)