Csharp/C#教程:移动窗口的问题分享


移动窗口的问题

我使用下面的代码移动窗口的表单,移动工作正常,但问题是不透明度和关闭。 我希望以这种方式工作:当我按下按钮opacity = 0.5,当我向上按钮opacity = 1时,当左按钮向下并且我移动鼠标窗口也移动,当我只是点击表格然后表格必须关闭。

using System; using System.Runtime.InteropServices; using System.Windows.Forms; public partial class FormImage : Form { 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(); public FormImage() { InitializeComponent(); } private void FormZdjecie_MouseMove( object sender, MouseEventArgs e ) { if ( e.Button == MouseButtons.Left) { ReleaseCapture(); SendMessage( Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 6 ); } } private void FormImage_MouseDown( object sender, MouseEventArgs e ) { this.Opacity = 0.5; } private void FormImage_MouseUp( object sender, MouseEventArgs e ) { this.Opacity = 1; } private void FormImage_MouseClick( object sender, MouseEventArgs e ) { Close(); } } 

知道如何修复此代码吗?

使用HT_CAPTION发送WM_NCLBUTTONDOWN将占用您的MouseUp事件。

您需要做的就是在SendMessage调用后立即更改Opacity

工作实例:

上述就是C#学习教程:移动窗口的问题分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 public partial class FormImage : Form { 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(); public FormImage() { InitializeComponent(); } private void FormImage_MouseDown(object sender, MouseEventArgs e) { this.Opacity = 0.5; ReleaseCapture(); SendMessage(this.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); this.Opacity = 1; } } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1022802.html

(0)
上一篇 2022年1月7日
下一篇 2022年1月7日

精彩推荐